OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/active_script_controller.h" | 8 #include "chrome/browser/extensions/active_script_controller.h" |
9 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 9 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 | 315 |
316 // Turning off the preference should have instant effect. | 316 // Turning off the preference should have instant effect. |
317 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); | 317 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), false); |
318 EXPECT_TRUE(RequiresUserConsent(extension)); | 318 EXPECT_TRUE(RequiresUserConsent(extension)); |
319 | 319 |
320 // And should also persist across navigations and websites. | 320 // And should also persist across navigations and websites. |
321 NavigateAndCommit(GURL("http://www.bar.com")); | 321 NavigateAndCommit(GURL("http://www.bar.com")); |
322 EXPECT_TRUE(RequiresUserConsent(extension)); | 322 EXPECT_TRUE(RequiresUserConsent(extension)); |
323 } | 323 } |
324 | 324 |
325 // Test that the "always allow" extension action context menu item will create | |
326 // a valid persisted permission even when active permissions are cleared. | |
327 TEST_F(ActiveScriptControllerUnitTest, TestAlwaysAllow) { | |
328 const Extension* extension = AddExtension(); | |
329 ASSERT_TRUE(extension); | |
330 | |
331 NavigateAndCommit(GURL("https://www.google.com")); | |
332 | |
333 // Ensure that there aren't any executions pending. | |
334 ASSERT_EQ(0u, GetExecutionCountForExtension(extension->id())); | |
335 ASSERT_FALSE(controller()->GetActionForExtension(extension)); | |
336 | |
337 // Since the extension requests all_hosts, we should require user consent. | |
338 EXPECT_TRUE(RequiresUserConsent(extension)); | |
339 | |
340 // Request an injection. There should be an action visible, but no executions. | |
341 RequestInjection(extension); | |
342 EXPECT_TRUE(controller()->GetActionForExtension(extension)); | |
343 EXPECT_EQ(0u, GetExecutionCountForExtension(extension->id())); | |
344 | |
345 // Simulate clicking "always allow" menu item. | |
346 controller()->AddPersistedPermission(extension); | |
347 | |
348 // The extension should execute, and the action should go away. | |
349 EXPECT_EQ(1u, GetExecutionCountForExtension(extension->id())); | |
350 EXPECT_FALSE(controller()->GetActionForExtension(extension)); | |
351 | |
not at google - send to devlin
2014/08/01 18:15:12
could you also check the effective permission set,
gpdavis
2014/08/07 20:50:39
Let's re-explore this unit test once we're happy w
| |
352 // Since we already executed on the given page, we shouldn't need permission | |
353 // for a second time. | |
354 EXPECT_FALSE(RequiresUserConsent(extension)); | |
355 | |
356 // Navigating to another site that hasn't been granted a persisted permission | |
357 // should necessitate user consent. | |
358 NavigateAndCommit(GURL("https://www.foo.com")); | |
359 EXPECT_TRUE(RequiresUserConsent(extension)); | |
360 | |
361 // We shouldn't need user permission upon returning to the original host. | |
362 NavigateAndCommit(GURL("https://www.google.com")); | |
363 EXPECT_FALSE(RequiresUserConsent(extension)); | |
364 | |
365 // Reinitializing permissions should clear active permissions, but not | |
366 // persisted permissions. | |
367 PermissionsUpdater(profile()).InitializePermissions(extension); | |
368 Reload(); | |
369 EXPECT_FALSE(RequiresUserConsent(extension)); | |
370 } | |
371 | |
325 } // namespace extensions | 372 } // namespace extensions |
OLD | NEW |