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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/content_settings/host_content_settings_map.h" | 6 #include "chrome/browser/content_settings/host_content_settings_map.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_content_settings_api.h" | 8 #include "chrome/browser/extensions/extension_content_settings_api.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "webkit/plugins/npapi/mock_plugin_list.h" | 14 #include "webkit/plugins/npapi/mock_plugin_list.h" |
15 | 15 |
16 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { | 16 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { |
17 CommandLine::ForCurrentProcess()->AppendSwitch( | 17 CommandLine::ForCurrentProcess()->AppendSwitch( |
18 switches::kEnableExperimentalExtensionApis); | 18 switches::kEnableExperimentalExtensionApis); |
19 | 19 |
20 PrefService* pref_service = browser()->profile()->GetPrefs(); | |
21 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); | |
22 pref_service->SetBoolean(prefs::kEnableReferrers, false); | |
23 | |
24 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; | 20 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; |
25 | 21 |
26 const PrefService::Preference* pref = pref_service->FindPreference( | |
27 prefs::kBlockThirdPartyCookies); | |
28 ASSERT_TRUE(pref); | |
29 EXPECT_TRUE(pref->IsExtensionControlled()); | |
30 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
31 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); | |
32 HostContentSettingsMap* map = | 22 HostContentSettingsMap* map = |
33 browser()->profile()->GetHostContentSettingsMap(); | 23 browser()->profile()->GetHostContentSettingsMap(); |
34 | 24 |
35 // Check default content settings by using an unknown URL. | 25 // Check default content settings by using an unknown URL. |
36 GURL example_url("http://www.example.com"); | 26 GURL example_url("http://www.example.com"); |
37 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 27 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
38 map->GetCookieContentSetting( | 28 map->GetCookieContentSetting( |
39 example_url, example_url, false)); | 29 example_url, example_url, false)); |
40 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 30 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
41 map->GetContentSetting(example_url, | 31 map->GetContentSetting(example_url, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #if 0 | 81 #if 0 |
92 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 82 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
93 map->GetContentSetting( | 83 map->GetContentSetting( |
94 url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | 84 url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); |
95 #endif | 85 #endif |
96 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 86 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
97 map->GetContentSetting( | 87 map->GetContentSetting( |
98 url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "")); | 88 url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "")); |
99 } | 89 } |
100 | 90 |
101 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PersistentIncognitoContentSettings) { | |
102 CommandLine::ForCurrentProcess()->AppendSwitch( | |
103 switches::kEnableExperimentalExtensionApis); | |
104 | |
105 PrefService* prefs = browser()->profile()->GetPrefs(); | |
106 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | |
107 | |
108 EXPECT_TRUE( | |
109 RunExtensionTestIncognito("content_settings/persistent_incognito")) << | |
110 message_; | |
111 | |
112 // Setting an incognito preference should not create an incognito profile. | |
113 EXPECT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | |
114 | |
115 PrefService* otr_prefs = | |
116 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); | |
117 const PrefService::Preference* pref = | |
118 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); | |
119 ASSERT_TRUE(pref); | |
120 EXPECT_TRUE(pref->IsExtensionControlled()); | |
121 EXPECT_TRUE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
122 | |
123 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); | |
124 ASSERT_TRUE(pref); | |
125 EXPECT_FALSE(pref->IsExtensionControlled()); | |
126 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
127 } | |
128 | |
129 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledContentSettings) { | |
130 CommandLine::ForCurrentProcess()->AppendSwitch( | |
131 switches::kEnableExperimentalExtensionApis); | |
132 | |
133 EXPECT_FALSE(RunExtensionTest("content_settings/persistent_incognito")); | |
134 } | |
135 | |
136 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, SessionOnlyIncognitoContentSettings) { | |
137 CommandLine::ForCurrentProcess()->AppendSwitch( | |
138 switches::kEnableExperimentalExtensionApis); | |
139 | |
140 PrefService* prefs = browser()->profile()->GetPrefs(); | |
141 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | |
142 | |
143 EXPECT_TRUE( | |
144 RunExtensionTestIncognito("content_settings/session_only_incognito")) << | |
145 message_; | |
146 | |
147 EXPECT_TRUE(browser()->profile()->HasOffTheRecordProfile()); | |
148 | |
149 PrefService* otr_prefs = | |
150 browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); | |
151 const PrefService::Preference* pref = | |
152 otr_prefs->FindPreference(prefs::kBlockThirdPartyCookies); | |
153 ASSERT_TRUE(pref); | |
154 EXPECT_TRUE(pref->IsExtensionControlled()); | |
155 EXPECT_FALSE(otr_prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
156 | |
157 pref = prefs->FindPreference(prefs::kBlockThirdPartyCookies); | |
158 ASSERT_TRUE(pref); | |
159 EXPECT_FALSE(pref->IsExtensionControlled()); | |
160 EXPECT_FALSE(prefs->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
161 } | |
162 | |
163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsClear) { | |
164 CommandLine::ForCurrentProcess()->AppendSwitch( | |
165 switches::kEnableExperimentalExtensionApis); | |
166 | |
167 PrefService* pref_service = browser()->profile()->GetPrefs(); | |
168 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); | |
169 | |
170 EXPECT_TRUE(RunExtensionTest("content_settings/clear")) << message_; | |
171 | |
172 const PrefService::Preference* pref = pref_service->FindPreference( | |
173 prefs::kBlockThirdPartyCookies); | |
174 ASSERT_TRUE(pref); | |
175 EXPECT_FALSE(pref->IsExtensionControlled()); | |
176 EXPECT_EQ(true, pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); | |
177 } | |
178 | |
179 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsOnChange) { | |
180 CommandLine::ForCurrentProcess()->AppendSwitch( | |
181 switches::kEnableExperimentalExtensionApis); | |
182 | |
183 PrefService* prefs = browser()->profile()->GetPrefs(); | |
184 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); | |
185 | |
186 EXPECT_TRUE(RunExtensionTestIncognito("content_settings/onchange")) << | |
187 message_; | |
188 } | |
189 | |
190 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | 91 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
191 ContentSettingsGetResourceIdentifiers) { | 92 ContentSettingsGetResourceIdentifiers) { |
192 CommandLine::ForCurrentProcess()->AppendSwitch( | 93 CommandLine::ForCurrentProcess()->AppendSwitch( |
193 switches::kEnableExperimentalExtensionApis); | 94 switches::kEnableExperimentalExtensionApis); |
194 CommandLine::ForCurrentProcess()->AppendSwitch( | 95 CommandLine::ForCurrentProcess()->AppendSwitch( |
195 switches::kEnableResourceContentSettings); | 96 switches::kEnableResourceContentSettings); |
196 | 97 |
197 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | 98 FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); |
198 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | 99 FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); |
199 const char* kFooName = "Foo Plugin"; | 100 const char* kFooName = "Foo Plugin"; |
(...skipping 15 matching lines...) Expand all Loading... |
215 FilePath(kBarPath), | 116 FilePath(kBarPath), |
216 ASCIIToUTF16("2.3.4"), | 117 ASCIIToUTF16("2.3.4"), |
217 ASCIIToUTF16("bar"))); | 118 ASCIIToUTF16("bar"))); |
218 GetResourceIdentifiersFunction::SetPluginListForTesting(&plugin_list); | 119 GetResourceIdentifiersFunction::SetPluginListForTesting(&plugin_list); |
219 | 120 |
220 EXPECT_TRUE(RunExtensionTest("content_settings/getresourceidentifiers")) | 121 EXPECT_TRUE(RunExtensionTest("content_settings/getresourceidentifiers")) |
221 << message_; | 122 << message_; |
222 | 123 |
223 GetResourceIdentifiersFunction::SetPluginListForTesting(NULL); | 124 GetResourceIdentifiersFunction::SetPluginListForTesting(NULL); |
224 } | 125 } |
OLD | NEW |