| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/callback_helpers.h" |
| 6 #include "base/run_loop.h" |
| 7 #include "chrome/browser/extensions/chrome_test_extension_loader.h" |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/navigation_observer.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "extensions/browser/extension_dialog_auto_confirm.h" |
| 13 #include "extensions/browser/extension_prefs.h" |
| 14 #include "extensions/browser/extension_registry.h" |
| 15 #include "extensions/common/extension.h" |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 // Test that visiting an url associated with a disabled extension offers to |
| 20 // re-enable it. |
| 21 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, |
| 22 PromptToReEnableExtensionsOnNavigation) { |
| 23 NavigationObserver::SetAllowedRepeatedPromptingForTesting(true); |
| 24 base::ScopedClosureRunner reset_repeated_prompting(base::Bind([]() { |
| 25 NavigationObserver::SetAllowedRepeatedPromptingForTesting(false); |
| 26 })); |
| 27 scoped_refptr<const Extension> extension = |
| 28 ChromeTestExtensionLoader(profile()).LoadExtension( |
| 29 test_data_dir_.AppendASCII("simple_with_file")); |
| 30 ASSERT_TRUE(extension); |
| 31 const std::string kExtensionId = extension->id(); |
| 32 const GURL kUrl = extension->GetResourceURL("file.html"); |
| 33 |
| 34 // We always navigate in a new tab because when we disable the extension, it |
| 35 // closes all tabs for that extension. If we only opened in the current tab, |
| 36 // this would result in the only open tab being closed, and the test quitting. |
| 37 auto navigate_to_url_in_new_tab = [this](const GURL& url) { |
| 38 ui_test_utils::NavigateToURLWithDisposition( |
| 39 browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 40 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 41 }; |
| 42 |
| 43 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 44 EXPECT_TRUE(registry->enabled_extensions().Contains(kExtensionId)); |
| 45 |
| 46 // Disable the extension due to a permissions increase. |
| 47 extension_service()->DisableExtension( |
| 48 kExtensionId, Extension::DISABLE_PERMISSIONS_INCREASE); |
| 49 EXPECT_TRUE(registry->disabled_extensions().Contains(kExtensionId)); |
| 50 |
| 51 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 52 EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE, |
| 53 prefs->GetDisableReasons(kExtensionId)); |
| 54 |
| 55 { |
| 56 // Visit an associated url and deny the prompt. The extension should remain |
| 57 // disabled. |
| 58 ScopedTestDialogAutoConfirm auto_deny(ScopedTestDialogAutoConfirm::CANCEL); |
| 59 navigate_to_url_in_new_tab(kUrl); |
| 60 base::RunLoop().RunUntilIdle(); |
| 61 EXPECT_TRUE(registry->disabled_extensions().Contains(kExtensionId)); |
| 62 EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE, |
| 63 prefs->GetDisableReasons(kExtensionId)); |
| 64 } |
| 65 |
| 66 { |
| 67 // Visit an associated url and accept the prompt. The extension should get |
| 68 // re-enabled. |
| 69 ScopedTestDialogAutoConfirm auto_accept( |
| 70 ScopedTestDialogAutoConfirm::ACCEPT); |
| 71 navigate_to_url_in_new_tab(kUrl); |
| 72 base::RunLoop().RunUntilIdle(); |
| 73 EXPECT_TRUE(registry->enabled_extensions().Contains(kExtensionId)); |
| 74 EXPECT_EQ(Extension::DISABLE_NONE, prefs->GetDisableReasons(kExtensionId)); |
| 75 } |
| 76 |
| 77 // Disable the extension for something other than a permissions increase. |
| 78 extension_service()->DisableExtension(kExtensionId, |
| 79 Extension::DISABLE_USER_ACTION); |
| 80 EXPECT_TRUE(registry->disabled_extensions().Contains(kExtensionId)); |
| 81 EXPECT_EQ(Extension::DISABLE_USER_ACTION, |
| 82 prefs->GetDisableReasons(kExtensionId)); |
| 83 |
| 84 { |
| 85 // We only prompt for permissions increases, not any other disable reason. |
| 86 // As such, the extension should stay disabled. |
| 87 ScopedTestDialogAutoConfirm auto_accept( |
| 88 ScopedTestDialogAutoConfirm::ACCEPT); |
| 89 navigate_to_url_in_new_tab(kUrl); |
| 90 base::RunLoop().RunUntilIdle(); |
| 91 EXPECT_TRUE(registry->disabled_extensions().Contains(kExtensionId)); |
| 92 EXPECT_EQ(Extension::DISABLE_USER_ACTION, |
| 93 prefs->GetDisableReasons(kExtensionId)); |
| 94 } |
| 95 |
| 96 // Load a hosted app and disable it for a permissions increase. |
| 97 scoped_refptr<const Extension> hosted_app = |
| 98 ChromeTestExtensionLoader(profile()).LoadExtension( |
| 99 test_data_dir_.AppendASCII("hosted_app")); |
| 100 ASSERT_TRUE(hosted_app); |
| 101 const std::string kHostedAppId = hosted_app->id(); |
| 102 const GURL kHostedAppUrl("http://localhost/extensions/hosted_app/main.html"); |
| 103 EXPECT_EQ(hosted_app, registry->enabled_extensions().GetExtensionOrAppByURL( |
| 104 kHostedAppUrl)); |
| 105 |
| 106 extension_service()->DisableExtension( |
| 107 kHostedAppId, Extension::DISABLE_PERMISSIONS_INCREASE); |
| 108 EXPECT_TRUE(registry->disabled_extensions().Contains(kHostedAppId)); |
| 109 EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE, |
| 110 prefs->GetDisableReasons(kHostedAppId)); |
| 111 |
| 112 { |
| 113 // When visiting a site that's associated with a hosted app, but not a |
| 114 // chrome-extension url, we don't prompt to re-enable. This is to avoid |
| 115 // prompting when visiting a regular website like calendar.google.com. |
| 116 // See crbug.com/678631. |
| 117 ScopedTestDialogAutoConfirm auto_accept( |
| 118 ScopedTestDialogAutoConfirm::ACCEPT); |
| 119 navigate_to_url_in_new_tab(kHostedAppUrl); |
| 120 base::RunLoop().RunUntilIdle(); |
| 121 EXPECT_TRUE(registry->disabled_extensions().Contains(kHostedAppId)); |
| 122 EXPECT_EQ(Extension::DISABLE_PERMISSIONS_INCREASE, |
| 123 prefs->GetDisableReasons(kHostedAppId)); |
| 124 } |
| 125 } |
| 126 |
| 127 } // namespace extensions |
| OLD | NEW |