OLD | NEW |
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 "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/extensions/extension_util.h" |
7 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 8 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
12 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
13 | 14 |
14 namespace extensions { | 15 namespace extensions { |
15 | 16 |
16 namespace { | 17 namespace { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 EXPECT_FALSE(dict.GetProxyServer(&value)); | 62 EXPECT_FALSE(dict.GetProxyServer(&value)); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 void ExpectNoSettings(PrefService* pref_service) { | 66 void ExpectNoSettings(PrefService* pref_service) { |
66 const PrefService::Preference* pref = | 67 const PrefService::Preference* pref = |
67 pref_service->FindPreference(prefs::kProxy); | 68 pref_service->FindPreference(prefs::kProxy); |
68 ASSERT_TRUE(pref != NULL); | 69 ASSERT_TRUE(pref != NULL); |
69 EXPECT_FALSE(pref->IsExtensionControlled()); | 70 EXPECT_FALSE(pref->IsExtensionControlled()); |
70 } | 71 } |
| 72 |
| 73 bool SetIsIncognitoEnabled(bool enabled) { |
| 74 ResultCatcher catcher; |
| 75 extensions::util::SetIsIncognitoEnabled( |
| 76 GetSingleLoadedExtension()->id(), browser()->profile(), enabled); |
| 77 if (!catcher.GetNextResult()) { |
| 78 message_ = catcher.message(); |
| 79 return false; |
| 80 } |
| 81 return true; |
| 82 } |
71 }; | 83 }; |
72 | 84 |
73 // Tests direct connection settings. | 85 // Tests direct connection settings. |
74 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyDirectSettings) { | 86 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyDirectSettings) { |
75 ASSERT_TRUE(RunExtensionTestIncognito("proxy/direct")) << message_; | 87 ASSERT_TRUE(RunExtensionTestIncognito("proxy/direct")) << message_; |
76 const Extension* extension = GetSingleLoadedExtension(); | 88 const Extension* extension = GetSingleLoadedExtension(); |
77 ASSERT_TRUE(extension); | 89 ASSERT_TRUE(extension); |
78 | 90 |
79 PrefService* pref_service = browser()->profile()->GetPrefs(); | 91 PrefService* pref_service = browser()->profile()->GetPrefs(); |
80 ValidateSettings(ProxyPrefs::MODE_DIRECT, kNoServer, kNoBypass, kNoPac, | 92 ValidateSettings(ProxyPrefs::MODE_DIRECT, kNoServer, kNoBypass, kNoPac, |
81 pref_service); | 93 pref_service); |
| 94 |
| 95 // As the extension is executed with incognito permission, the settings |
| 96 // should propagate to incognito mode. |
| 97 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); |
| 98 ValidateSettings(ProxyPrefs::MODE_DIRECT, kNoServer, kNoBypass, kNoPac, |
| 99 pref_service); |
82 } | 100 } |
83 | 101 |
84 // Tests auto-detect settings. | 102 // Tests auto-detect settings. |
85 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyAutoSettings) { | 103 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyAutoSettings) { |
86 ASSERT_TRUE(RunExtensionTestIncognito("proxy/auto")) << message_; | 104 ASSERT_TRUE(RunExtensionTestIncognito("proxy/auto")) << message_; |
87 const Extension* extension = GetSingleLoadedExtension(); | 105 const Extension* extension = GetSingleLoadedExtension(); |
88 ASSERT_TRUE(extension); | 106 ASSERT_TRUE(extension); |
89 | 107 |
90 PrefService* pref_service = browser()->profile()->GetPrefs(); | 108 PrefService* pref_service = browser()->profile()->GetPrefs(); |
91 ValidateSettings(ProxyPrefs::MODE_AUTO_DETECT, kNoServer, kNoBypass, kNoPac, | 109 ValidateSettings(ProxyPrefs::MODE_AUTO_DETECT, kNoServer, kNoBypass, kNoPac, |
92 pref_service); | 110 pref_service); |
93 } | 111 } |
94 | 112 |
95 // Tests PAC proxy settings. | 113 // Tests PAC proxy settings. |
96 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyPacScript) { | 114 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyPacScript) { |
97 ASSERT_TRUE(RunExtensionTest("proxy/pac")) << message_; | 115 ASSERT_TRUE(RunExtensionTest("proxy/pac")) << message_; |
98 const Extension* extension = GetSingleLoadedExtension(); | 116 const Extension* extension = GetSingleLoadedExtension(); |
99 ASSERT_TRUE(extension); | 117 ASSERT_TRUE(extension); |
100 | 118 |
101 PrefService* pref_service = browser()->profile()->GetPrefs(); | 119 PrefService* pref_service = browser()->profile()->GetPrefs(); |
102 ValidateSettings(ProxyPrefs::MODE_PAC_SCRIPT, kNoServer, kNoBypass, | 120 ValidateSettings(ProxyPrefs::MODE_PAC_SCRIPT, kNoServer, kNoBypass, |
103 "http://wpad/windows.pac", pref_service); | 121 "http://wpad/windows.pac", pref_service); |
| 122 |
| 123 // As the extension is not executed with incognito permission, the settings |
| 124 // should not propagate to incognito mode. |
| 125 pref_service = browser()->profile()->GetOffTheRecordProfile()->GetPrefs(); |
| 126 ExpectNoSettings(pref_service); |
| 127 |
| 128 // Now we enable the extension in incognito mode and verify that settings |
| 129 // are applied. |
| 130 ASSERT_TRUE(SetIsIncognitoEnabled(true)); |
| 131 ValidateSettings(ProxyPrefs::MODE_PAC_SCRIPT, kNoServer, kNoBypass, |
| 132 "http://wpad/windows.pac", pref_service); |
| 133 |
| 134 // Disabling incognito permission should revoke the settings for incognito |
| 135 // mode. |
| 136 ASSERT_TRUE(SetIsIncognitoEnabled(false)); |
| 137 ExpectNoSettings(pref_service); |
104 } | 138 } |
105 | 139 |
106 // Tests PAC proxy settings. | 140 // Tests PAC proxy settings. |
107 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyPacDataUrl) { | 141 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyPacDataUrl) { |
108 ASSERT_TRUE(RunExtensionTest("proxy/pacdataurl")) << message_; | 142 ASSERT_TRUE(RunExtensionTest("proxy/pacdataurl")) << message_; |
109 const Extension* extension = GetSingleLoadedExtension(); | 143 const Extension* extension = GetSingleLoadedExtension(); |
110 ASSERT_TRUE(extension); | 144 ASSERT_TRUE(extension); |
111 const char url[] = | 145 const char url[] = |
112 "data:;base64,ZnVuY3Rpb24gRmluZFByb3h5R" | 146 "data:;base64,ZnVuY3Rpb24gRmluZFByb3h5R" |
113 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" | 147 "m9yVVJMKHVybCwgaG9zdCkgewogIGlmIChob3N0ID09ICdmb29iYXIuY29tJykKICAgIHJl" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 RunExtensionSubtest("proxy/events", "invalid_proxy.html")) << message_; | 322 RunExtensionSubtest("proxy/events", "invalid_proxy.html")) << message_; |
289 } | 323 } |
290 | 324 |
291 // Tests error events: PAC script parse error. | 325 // Tests error events: PAC script parse error. |
292 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyEventsParseError) { | 326 IN_PROC_BROWSER_TEST_F(ProxySettingsApiTest, ProxyEventsParseError) { |
293 ASSERT_TRUE( | 327 ASSERT_TRUE( |
294 RunExtensionSubtest("proxy/events", "parse_error.html")) << message_; | 328 RunExtensionSubtest("proxy/events", "parse_error.html")) << message_; |
295 } | 329 } |
296 | 330 |
297 } // namespace extensions | 331 } // namespace extensions |
OLD | NEW |