OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_content_settings_store.h" | 5 #include "chrome/browser/extensions/extension_content_settings_store.h" |
6 | 6 |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 using ::testing::Mock; | 10 using ::testing::Mock; |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 private: | 23 private: |
24 int64 internal_; | 24 int64 internal_; |
25 }; | 25 }; |
26 | 26 |
27 class MockExtensionContentSettingsStoreObserver | 27 class MockExtensionContentSettingsStoreObserver |
28 : public ExtensionContentSettingsStore::Observer { | 28 : public ExtensionContentSettingsStore::Observer { |
29 public: | 29 public: |
30 MOCK_METHOD2(OnContentSettingChanged, | 30 MOCK_METHOD2(OnContentSettingChanged, |
31 void(const std::string& extension_id, bool incognito)); | 31 void(const std::string& extension_id, bool incognito)); |
32 MOCK_METHOD0(OnDestruction, void()); | |
33 }; | 32 }; |
34 | 33 |
35 } | 34 } |
36 | 35 |
37 TEST(ExtensionContentSettingsStoreTest, RegisterUnregister) { | 36 TEST(ExtensionContentSettingsStoreTest, RegisterUnregister) { |
38 FakeTimer timer; | 37 FakeTimer timer; |
39 | 38 |
40 ::testing::StrictMock<MockExtensionContentSettingsStoreObserver> observer; | 39 ::testing::StrictMock<MockExtensionContentSettingsStoreObserver> observer; |
41 | 40 |
42 ExtensionContentSettingsStore map; | 41 scoped_refptr<ExtensionContentSettingsStore> map( |
43 map.AddObserver(&observer); | 42 new ExtensionContentSettingsStore()); |
| 43 map->AddObserver(&observer); |
44 | 44 |
45 GURL url("http://www.youtube.com"); | 45 GURL url("http://www.youtube.com"); |
46 | 46 |
47 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 47 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
48 map.GetEffectiveContentSetting( | 48 map->GetEffectiveContentSetting( |
49 url, | 49 url, |
50 url, | 50 url, |
51 CONTENT_SETTINGS_TYPE_COOKIES, | 51 CONTENT_SETTINGS_TYPE_COOKIES, |
52 "", | 52 "", |
53 false)); | 53 false)); |
54 | 54 |
55 // Register first extension | 55 // Register first extension |
56 std::string ext_id("my_extension"); | 56 std::string ext_id("my_extension"); |
57 base::Time time_1 = timer.GetNext(); | 57 base::Time time_1 = timer.GetNext(); |
58 map.RegisterExtension(ext_id, time_1, true); | 58 map->RegisterExtension(ext_id, time_1, true); |
59 | 59 |
60 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 60 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
61 map.GetEffectiveContentSetting( | 61 map->GetEffectiveContentSetting( |
62 url, | 62 url, |
63 url, | 63 url, |
64 CONTENT_SETTINGS_TYPE_COOKIES, | 64 CONTENT_SETTINGS_TYPE_COOKIES, |
65 "", | 65 "", |
66 false)); | 66 false)); |
67 | 67 |
68 // Set setting | 68 // Set setting |
69 ContentSettingsPattern pattern = | 69 ContentSettingsPattern pattern = |
70 ContentSettingsPattern::FromURL(GURL("http://www.youtube.com")); | 70 ContentSettingsPattern::FromURL(GURL("http://www.youtube.com")); |
71 EXPECT_CALL(observer, OnContentSettingChanged(ext_id, false)); | 71 EXPECT_CALL(observer, OnContentSettingChanged(ext_id, false)); |
72 map.SetExtensionContentSetting( | 72 map->SetExtensionContentSetting( |
73 ext_id, | 73 ext_id, |
74 pattern, | 74 pattern, |
75 pattern, | 75 pattern, |
76 CONTENT_SETTINGS_TYPE_COOKIES, | 76 CONTENT_SETTINGS_TYPE_COOKIES, |
77 "", | 77 "", |
78 CONTENT_SETTING_ALLOW, | 78 CONTENT_SETTING_ALLOW, |
79 kExtensionPrefsScopeRegular); | 79 kExtensionPrefsScopeRegular); |
80 Mock::VerifyAndClear(&observer); | 80 Mock::VerifyAndClear(&observer); |
81 | 81 |
82 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 82 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
83 map.GetEffectiveContentSetting( | 83 map->GetEffectiveContentSetting( |
84 url, | 84 url, |
85 url, | 85 url, |
86 CONTENT_SETTINGS_TYPE_COOKIES, | 86 CONTENT_SETTINGS_TYPE_COOKIES, |
87 "", | 87 "", |
88 false)); | 88 false)); |
89 | 89 |
90 // Register second extension. | 90 // Register second extension. |
91 std::string ext_id_2("my_second_extension"); | 91 std::string ext_id_2("my_second_extension"); |
92 base::Time time_2 = timer.GetNext(); | 92 base::Time time_2 = timer.GetNext(); |
93 map.RegisterExtension(ext_id_2, time_2, true); | 93 map->RegisterExtension(ext_id_2, time_2, true); |
94 EXPECT_CALL(observer, OnContentSettingChanged(ext_id_2, false)); | 94 EXPECT_CALL(observer, OnContentSettingChanged(ext_id_2, false)); |
95 map.SetExtensionContentSetting( | 95 map->SetExtensionContentSetting( |
96 ext_id_2, | 96 ext_id_2, |
97 pattern, | 97 pattern, |
98 pattern, | 98 pattern, |
99 CONTENT_SETTINGS_TYPE_COOKIES, | 99 CONTENT_SETTINGS_TYPE_COOKIES, |
100 "", | 100 "", |
101 CONTENT_SETTING_BLOCK, | 101 CONTENT_SETTING_BLOCK, |
102 kExtensionPrefsScopeRegular); | 102 kExtensionPrefsScopeRegular); |
103 | 103 |
104 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 104 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
105 map.GetEffectiveContentSetting( | 105 map->GetEffectiveContentSetting( |
106 url, | 106 url, |
107 url, | 107 url, |
108 CONTENT_SETTINGS_TYPE_COOKIES, | 108 CONTENT_SETTINGS_TYPE_COOKIES, |
109 "", | 109 "", |
110 false)); | 110 false)); |
111 | 111 |
112 // Unregister first extension. This shouldn't change the setting. | 112 // Unregister first extension. This shouldn't change the setting. |
113 EXPECT_CALL(observer, OnContentSettingChanged(ext_id, false)); | 113 EXPECT_CALL(observer, OnContentSettingChanged(ext_id, false)); |
114 map.UnregisterExtension(ext_id); | 114 map->UnregisterExtension(ext_id); |
115 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 115 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
116 map.GetEffectiveContentSetting( | 116 map->GetEffectiveContentSetting( |
117 url, | 117 url, |
118 url, | 118 url, |
119 CONTENT_SETTINGS_TYPE_COOKIES, | 119 CONTENT_SETTINGS_TYPE_COOKIES, |
120 "", | 120 "", |
121 false)); | 121 false)); |
122 Mock::VerifyAndClear(&observer); | 122 Mock::VerifyAndClear(&observer); |
123 | 123 |
124 // Unregister second extension. This should reset the setting to its default | 124 // Unregister second extension. This should reset the setting to its default |
125 // value. | 125 // value. |
126 EXPECT_CALL(observer, OnContentSettingChanged(ext_id_2, false)); | 126 EXPECT_CALL(observer, OnContentSettingChanged(ext_id_2, false)); |
127 map.UnregisterExtension(ext_id_2); | 127 map->UnregisterExtension(ext_id_2); |
128 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 128 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
129 map.GetEffectiveContentSetting( | 129 map->GetEffectiveContentSetting( |
130 url, | 130 url, |
131 url, | 131 url, |
132 CONTENT_SETTINGS_TYPE_COOKIES, | 132 CONTENT_SETTINGS_TYPE_COOKIES, |
133 "", | 133 "", |
134 false)); | 134 false)); |
135 Mock::VerifyAndClear(&observer); | |
136 | 135 |
137 EXPECT_CALL(observer, OnDestruction()); | 136 map->RemoveObserver(&observer); |
138 } | 137 } |
OLD | NEW |