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

Side by Side Diff: chrome/browser/extensions/api/content_settings/content_settings_apitest.cc

Issue 23694020: Don't clear existing extension-defined preferences and content settings when reloading or updating… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 7 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/content_settings/cookie_settings.h" 7 #include "chrome/browser/content_settings/cookie_settings.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h" 9 #include "chrome/browser/extensions/api/content_settings/content_settings_api.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/plugin_service.h" 15 #include "content/public/browser/plugin_service.h"
16 #include "content/public/common/webplugininfo.h" 16 #include "content/public/common/webplugininfo.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentSettings) { 20 class ExtensionContentSettingsApiTest : public ExtensionApiTest {
21 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_; 21 public:
22 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
23 ExtensionApiTest::SetUpCommandLine(command_line);
24 command_line->AppendSwitch(switches::kDisablePluginsDiscovery);
25 }
22 26
23 HostContentSettingsMap* map = 27 protected:
24 browser()->profile()->GetHostContentSettingsMap(); 28 void CheckContentSettings() {
25 CookieSettings* cookie_settings = 29 HostContentSettingsMap* map =
26 CookieSettings::Factory::GetForProfile(browser()->profile()).get(); 30 browser()->profile()->GetHostContentSettingsMap();
31 CookieSettings* cookie_settings =
32 CookieSettings::Factory::GetForProfile(browser()->profile()).get();
27 33
28 // Check default content settings by using an unknown URL. 34 // Check default content settings by using an unknown URL.
29 GURL example_url("http://www.example.com"); 35 GURL example_url("http://www.example.com");
30 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( 36 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
31 example_url, example_url)); 37 example_url, example_url));
32 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 38 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
33 example_url, example_url)); 39 example_url, example_url));
34 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(example_url)); 40 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(example_url));
35 EXPECT_EQ(CONTENT_SETTING_ALLOW, 41 EXPECT_EQ(CONTENT_SETTING_ALLOW,
36 map->GetContentSetting(example_url, 42 map->GetContentSetting(example_url,
37 example_url, 43 example_url,
38 CONTENT_SETTINGS_TYPE_IMAGES, 44 CONTENT_SETTINGS_TYPE_IMAGES,
39 std::string())); 45 std::string()));
40 EXPECT_EQ(CONTENT_SETTING_BLOCK, 46 EXPECT_EQ(CONTENT_SETTING_BLOCK,
41 map->GetContentSetting(example_url, 47 map->GetContentSetting(example_url,
42 example_url, 48 example_url,
43 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 49 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
44 std::string())); 50 std::string()));
45 EXPECT_EQ(CONTENT_SETTING_ALLOW, 51 EXPECT_EQ(CONTENT_SETTING_ALLOW,
46 map->GetContentSetting(example_url, 52 map->GetContentSetting(example_url,
47 example_url, 53 example_url,
48 CONTENT_SETTINGS_TYPE_PLUGINS, 54 CONTENT_SETTINGS_TYPE_PLUGINS,
49 std::string())); 55 std::string()));
50 EXPECT_EQ(CONTENT_SETTING_BLOCK, 56 EXPECT_EQ(CONTENT_SETTING_BLOCK,
51 map->GetContentSetting(example_url, 57 map->GetContentSetting(example_url,
52 example_url, 58 example_url,
53 CONTENT_SETTINGS_TYPE_POPUPS, 59 CONTENT_SETTINGS_TYPE_POPUPS,
54 std::string())); 60 std::string()));
55 #if 0 61 #if 0
56 // TODO(bauerb): Enable once geolocation settings are integrated into the 62 // TODO(bauerb): Enable once geolocation settings are integrated into the
57 // HostContentSettingsMap. 63 // HostContentSettingsMap.
58 EXPECT_EQ(CONTENT_SETTING_ALLOW, 64 EXPECT_EQ(CONTENT_SETTING_ALLOW,
59 map->GetContentSetting(example_url, 65 map->GetContentSetting(example_url,
60 example_url, 66 example_url,
61 CONTENT_SETTINGS_TYPE_GEOLOCATION, 67 CONTENT_SETTINGS_TYPE_GEOLOCATION,
62 std::string())); 68 std::string()));
63 #endif 69 #endif
64 EXPECT_EQ(CONTENT_SETTING_ASK, 70 EXPECT_EQ(CONTENT_SETTING_ASK,
65 map->GetContentSetting(example_url, 71 map->GetContentSetting(example_url,
66 example_url, 72 example_url,
67 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 73 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
68 std::string())); 74 std::string()));
69 75
70 // Check content settings for www.google.com 76 // Check content settings for www.google.com
71 GURL url("http://www.google.com"); 77 GURL url("http://www.google.com");
72 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(url, url)); 78 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(url, url));
73 EXPECT_EQ(CONTENT_SETTING_ALLOW, 79 EXPECT_EQ(CONTENT_SETTING_ALLOW,
74 map->GetContentSetting( 80 map->GetContentSetting(
75 url, url, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 81 url, url, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
76 EXPECT_EQ(CONTENT_SETTING_BLOCK, 82 EXPECT_EQ(CONTENT_SETTING_BLOCK,
77 map->GetContentSetting( 83 map->GetContentSetting(
78 url, url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 84 url, url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
79 EXPECT_EQ(CONTENT_SETTING_BLOCK, 85 EXPECT_EQ(CONTENT_SETTING_BLOCK,
80 map->GetContentSetting( 86 map->GetContentSetting(
81 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 87 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
82 EXPECT_EQ(CONTENT_SETTING_ALLOW, 88 EXPECT_EQ(CONTENT_SETTING_ALLOW,
83 map->GetContentSetting( 89 map->GetContentSetting(
84 url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); 90 url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
85 #if 0 91 #if 0
86 EXPECT_EQ(CONTENT_SETTING_BLOCK, 92 EXPECT_EQ(CONTENT_SETTING_BLOCK,
87 map->GetContentSetting( 93 map->GetContentSetting(
88 url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); 94 url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
89 #endif 95 #endif
90 EXPECT_EQ(CONTENT_SETTING_BLOCK, 96 EXPECT_EQ(
91 map->GetContentSetting( 97 CONTENT_SETTING_BLOCK,
92 url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 98 map->GetContentSetting(
93 } 99 url, url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
94
95 class ContentSettingsGetResourceIdentifiersTest : public ExtensionApiTest {
96 public:
97 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
98 ExtensionApiTest::SetUpCommandLine(command_line);
99 command_line->AppendSwitch(switches::kDisablePluginsDiscovery);
100 } 100 }
101 }; 101 };
102 102
103 IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest, Standard) {
104 EXPECT_TRUE(RunExtensionTest("content_settings/standard")) << message_;
105
106 CheckContentSettings();
107
108 // The settings should not be reset when the extension is reloaded.
Jeffrey Yasskin 2013/09/06 21:31:56 Could you also check that an uninstall+reinstall d
109 ReloadExtension(last_loaded_extension_id_);
110 CheckContentSettings();
111 }
112
103 // Flaky on the trybots. See http://crbug.com/96725. 113 // Flaky on the trybots. See http://crbug.com/96725.
104 IN_PROC_BROWSER_TEST_F(ContentSettingsGetResourceIdentifiersTest, 114 IN_PROC_BROWSER_TEST_F(ExtensionContentSettingsApiTest,
105 DISABLED_Test) { 115 DISABLED_GetResourceIdentifiers) {
106 base::FilePath::CharType kFooPath[] = 116 base::FilePath::CharType kFooPath[] =
107 FILE_PATH_LITERAL("/plugins/foo.plugin"); 117 FILE_PATH_LITERAL("/plugins/foo.plugin");
108 base::FilePath::CharType kBarPath[] = 118 base::FilePath::CharType kBarPath[] =
109 FILE_PATH_LITERAL("/plugins/bar.plugin"); 119 FILE_PATH_LITERAL("/plugins/bar.plugin");
110 const char* kFooName = "Foo Plugin"; 120 const char* kFooName = "Foo Plugin";
111 const char* kBarName = "Bar Plugin"; 121 const char* kBarName = "Bar Plugin";
112 122
113 content::PluginService::GetInstance()->RegisterInternalPlugin( 123 content::PluginService::GetInstance()->RegisterInternalPlugin(
114 content::WebPluginInfo(ASCIIToUTF16(kFooName), 124 content::WebPluginInfo(ASCIIToUTF16(kFooName),
115 base::FilePath(kFooPath), 125 base::FilePath(kFooPath),
116 ASCIIToUTF16("1.2.3"), 126 ASCIIToUTF16("1.2.3"),
117 ASCIIToUTF16("foo")), 127 ASCIIToUTF16("foo")),
118 false); 128 false);
119 content::PluginService::GetInstance()->RegisterInternalPlugin( 129 content::PluginService::GetInstance()->RegisterInternalPlugin(
120 content::WebPluginInfo(ASCIIToUTF16(kBarName), 130 content::WebPluginInfo(ASCIIToUTF16(kBarName),
121 base::FilePath(kBarPath), 131 base::FilePath(kBarPath),
122 ASCIIToUTF16("2.3.4"), 132 ASCIIToUTF16("2.3.4"),
123 ASCIIToUTF16("bar")), 133 ASCIIToUTF16("bar")),
124 false); 134 false);
125 135
126 EXPECT_TRUE(RunExtensionTest("content_settings/getresourceidentifiers")) 136 EXPECT_TRUE(RunExtensionTest("content_settings/getresourceidentifiers"))
127 << message_; 137 << message_;
128 } 138 }
129 139
130 } // namespace extensions 140 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698