OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/extensions/extension_service_test_base.h" | 8 #include "chrome/browser/extensions/extension_service_test_base.h" |
9 #include "chrome/browser/extensions/extension_util.h" | 9 #include "chrome/browser/extensions/extension_util.h" |
10 #include "chrome/browser/extensions/permissions_updater.h" | 10 #include "chrome/browser/extensions/permissions_updater.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 using ScriptingPermissionsModifierUnitTest = ExtensionServiceTestBase; | 87 using ScriptingPermissionsModifierUnitTest = ExtensionServiceTestBase; |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 | 90 |
91 TEST_F(ScriptingPermissionsModifierUnitTest, WithholdAllHosts) { | 91 TEST_F(ScriptingPermissionsModifierUnitTest, WithholdAllHosts) { |
92 InitializeEmptyExtensionService(); | 92 InitializeEmptyExtensionService(); |
93 | 93 |
94 // Permissions are only withheld with the appropriate switch turned on. | 94 // Permissions are only withheld with the appropriate switch turned on. |
95 scoped_ptr<FeatureSwitch::ScopedOverride> switch_override( | 95 std::unique_ptr<FeatureSwitch::ScopedOverride> switch_override( |
96 new FeatureSwitch::ScopedOverride(FeatureSwitch::scripts_require_action(), | 96 new FeatureSwitch::ScopedOverride(FeatureSwitch::scripts_require_action(), |
97 FeatureSwitch::OVERRIDE_ENABLED)); | 97 FeatureSwitch::OVERRIDE_ENABLED)); |
98 | 98 |
99 URLPattern google(URLPattern::SCHEME_ALL, "http://www.google.com/*"); | 99 URLPattern google(URLPattern::SCHEME_ALL, "http://www.google.com/*"); |
100 URLPattern sub_google(URLPattern::SCHEME_ALL, "http://*.google.com/*"); | 100 URLPattern sub_google(URLPattern::SCHEME_ALL, "http://*.google.com/*"); |
101 URLPattern all_http(URLPattern::SCHEME_ALL, "http://*/*"); | 101 URLPattern all_http(URLPattern::SCHEME_ALL, "http://*/*"); |
102 URLPattern all_hosts(URLPattern::SCHEME_ALL, "<all_urls>"); | 102 URLPattern all_hosts(URLPattern::SCHEME_ALL, "<all_urls>"); |
103 URLPattern all_com(URLPattern::SCHEME_ALL, "http://*.com/*"); | 103 URLPattern all_com(URLPattern::SCHEME_ALL, "http://*.com/*"); |
104 | 104 |
105 std::set<URLPattern> all_host_patterns; | 105 std::set<URLPattern> all_host_patterns; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // Since the extension was created without the switch on, it should default | 235 // Since the extension was created without the switch on, it should default |
236 // to having all urls access. | 236 // to having all urls access. |
237 EXPECT_TRUE(SetsAreEqual( | 237 EXPECT_TRUE(SetsAreEqual( |
238 permissions_data->active_permissions().scriptable_hosts().patterns(), | 238 permissions_data->active_permissions().scriptable_hosts().patterns(), |
239 all_host_patterns)); | 239 all_host_patterns)); |
240 EXPECT_TRUE( | 240 EXPECT_TRUE( |
241 permissions_data->withheld_permissions().scriptable_hosts().is_empty()); | 241 permissions_data->withheld_permissions().scriptable_hosts().is_empty()); |
242 EXPECT_TRUE(util::AllowedScriptingOnAllUrls(extension_a->id(), profile())); | 242 EXPECT_TRUE(util::AllowedScriptingOnAllUrls(extension_a->id(), profile())); |
243 | 243 |
244 // Enable the switch, and re-init permission for the extension. | 244 // Enable the switch, and re-init permission for the extension. |
245 scoped_ptr<FeatureSwitch::ScopedOverride> switch_override( | 245 std::unique_ptr<FeatureSwitch::ScopedOverride> switch_override( |
246 new FeatureSwitch::ScopedOverride(FeatureSwitch::scripts_require_action(), | 246 new FeatureSwitch::ScopedOverride(FeatureSwitch::scripts_require_action(), |
247 FeatureSwitch::OVERRIDE_ENABLED)); | 247 FeatureSwitch::OVERRIDE_ENABLED)); |
248 updater.InitializePermissions(extension_a.get()); | 248 updater.InitializePermissions(extension_a.get()); |
249 | 249 |
250 // Since the extension was installed when the switch was off, it should still | 250 // Since the extension was installed when the switch was off, it should still |
251 // have the all urls pref. | 251 // have the all urls pref. |
252 permissions_data = extension_a->permissions_data(); | 252 permissions_data = extension_a->permissions_data(); |
253 EXPECT_TRUE(SetsAreEqual( | 253 EXPECT_TRUE(SetsAreEqual( |
254 permissions_data->active_permissions().scriptable_hosts().patterns(), | 254 permissions_data->active_permissions().scriptable_hosts().patterns(), |
255 all_host_patterns)); | 255 all_host_patterns)); |
(...skipping 26 matching lines...) Expand all Loading... |
282 EXPECT_TRUE(SetsAreEqual( | 282 EXPECT_TRUE(SetsAreEqual( |
283 permissions_data->withheld_permissions().scriptable_hosts().patterns(), | 283 permissions_data->withheld_permissions().scriptable_hosts().patterns(), |
284 all_host_patterns)); | 284 all_host_patterns)); |
285 EXPECT_FALSE(util::AllowedScriptingOnAllUrls(extension_b->id(), profile())); | 285 EXPECT_FALSE(util::AllowedScriptingOnAllUrls(extension_b->id(), profile())); |
286 } | 286 } |
287 | 287 |
288 TEST_F(ScriptingPermissionsModifierUnitTest, GrantHostPermission) { | 288 TEST_F(ScriptingPermissionsModifierUnitTest, GrantHostPermission) { |
289 InitializeEmptyExtensionService(); | 289 InitializeEmptyExtensionService(); |
290 | 290 |
291 // Permissions are only withheld with the appropriate switch turned on. | 291 // Permissions are only withheld with the appropriate switch turned on. |
292 scoped_ptr<FeatureSwitch::ScopedOverride> switch_override( | 292 std::unique_ptr<FeatureSwitch::ScopedOverride> switch_override( |
293 new FeatureSwitch::ScopedOverride(FeatureSwitch::scripts_require_action(), | 293 new FeatureSwitch::ScopedOverride(FeatureSwitch::scripts_require_action(), |
294 FeatureSwitch::OVERRIDE_ENABLED)); | 294 FeatureSwitch::OVERRIDE_ENABLED)); |
295 | 295 |
296 URLPattern all_hosts(URLPattern::SCHEME_ALL, "<all_urls>"); | 296 URLPattern all_hosts(URLPattern::SCHEME_ALL, "<all_urls>"); |
297 std::set<URLPattern> all_host_patterns; | 297 std::set<URLPattern> all_host_patterns; |
298 all_host_patterns.insert(all_hosts); | 298 all_host_patterns.insert(all_hosts); |
299 | 299 |
300 scoped_refptr<const Extension> extension = CreateExtensionWithPermissions( | 300 scoped_refptr<const Extension> extension = CreateExtensionWithPermissions( |
301 all_host_patterns, all_host_patterns, Manifest::INTERNAL, "extension"); | 301 all_host_patterns, all_host_patterns, Manifest::INTERNAL, "extension"); |
302 PermissionsUpdater(profile()).InitializePermissions(extension.get()); | 302 PermissionsUpdater(profile()).InitializePermissions(extension.get()); |
(...skipping 20 matching lines...) Expand all Loading... |
323 EXPECT_EQ(PermissionsData::ACCESS_WITHHELD, get_page_access(kUrl2)); | 323 EXPECT_EQ(PermissionsData::ACCESS_WITHHELD, get_page_access(kUrl2)); |
324 | 324 |
325 modifier.RemoveGrantedHostPermission(kUrl); | 325 modifier.RemoveGrantedHostPermission(kUrl); |
326 EXPECT_FALSE(modifier.HasGrantedHostPermission(kUrl)); | 326 EXPECT_FALSE(modifier.HasGrantedHostPermission(kUrl)); |
327 EXPECT_FALSE(modifier.HasGrantedHostPermission(kUrl2)); | 327 EXPECT_FALSE(modifier.HasGrantedHostPermission(kUrl2)); |
328 EXPECT_EQ(PermissionsData::ACCESS_WITHHELD, get_page_access(kUrl)); | 328 EXPECT_EQ(PermissionsData::ACCESS_WITHHELD, get_page_access(kUrl)); |
329 EXPECT_EQ(PermissionsData::ACCESS_WITHHELD, get_page_access(kUrl2)); | 329 EXPECT_EQ(PermissionsData::ACCESS_WITHHELD, get_page_access(kUrl2)); |
330 } | 330 } |
331 | 331 |
332 } // namespace extensions | 332 } // namespace extensions |
OLD | NEW |