// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/scoped_observer.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/startup_helper.h"
#include "chrome/browser/extensions/webstore_installer_test.h"
#include "chrome/browser/infobars/infobar_service.h"
-#include "chrome/browser/managed_mode/managed_user_service.h"
-#include "chrome/browser/managed_mode/managed_user_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/extension_builder.h"
-#include "chrome/common/extensions/value_builder.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "extensions/browser/extension_host.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_registry_observer.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/common/extension_builder.h"
+#include "extensions/common/value_builder.h"
#include "net/dns/mock_host_resolver.h"
#include "url/gurl.h"
};
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::ACCEPT;
ui_test_utils::NavigateToURL(
browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
RunTest("runTest");
- const extensions::Extension* extension = browser()->profile()->
- GetExtensionService()->GetExtensionById(kTestExtensionId, false);
+ const extensions::Extension* extension =
+ extensions::ExtensionRegistry::Get(
+ browser()->profile())->enabled_extensions().GetByID(kTestExtensionId);
EXPECT_TRUE(extension);
}
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
InstallNotAllowedFromNonVerifiedDomains) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::CANCEL;
ui_test_utils::NavigateToURL(
browser(),
GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
// Flakes on all platforms: http://crbug.com/95713, http://crbug.com/229947
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
DISABLED_ArgumentValidation) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::CANCEL;
// Each of these tests has to run separately, since one page/tab can
// only have one in-progress install request. These tests don't all pass
}
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::CANCEL;
ui_test_utils::NavigateToURL(
browser(),
}
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::CANCEL;
ui_test_utils::NavigateToURL(
browser(),
GenerateTestServerUrl(kAppDomain, "install_not_supported.html"));
// Regression test for http://crbug.com/144991.
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::ACCEPT;
const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html");
EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId));
}
-class WebstoreStartupInstallerManagedUsersTest
+class WebstoreStartupInstallerSupervisedUsersTest
: public WebstoreStartupInstallerTest {
public:
// InProcessBrowserTest overrides:
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(switches::kNewProfileIsSupervised);
+ command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
}
};
-IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerManagedUsersTest,
+IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest,
InstallProhibited) {
#if defined(OS_WIN) && defined(USE_ASH)
// Disable this test in Metro+Ash for now (http://crbug.com/262796).
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kAshBrowserTests))
return;
#endif
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::ACCEPT;
ui_test_utils::NavigateToURL(
browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html"));
// No error infobar should show up.
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
- InfoBarService* info_bar_service = InfoBarService::FromWebContents(contents);
- EXPECT_EQ(info_bar_service->infobar_count(), 0u);
+ InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
+ EXPECT_EQ(0u, infobar_service->infobar_count());
}
// The unpack failure test needs to use a different install .crx, which is
class WebstoreStartupInstallUnpackFailureTest
: public WebstoreStartupInstallerTest {
public:
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
GURL crx_url = GenerateTestServerUrl(
kWebstoreDomain, "malformed_extension.crx");
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kAppsGalleryUpdateURL, crx_url.spec());
}
IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest,
WebstoreStartupInstallUnpackFailureTest) {
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::ACCEPT;
ui_test_utils::NavigateToURL(browser(),
GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
RunTest("runTest");
}
-class CommandLineWebstoreInstall : public WebstoreStartupInstallerTest,
- public content::NotificationObserver {
+class CommandLineWebstoreInstall
+ : public WebstoreStartupInstallerTest,
+ public content::NotificationObserver,
+ public extensions::ExtensionRegistryObserver {
public:
CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {}
virtual ~CommandLineWebstoreInstall() {}
virtual void SetUpOnMainThread() OVERRIDE {
WebstoreStartupInstallerTest::SetUpOnMainThread();
- registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
- content::NotificationService::AllSources());
+ extensions::ExtensionRegistry::Get(browser()->profile())->AddObserver(this);
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllSources());
}
+ virtual void TearDownOnMainThread() OVERRIDE {
+ extensions::ExtensionRegistry::Get(browser()->profile())
+ ->RemoveObserver(this);
+ WebstoreStartupInstallerTest::TearDownOnMainThread();
+ }
+
bool saw_install() { return saw_install_; }
int browser_open_count() { return browser_open_count_; }
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
- if (type == chrome::NOTIFICATION_EXTENSION_INSTALLED) {
- const Extension* extension =
- content::Details<const extensions::InstalledExtensionInfo>(details)->
- extension;
- ASSERT_TRUE(extension != NULL);
- EXPECT_EQ(extension->id(), kTestExtensionId);
- saw_install_ = true;
- } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) {
- browser_open_count_++;
- } else {
- ASSERT_TRUE(false) << "Unexpected notification type : " << type;
- }
+ DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED);
+ ++browser_open_count_;
+ }
+
+ virtual void OnExtensionWillBeInstalled(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ bool is_update,
+ bool from_ephemeral,
+ const std::string& old_name) OVERRIDE {
+ EXPECT_EQ(extension->id(), kTestExtensionId);
+ saw_install_ = true;
}
content::NotificationRegistrar registrar_;
int browser_open_count_;
};
-IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) {
- CommandLine* command_line = CommandLine::ForCurrentProcess();
+IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, CannotInstallNonEphemeral) {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(
- switches::kInstallFromWebstore, kTestExtensionId);
- command_line->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
+ switches::kInstallEphemeralAppFromWebstore, kTestExtensionId);
+ ExtensionInstallPrompt::g_auto_confirm_for_tests =
+ ExtensionInstallPrompt::ACCEPT;
extensions::StartupHelper helper;
- EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile()));
- EXPECT_TRUE(saw_install());
- EXPECT_EQ(0, browser_open_count());
-}
-
-IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) {
- CommandLine* command_line = CommandLine::ForCurrentProcess();
- command_line->AppendSwitchASCII(
- switches::kInstallFromWebstore, kTestExtensionId);
- command_line->AppendSwitchASCII(
- switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
- extensions::StartupHelper helper;
- EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile()));
+ EXPECT_FALSE(helper.InstallEphemeralApp(*command_line, browser()->profile()));
EXPECT_FALSE(saw_install());
EXPECT_EQ(0, browser_open_count());
}
-
-IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedAccept) {
- extensions::StartupHelper helper;
-
- // Small test of "WebStoreIdFromLimitedInstallCmdLine" which made more
- // sense together with the rest of the test for "LimitedInstallFromWebstore".
- CommandLine command_line_test1(CommandLine::NO_PROGRAM);
- command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore,
- "1");
- EXPECT_EQ("nckgahadagoaajjgafhacjanaoiihapd",
- helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1));
-
- CommandLine command_line_test2(CommandLine::NO_PROGRAM);
- command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore,
- "2");
- EXPECT_EQ(kTestExtensionId,
- helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1));
-
- // Now, on to the real test for LimitedInstallFromWebstore.
- CommandLine* command_line = CommandLine::ForCurrentProcess();
- command_line->AppendSwitchASCII(
- switches::kLimitedInstallFromWebstore, "2");
- helper.LimitedInstallFromWebstore(*command_line, browser()->profile(),
- base::MessageLoop::QuitWhenIdleClosure());
- base::MessageLoop::current()->Run();
-
- EXPECT_TRUE(saw_install());
- EXPECT_EQ(0, browser_open_count());
-}