Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/extensions/extension_content_settings_apitest.cc

Issue 7029031: Content settings extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync & review Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/content_settings/host_content_settings_map.h"
5 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/prefs/pref_service.h" 7 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
11 12
12 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { 13 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) {
13 CommandLine::ForCurrentProcess()->AppendSwitch( 14 CommandLine::ForCurrentProcess()->AppendSwitch(
14 switches::kEnableExperimentalExtensionApis); 15 switches::kEnableExperimentalExtensionApis);
15 16
16 PrefService* pref_service = browser()->profile()->GetPrefs(); 17 PrefService* pref_service = browser()->profile()->GetPrefs();
17 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true); 18 pref_service->SetBoolean(prefs::kBlockThirdPartyCookies, true);
18 pref_service->SetBoolean(prefs::kEnableReferrers, false); 19 pref_service->SetBoolean(prefs::kEnableReferrers, false);
19 20
20 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; 21 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_;
21 22
22 const PrefService::Preference* pref = pref_service->FindPreference( 23 const PrefService::Preference* pref = pref_service->FindPreference(
23 prefs::kBlockThirdPartyCookies); 24 prefs::kBlockThirdPartyCookies);
24 ASSERT_TRUE(pref); 25 ASSERT_TRUE(pref);
25 EXPECT_TRUE(pref->IsExtensionControlled()); 26 EXPECT_TRUE(pref->IsExtensionControlled());
26 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies)); 27 EXPECT_FALSE(pref_service->GetBoolean(prefs::kBlockThirdPartyCookies));
27 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers)); 28 EXPECT_TRUE(pref_service->GetBoolean(prefs::kEnableReferrers));
29 HostContentSettingsMap* map =
30 browser()->profile()->GetHostContentSettingsMap();
31
32 // Check default content settings by using an unknown URL.
33 GURL example_url("http://www.example.com");
34 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
35 map->GetCookieContentSetting(example_url, example_url,
36 false));
37 EXPECT_EQ(CONTENT_SETTING_ALLOW,
38 map->GetContentSetting(example_url, CONTENT_SETTINGS_TYPE_IMAGES,
39 std::string()));
40 EXPECT_EQ(CONTENT_SETTING_BLOCK,
41 map->GetContentSetting(example_url,
42 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
43 std::string()));
44 EXPECT_EQ(CONTENT_SETTING_ALLOW,
45 map->GetContentSetting(example_url, CONTENT_SETTINGS_TYPE_PLUGINS,
46 std::string()));
47 EXPECT_EQ(CONTENT_SETTING_BLOCK,
48 map->GetContentSetting(example_url, CONTENT_SETTINGS_TYPE_POPUPS,
49 std::string()));
50 #if 0
51 // TODO(bauerb): Enable once geolocation settings are integrated into the
52 // HostContentSettingsMap.
53 EXPECT_EQ(CONTENT_SETTING_ALLOW,
54 map->GetContentSetting(example_url,
55 CONTENT_SETTINGS_TYPE_GEOLOCATION,
56 std::string()));
57 #endif
58 EXPECT_EQ(CONTENT_SETTING_ASK,
59 map->GetContentSetting(example_url,
60 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
61 std::string()));
62
63 // Check content settings for www.google.com
64 GURL url("http://www.google.com");
65 EXPECT_EQ(CONTENT_SETTING_BLOCK,
66 map->GetCookieContentSetting(url, url, false));
67 EXPECT_EQ(CONTENT_SETTING_ALLOW,
68 map->GetContentSetting(url, CONTENT_SETTINGS_TYPE_IMAGES, ""));
69 EXPECT_EQ(CONTENT_SETTING_BLOCK,
70 map->GetContentSetting(url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
71 EXPECT_EQ(CONTENT_SETTING_BLOCK,
72 map->GetContentSetting(url, CONTENT_SETTINGS_TYPE_PLUGINS, ""));
73 EXPECT_EQ(CONTENT_SETTING_ALLOW,
74 map->GetContentSetting(url, CONTENT_SETTINGS_TYPE_POPUPS, ""));
75 #if 0
76 EXPECT_EQ(CONTENT_SETTING_BLOCK,
77 map->GetContentSetting(url, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
78 #endif
79 EXPECT_EQ(CONTENT_SETTING_BLOCK,
80 map->GetContentSetting(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
81 ""));
28 } 82 }
29 83
30 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PersistentIncognitoContentSettings) { 84 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PersistentIncognitoContentSettings) {
31 CommandLine::ForCurrentProcess()->AppendSwitch( 85 CommandLine::ForCurrentProcess()->AppendSwitch(
32 switches::kEnableExperimentalExtensionApis); 86 switches::kEnableExperimentalExtensionApis);
33 87
34 PrefService* prefs = browser()->profile()->GetPrefs(); 88 PrefService* prefs = browser()->profile()->GetPrefs();
35 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); 89 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
36 90
37 EXPECT_TRUE( 91 EXPECT_TRUE(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsOnChange) { 162 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettingsOnChange) {
109 CommandLine::ForCurrentProcess()->AppendSwitch( 163 CommandLine::ForCurrentProcess()->AppendSwitch(
110 switches::kEnableExperimentalExtensionApis); 164 switches::kEnableExperimentalExtensionApis);
111 165
112 PrefService* prefs = browser()->profile()->GetPrefs(); 166 PrefService* prefs = browser()->profile()->GetPrefs();
113 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false); 167 prefs->SetBoolean(prefs::kBlockThirdPartyCookies, false);
114 168
115 EXPECT_TRUE(RunExtensionTestIncognito("content_settings/onchange")) << 169 EXPECT_TRUE(RunExtensionTestIncognito("content_settings/onchange")) <<
116 message_; 170 message_;
117 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698