Home | History | Annotate | Download | only in content_settings
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MOCK_PROVIDER_H_
      6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MOCK_PROVIDER_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "chrome/browser/content_settings/content_settings_provider.h"
     11 
     12 namespace content_settings {
     13 
     14 // The class MockDefaultProvider is a mock for a default content settings
     15 // provider.
     16 class MockDefaultProvider : public DefaultProviderInterface {
     17  public:
     18   // Create a content settings provider that provides a given setting for a
     19   // given type.
     20   MockDefaultProvider(ContentSettingsType content_type,
     21                               ContentSetting setting,
     22                               bool is_managed,
     23                               bool can_override);
     24   virtual ~MockDefaultProvider();
     25 
     26   // DefaultProviderInterface implementation.
     27   virtual ContentSetting ProvideDefaultSetting(
     28       ContentSettingsType content_type) const;
     29   virtual void UpdateDefaultSetting(ContentSettingsType content_type,
     30                                     ContentSetting setting);
     31   virtual void ResetToDefaults();
     32   virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const;
     33 
     34  private:
     35   ContentSettingsType content_type_;
     36   ContentSetting setting_;
     37   bool is_managed_;
     38   bool can_override_;
     39 
     40   DISALLOW_COPY_AND_ASSIGN(MockDefaultProvider);
     41 };
     42 
     43 // The class MockProvider is a mock for a non default content settings provider.
     44 class MockProvider : public ProviderInterface {
     45  public:
     46   MockProvider();
     47   MockProvider(ContentSettingsPattern requesting_url_pattern,
     48                ContentSettingsPattern embedding_url_pattern,
     49                ContentSettingsType content_type,
     50                ResourceIdentifier resource_identifier,
     51                ContentSetting setting,
     52                bool read_only,
     53                bool is_managed);
     54   virtual ~MockProvider();
     55 
     56   virtual bool ContentSettingsTypeIsManaged(ContentSettingsType type);
     57 
     58   // ProviderInterface implementation
     59   virtual ContentSetting GetContentSetting(
     60       const GURL& requesting_url,
     61       const GURL& embedding_url,
     62       ContentSettingsType content_type,
     63       const ResourceIdentifier& resource_identifier) const;
     64 
     65   // The MockProvider is only able to store one content setting. So every time
     66   // this method is called the previously set content settings is overwritten.
     67   virtual void SetContentSetting(
     68       const ContentSettingsPattern& requesting_url_pattern,
     69       const ContentSettingsPattern& embedding_url_pattern,
     70       ContentSettingsType content_type,
     71       const ResourceIdentifier& resource_identifier,
     72       ContentSetting content_setting);
     73 
     74   virtual void GetAllContentSettingsRules(
     75       ContentSettingsType content_type,
     76       const ResourceIdentifier& resource_identifier,
     77       Rules* content_setting_rules) const {}
     78 
     79   virtual void ClearAllContentSettingsRules(
     80       ContentSettingsType content_type) {}
     81 
     82   virtual void ResetToDefaults() {}
     83 
     84   // Accessors
     85   void set_requesting_url_pattern(ContentSettingsPattern pattern) {
     86     requesting_url_pattern_ = pattern;
     87   }
     88 
     89   ContentSettingsPattern requesting_url_pattern() const {
     90     return requesting_url_pattern_;
     91   }
     92 
     93   void set_embedding_url_pattern(ContentSettingsPattern pattern) {
     94     embedding_url_pattern_ = pattern;
     95   }
     96 
     97   ContentSettingsPattern embedding_url_pattern() const {
     98     return embedding_url_pattern_;
     99   }
    100 
    101   void set_content_type(ContentSettingsType content_type) {
    102     content_type_ = content_type;
    103   }
    104 
    105   ContentSettingsType content_type() const {
    106     return content_type_;
    107   }
    108 
    109   void set_resource_identifier(ResourceIdentifier resource_identifier) {
    110     resource_identifier_ = resource_identifier;
    111   }
    112 
    113   ResourceIdentifier resource_identifier() const {
    114     return resource_identifier_;
    115   }
    116 
    117   void set_setting(ContentSetting setting) {
    118     setting_ = setting;
    119   }
    120 
    121   ContentSetting setting() const {
    122     return setting_;
    123   }
    124 
    125   void set_read_only(bool read_only) {
    126     read_only_ = read_only;
    127   }
    128 
    129   bool read_only() const {
    130     return read_only_;
    131   }
    132 
    133   void set_is_managed(bool is_managed) {
    134     is_managed_ = is_managed;
    135   }
    136 
    137   bool is_managed() const {
    138     return is_managed_;
    139   }
    140 
    141  private:
    142   ContentSettingsPattern requesting_url_pattern_;
    143   ContentSettingsPattern embedding_url_pattern_;
    144   ContentSettingsType content_type_;
    145   ResourceIdentifier resource_identifier_;
    146   ContentSetting setting_;
    147   bool read_only_;
    148   bool is_managed_;
    149 
    150   DISALLOW_COPY_AND_ASSIGN(MockProvider);
    151 };
    152 
    153 }  // namespace content_settings
    154 
    155 #endif  // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MOCK_PROVIDER_H_
    156