diff options
7 files changed, 70 insertions, 43 deletions
diff --git a/chrome/browser/extensions/extension_install_dialog.cc b/chrome/browser/extensions/extension_install_dialog.cc index dad6d26..55b6b68 100644 --- a/chrome/browser/extensions/extension_install_dialog.cc +++ b/chrome/browser/extensions/extension_install_dialog.cc @@ -1,14 +1,16 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/extensions/extension_install_dialog.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/file_path.h" #include "base/message_loop.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" namespace { @@ -19,7 +21,6 @@ enum AutoConfirmForTest { PROCEED, ABORT }; -AutoConfirmForTest auto_confirm_for_tests = DO_NOT_SKIP; void AutoConfirmTask(ExtensionInstallUI::Delegate* delegate, bool proceed) { if (proceed) @@ -28,8 +29,9 @@ void AutoConfirmTask(ExtensionInstallUI::Delegate* delegate, bool proceed) { delegate->InstallUIAbort(true); } -void DoAutoConfirm(ExtensionInstallUI::Delegate* delegate) { - bool proceed = (auto_confirm_for_tests == PROCEED); +void DoAutoConfirm(AutoConfirmForTest setting, + ExtensionInstallUI::Delegate* delegate) { + bool proceed = (setting == PROCEED); // We use PostTask instead of calling the delegate directly here, because in // the real implementations it's highly likely the message loop will be // pumping a few times before the user clicks accept or cancel. @@ -38,6 +40,21 @@ void DoAutoConfirm(ExtensionInstallUI::Delegate* delegate) { base::Bind(&AutoConfirmTask, delegate, proceed)); } +AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() { + const CommandLine* cmdline = CommandLine::ForCurrentProcess(); + if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) + return DO_NOT_SKIP; + std::string value = cmdline->GetSwitchValueASCII( + switches::kAppsGalleryInstallAutoConfirmForTests); + if (value == "accept") + return PROCEED; + else if (value == "cancel") + return ABORT; + else + NOTREACHED(); + return DO_NOT_SKIP; +} + } // namespace void ShowExtensionInstallDialog(Profile* profile, @@ -45,8 +62,9 @@ void ShowExtensionInstallDialog(Profile* profile, const Extension* extension, SkBitmap* icon, const ExtensionInstallUI::Prompt& prompt) { - if (auto_confirm_for_tests != DO_NOT_SKIP) { - DoAutoConfirm(delegate); + AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); + if (auto_confirm != DO_NOT_SKIP) { + DoAutoConfirm(auto_confirm, delegate); return; } ShowExtensionInstallDialogImpl(profile, delegate, extension, icon, prompt); @@ -93,8 +111,9 @@ bool ShowExtensionInstallDialogForManifest( // In tests, we may have setup to proceed or abort without putting up the real // confirmation dialog. - if (auto_confirm_for_tests != DO_NOT_SKIP) { - DoAutoConfirm(delegate); + AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); + if (auto_confirm != DO_NOT_SKIP) { + DoAutoConfirm(auto_confirm, delegate); return true; } @@ -109,8 +128,3 @@ bool ShowExtensionInstallDialogForManifest( filled_out_prompt); return true; } - -void SetExtensionInstallDialogAutoConfirmForTests( - bool should_proceed) { - auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; -} diff --git a/chrome/browser/extensions/extension_install_dialog.h b/chrome/browser/extensions/extension_install_dialog.h index 4124635..e4575c9 100644 --- a/chrome/browser/extensions/extension_install_dialog.h +++ b/chrome/browser/extensions/extension_install_dialog.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -54,10 +54,4 @@ bool ShowExtensionInstallDialogForManifest( const ExtensionInstallUI::Prompt& prompt, scoped_refptr<Extension>* dummy_extension); -// For use only in tests - sets a flag that makes invocations of -// ShowExtensionInstallDialog* skip putting up a real dialog, and -// instead act as if the dialog choice was to proceed or abort. -void SetExtensionInstallDialogAutoConfirmForTests( - bool should_proceed); - #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_DIALOG_H_ diff --git a/chrome/browser/extensions/extension_management_api_browsertest.cc b/chrome/browser/extensions/extension_management_api_browsertest.cc index c226902..9966f01 100644 --- a/chrome/browser/extensions/extension_management_api_browsertest.cc +++ b/chrome/browser/extensions/extension_management_api_browsertest.cc @@ -1,7 +1,8 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" #include "base/stringprintf.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_function_test_utils.h" @@ -13,6 +14,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/chrome_switches.h" namespace keys = extension_management_api_constants; namespace util = extension_function_test_utils; @@ -121,10 +123,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementApiEscalationTest, ReEnable(false, keys::kGestureNeededForEscalationError); // Expect an error that user cancelled the dialog. - SetExtensionInstallDialogAutoConfirmForTests(false); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); ReEnable(true, keys::kUserDidNotReEnableError); // This should succeed when user accepts dialog. - SetExtensionInstallDialogAutoConfirmForTests(true); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); ReEnable(true, ""); } diff --git a/chrome/browser/extensions/extension_webstore_private_apitest.cc b/chrome/browser/extensions/extension_webstore_private_apitest.cc index b4b70b3..99b3f1e 100644 --- a/chrome/browser/extensions/extension_webstore_private_apitest.cc +++ b/chrome/browser/extensions/extension_webstore_private_apitest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -90,8 +90,10 @@ class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { public: void SetUpCommandLine(CommandLine* command_line) OVERRIDE { ExtensionApiTest::SetUpCommandLine(command_line); - command_line->AppendSwitchASCII(switches::kAppsGalleryURL, - "http://www.example.com"); + command_line->AppendSwitchASCII( + switches::kAppsGalleryURL, "http://www.example.com"); + command_line->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); } void SetUpInProcessBrowserTestFixture() OVERRIDE { @@ -99,7 +101,6 @@ class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { // API functions. host_resolver()->AddRule("www.example.com", "127.0.0.1"); ASSERT_TRUE(test_server()->Start()); - SetExtensionInstallDialogAutoConfirmForTests(true); ExtensionInstallUI::DisableFailureUIForTests(); } @@ -233,7 +234,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { // Now test the case where the user cancels the confirmation dialog. IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { - SetExtensionInstallDialogAutoConfirmForTests(false); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); } diff --git a/chrome/browser/extensions/webstore_inline_install_browsertest.cc b/chrome/browser/extensions/webstore_inline_install_browsertest.cc index 664751d..ea82dd0 100644 --- a/chrome/browser/extensions/webstore_inline_install_browsertest.cc +++ b/chrome/browser/extensions/webstore_inline_install_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -82,7 +82,8 @@ class WebstoreInlineInstallTest : public InProcessBrowserTest { }; IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) { - SetExtensionInstallDialogAutoConfirmForTests(true); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); ui_test_utils::NavigateToURL( browser(), GenerateTestServerUrl(kAppDomain, "install.html")); @@ -96,7 +97,8 @@ IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, Install) { IN_PROC_BROWSER_TEST_F( WebstoreInlineInstallTest, InstallNotAllowedFromNonVerifiedDomains) { - SetExtensionInstallDialogAutoConfirmForTests(false); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); ui_test_utils::NavigateToURL( browser(), GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html")); @@ -113,7 +115,8 @@ IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, FindLink) { } IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, ArgumentValidation) { - SetExtensionInstallDialogAutoConfirmForTests(false); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); ui_test_utils::NavigateToURL( browser(), GenerateTestServerUrl(kAppDomain, "argument_validation.html")); @@ -121,7 +124,8 @@ IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, ArgumentValidation) { } IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallTest, InstallNotSupported) { - SetExtensionInstallDialogAutoConfirmForTests(false); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); ui_test_utils::NavigateToURL( browser(), GenerateTestServerUrl(kAppDomain, "install_not_supported.html")); @@ -158,7 +162,8 @@ class WebstoreInlineInstallUnpackFailureTest }; IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallUnpackFailureTest, Test) { - SetExtensionInstallDialogAutoConfirmForTests(true); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); ui_test_utils::NavigateToURL(browser(), GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 63fe16a..c2af6c7 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -61,14 +61,14 @@ const char kAllowWebUICompositing[] = "allow-webui-compositing"; // but less commonly used plug-ins. const char kAlwaysAuthorizePlugins[] = "always-authorize-plugins"; -// Specifies that the associated value should be launched in "application" -// mode. -const char kApp[] = "app"; - // Specifies that the extension-app with the specified id should be launched // according to its configuration. const char kAppId[] = "app-id"; +// Specifies that the associated value should be launched in "application" +// mode. +const char kApp[] = "app"; + // A URL for the server which assigns channel ids for server pushed app // notifications. const char kAppNotifyChannelServerURL[] = "app-notify-channel-server-url"; @@ -77,6 +77,17 @@ const char kAppNotifyChannelServerURL[] = "app-notify-channel-server-url"; // some private APIs. const char kAppsCheckoutURL[] = "apps-checkout-url"; +// The URL that the webstore APIs download extensions from. +// Note: the URL must contain one '%s' for the extension ID. +const char kAppsGalleryDownloadURL[] = "apps-gallery-download-url"; + +// A setting to cause extension/app installs from the webstore skip the normal +// confirmation dialog. A value of 'accept' means to always act as if the dialog +// was accepted, and 'cancel' means to always act as if the dialog was +// cancelled. +const char kAppsGalleryInstallAutoConfirmForTests[] = + "apps-gallery-install-auto-confirm-for-tests"; + // Allows the webstorePrivate APIs to return browser (aka sync) login tokens to // be used for auto-login in the Web Store (normally they do not). const char kAppsGalleryReturnTokens[] = "apps-gallery-return-tokens"; @@ -84,10 +95,6 @@ const char kAppsGalleryReturnTokens[] = "apps-gallery-return-tokens"; // The URL to use for the gallery link in the app launcher. const char kAppsGalleryURL[] = "apps-gallery-url"; -// The URL that the webstore APIs download extensions from. -// Note: the URL must contain one '%s' for the extension ID. -const char kAppsGalleryDownloadURL[] = "apps-gallery-download-url"; - // The update url used by gallery/webstore extensions. const char kAppsGalleryUpdateURL[] = "apps-gallery-update-url"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index a113373..eeae1e8 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -38,9 +38,10 @@ extern const char kAppId[]; extern const char kApp[]; extern const char kAppNotifyChannelServerURL[]; extern const char kAppsCheckoutURL[]; +extern const char kAppsGalleryDownloadURL[]; +extern const char kAppsGalleryInstallAutoConfirmForTests[]; extern const char kAppsGalleryReturnTokens[]; extern const char kAppsGalleryURL[]; -extern const char kAppsGalleryDownloadURL[]; extern const char kAppsGalleryUpdateURL[]; extern const char kAppsNewInstallBubble[]; extern const char kAppsNoThrob[]; |