Make the ChromeOS chromecast system tray integration use a private API.
[chromium-blink-merge.git] / chrome / browser / extensions / webstore_startup_installer_browsertest.cc
blobe87138eff767988c0e42d92e3848dd07da77e53d
1 // Copyright (c) 2012 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.
5 #include "base/command_line.h"
6 #include "base/scoped_observer.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/webstore_installer_test.h"
9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/test_switches.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "extensions/browser/extension_host.h"
21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/install/extension_install_ui.h"
24 #include "extensions/common/extension_builder.h"
25 #include "extensions/common/value_builder.h"
26 #include "net/dns/mock_host_resolver.h"
27 #include "url/gurl.h"
29 using content::WebContents;
30 using extensions::DictionaryBuilder;
31 using extensions::Extension;
32 using extensions::ExtensionBuilder;
33 using extensions::ListBuilder;
35 const char kWebstoreDomain[] = "cws.com";
36 const char kAppDomain[] = "app.com";
37 const char kNonAppDomain[] = "nonapp.com";
38 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje";
39 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install";
40 const char kCrxFilename[] = "extension.crx";
42 class WebstoreStartupInstallerTest : public WebstoreInstallerTest {
43 public:
44 WebstoreStartupInstallerTest()
45 : WebstoreInstallerTest(
46 kWebstoreDomain,
47 kTestDataPath,
48 kCrxFilename,
49 kAppDomain,
50 kNonAppDomain) {}
53 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) {
54 AutoAcceptInstall();
56 ui_test_utils::NavigateToURL(
57 browser(), GenerateTestServerUrl(kAppDomain, "install.html"));
59 RunTest("runTest");
61 extensions::ExtensionRegistry* registry =
62 extensions::ExtensionRegistry::Get(browser()->profile());
63 const extensions::Extension* extension =
64 registry->enabled_extensions().GetByID(kTestExtensionId);
65 EXPECT_TRUE(extension);
68 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
69 InstallNotAllowedFromNonVerifiedDomains) {
70 AutoCancelInstall();
71 ui_test_utils::NavigateToURL(
72 browser(),
73 GenerateTestServerUrl(kNonAppDomain, "install_non_verified_domain.html"));
75 RunTest("runTest1");
76 RunTest("runTest2");
79 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, FindLink) {
80 ui_test_utils::NavigateToURL(
81 browser(), GenerateTestServerUrl(kAppDomain, "find_link.html"));
83 RunTest("runTest");
86 // Flakes on all platforms: http://crbug.com/95713, http://crbug.com/229947
87 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest,
88 DISABLED_ArgumentValidation) {
89 AutoCancelInstall();
91 // Each of these tests has to run separately, since one page/tab can
92 // only have one in-progress install request. These tests don't all pass
93 // callbacks to install, so they have no way to wait for the installation
94 // to complete before starting the next test.
95 bool is_finished = false;
96 for (int i = 0; !is_finished; ++i) {
97 ui_test_utils::NavigateToURL(
98 browser(),
99 GenerateTestServerUrl(kAppDomain, "argument_validation.html"));
100 is_finished = !RunIndexedTest("runTest", i);
104 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, MultipleInstallCalls) {
105 AutoCancelInstall();
107 ui_test_utils::NavigateToURL(
108 browser(),
109 GenerateTestServerUrl(kAppDomain, "multiple_install_calls.html"));
110 RunTest("runTest");
113 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallNotSupported) {
114 AutoCancelInstall();
115 ui_test_utils::NavigateToURL(
116 browser(),
117 GenerateTestServerUrl(kAppDomain, "install_not_supported.html"));
119 ui_test_utils::WindowedTabAddedNotificationObserver observer(
120 content::NotificationService::AllSources());
121 RunTest("runTest");
122 observer.Wait();
124 // The inline install should fail, and a store-provided URL should be opened
125 // in a new tab.
126 WebContents* web_contents =
127 browser()->tab_strip_model()->GetActiveWebContents();
128 EXPECT_EQ(GURL("http://cws.com/show-me-the-money"), web_contents->GetURL());
131 // Regression test for http://crbug.com/144991.
132 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) {
133 AutoAcceptInstall();
135 const GURL kInstallUrl = GenerateTestServerUrl(kAppDomain, "install.html");
137 // We're forced to construct a hosted app dynamically because we need the
138 // app to run on a declared URL, but we don't know the port ahead of time.
139 scoped_refptr<const Extension> hosted_app = ExtensionBuilder()
140 .SetManifest(DictionaryBuilder()
141 .Set("name", "hosted app")
142 .Set("version", "1")
143 .Set("app", DictionaryBuilder()
144 .Set("urls", ListBuilder().Append(kInstallUrl.spec()))
145 .Set("launch", DictionaryBuilder()
146 .Set("web_url", kInstallUrl.spec())))
147 .Set("manifest_version", 2))
148 .Build();
149 ASSERT_TRUE(hosted_app.get());
151 ExtensionService* extension_service =
152 extensions::ExtensionSystem::Get(browser()->profile())->
153 extension_service();
154 extensions::ExtensionRegistry* registry =
155 extensions::ExtensionRegistry::Get(browser()->profile());
157 extension_service->AddExtension(hosted_app.get());
158 EXPECT_TRUE(registry->enabled_extensions().GetByID(hosted_app->id()));
160 ui_test_utils::NavigateToURL(browser(), kInstallUrl);
162 EXPECT_FALSE(registry->enabled_extensions().GetByID(kTestExtensionId));
163 RunTest("runTest");
164 EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId));
167 class WebstoreStartupInstallerSupervisedUsersTest
168 : public WebstoreStartupInstallerTest {
169 public:
170 // InProcessBrowserTest overrides:
171 void SetUpCommandLine(base::CommandLine* command_line) override {
172 WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
173 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf");
177 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerSupervisedUsersTest,
178 InstallProhibited) {
179 #if defined(OS_WIN) && defined(USE_ASH)
180 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
181 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
182 switches::kAshBrowserTests))
183 return;
184 #endif
186 AutoAcceptInstall();
188 ui_test_utils::NavigateToURL(
189 browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html"));
191 RunTest("runTest");
193 // No error infobar should show up.
194 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
195 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
196 EXPECT_EQ(0u, infobar_service->infobar_count());
199 // The unpack failure test needs to use a different install .crx, which is
200 // specified via a command-line flag, so it needs its own test subclass.
201 class WebstoreStartupInstallUnpackFailureTest
202 : public WebstoreStartupInstallerTest {
203 public:
204 void SetUpCommandLine(base::CommandLine* command_line) override {
205 WebstoreStartupInstallerTest::SetUpCommandLine(command_line);
207 GURL crx_url = GenerateTestServerUrl(
208 kWebstoreDomain, "malformed_extension.crx");
209 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
210 switches::kAppsGalleryUpdateURL, crx_url.spec());
213 void SetUpInProcessBrowserTestFixture() override {
214 WebstoreStartupInstallerTest::SetUpInProcessBrowserTestFixture();
215 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests();
219 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallUnpackFailureTest,
220 WebstoreStartupInstallUnpackFailureTest) {
221 AutoAcceptInstall();
223 ui_test_utils::NavigateToURL(browser(),
224 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
226 RunTest("runTest");