| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/extensions/extension_install_ui.h" | 9 #include "chrome/browser/extensions/extension_install_ui.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/extensions/startup_helper.h" | 12 #include "chrome/browser/extensions/startup_helper.h" |
| 13 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 13 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/api/requirements/requirements_handler.h" |
| 19 #include "chrome/common/extensions/extension_builder.h" | 20 #include "chrome/common/extensions/extension_builder.h" |
| 21 #include "chrome/common/extensions/manifest_handler.h" |
| 20 #include "chrome/common/extensions/value_builder.h" | 22 #include "chrome/common/extensions/value_builder.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
| 28 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
| 29 #include "net/base/host_port_pair.h" | 31 #include "net/base/host_port_pair.h" |
| 30 #include "net/base/mock_host_resolver.h" | 32 #include "net/base/mock_host_resolver.h" |
| 31 | 33 |
| 32 using content::WebContents; | 34 using content::WebContents; |
| 33 using extensions::DictionaryBuilder; | 35 |
| 34 using extensions::Extension; | 36 namespace extensions { |
| 35 using extensions::ExtensionBuilder; | |
| 36 using extensions::ListBuilder; | |
| 37 | 37 |
| 38 const char kWebstoreDomain[] = "cws.com"; | 38 const char kWebstoreDomain[] = "cws.com"; |
| 39 const char kAppDomain[] = "app.com"; | 39 const char kAppDomain[] = "app.com"; |
| 40 const char kNonAppDomain[] = "nonapp.com"; | 40 const char kNonAppDomain[] = "nonapp.com"; |
| 41 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; | 41 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; |
| 42 | 42 |
| 43 class WebstoreStartupInstallerTest : public InProcessBrowserTest { | 43 class WebstoreStartupInstallerTest : public InProcessBrowserTest { |
| 44 public: | 44 protected: |
| 45 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 45 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 46 // We start the test server now instead of in | 46 // We start the test server now instead of in |
| 47 // SetUpInProcessBrowserTestFixture so that we can get its port number. | 47 // SetUpInProcessBrowserTestFixture so that we can get its port number. |
| 48 ASSERT_TRUE(test_server()->Start()); | 48 ASSERT_TRUE(test_server()->Start()); |
| 49 | 49 |
| 50 net::HostPortPair host_port = test_server()->host_port_pair(); | 50 net::HostPortPair host_port = test_server()->host_port_pair(); |
| 51 test_gallery_url_ = base::StringPrintf( | 51 test_gallery_url_ = base::StringPrintf( |
| 52 "http://%s:%d/files/extensions/api_test/webstore_inline_install", | 52 "http://%s:%d/files/extensions/api_test/webstore_inline_install", |
| 53 kWebstoreDomain, host_port.port()); | 53 kWebstoreDomain, host_port.port()); |
| 54 command_line->AppendSwitchASCII( | 54 command_line->AppendSwitchASCII( |
| 55 switches::kAppsGalleryURL, test_gallery_url_); | 55 switches::kAppsGalleryURL, test_gallery_url_); |
| 56 | 56 |
| 57 GURL crx_url = GenerateTestServerUrl(kWebstoreDomain, "extension.crx"); | 57 GURL crx_url = GenerateTestServerUrl(kWebstoreDomain, "extension.crx"); |
| 58 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 58 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 59 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 59 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
| 60 | 60 |
| 61 // Allow tests to call window.gc(), so that we can check that callback | 61 // Allow tests to call window.gc(), so that we can check that callback |
| 62 // functions don't get collected prematurely. | 62 // functions don't get collected prematurely. |
| 63 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 63 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 66 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 67 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); | 67 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); |
| 68 host_resolver()->AddRule(kAppDomain, "127.0.0.1"); | 68 host_resolver()->AddRule(kAppDomain, "127.0.0.1"); |
| 69 host_resolver()->AddRule(kNonAppDomain, "127.0.0.1"); | 69 host_resolver()->AddRule(kNonAppDomain, "127.0.0.1"); |
| 70 } | 70 } |
| 71 | 71 |
| 72 protected: | 72 virtual void SetUpOnMainThread() OVERRIDE { |
| 73 InProcessBrowserTest::SetUpOnMainThread(); |
| 74 (new RequirementsHandler)->Register(); |
| 75 } |
| 76 |
| 77 virtual void CleanUpOnMainThread() OVERRIDE { |
| 78 ManifestHandler::ClearRegistryForTesting(); |
| 79 InProcessBrowserTest::CleanUpOnMainThread(); |
| 80 } |
| 81 |
| 73 GURL GenerateTestServerUrl(const std::string& domain, | 82 GURL GenerateTestServerUrl(const std::string& domain, |
| 74 const std::string& page_filename) { | 83 const std::string& page_filename) { |
| 75 GURL page_url = test_server()->GetURL( | 84 GURL page_url = test_server()->GetURL( |
| 76 "files/extensions/api_test/webstore_inline_install/" + page_filename); | 85 "files/extensions/api_test/webstore_inline_install/" + page_filename); |
| 77 | 86 |
| 78 GURL::Replacements replace_host; | 87 GURL::Replacements replace_host; |
| 79 replace_host.SetHostStr(domain); | 88 replace_host.SetHostStr(domain); |
| 80 return page_url.ReplaceComponents(replace_host); | 89 return page_url.ReplaceComponents(replace_host); |
| 81 } | 90 } |
| 82 | 91 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 124 |
| 116 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) { | 125 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, Install) { |
| 117 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 126 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 118 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | 127 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); |
| 119 | 128 |
| 120 ui_test_utils::NavigateToURL( | 129 ui_test_utils::NavigateToURL( |
| 121 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); | 130 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); |
| 122 | 131 |
| 123 RunTest("runTest"); | 132 RunTest("runTest"); |
| 124 | 133 |
| 125 const extensions::Extension* extension = browser()->profile()-> | 134 const Extension* extension = browser()->profile()-> |
| 126 GetExtensionService()->GetExtensionById(kTestExtensionId, false); | 135 GetExtensionService()->GetExtensionById(kTestExtensionId, false); |
| 127 EXPECT_TRUE(extension); | 136 EXPECT_TRUE(extension); |
| 128 } | 137 } |
| 129 | 138 |
| 130 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, | 139 IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, |
| 131 InstallNotAllowedFromNonVerifiedDomains) { | 140 InstallNotAllowedFromNonVerifiedDomains) { |
| 132 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 141 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 133 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); | 142 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); |
| 134 ui_test_utils::NavigateToURL( | 143 ui_test_utils::NavigateToURL( |
| 135 browser(), | 144 browser(), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 .Set("version", "1") | 222 .Set("version", "1") |
| 214 .Set("app", DictionaryBuilder() | 223 .Set("app", DictionaryBuilder() |
| 215 .Set("urls", ListBuilder().Append(kInstallUrl.spec())) | 224 .Set("urls", ListBuilder().Append(kInstallUrl.spec())) |
| 216 .Set("launch", DictionaryBuilder() | 225 .Set("launch", DictionaryBuilder() |
| 217 .Set("web_url", kInstallUrl.spec()))) | 226 .Set("web_url", kInstallUrl.spec()))) |
| 218 .Set("manifest_version", 2)) | 227 .Set("manifest_version", 2)) |
| 219 .Build(); | 228 .Build(); |
| 220 ASSERT_TRUE(hosted_app); | 229 ASSERT_TRUE(hosted_app); |
| 221 | 230 |
| 222 ExtensionService* extension_service = | 231 ExtensionService* extension_service = |
| 223 extensions::ExtensionSystem::Get(browser()->profile())-> | 232 ExtensionSystem::Get(browser()->profile())-> |
| 224 extension_service(); | 233 extension_service(); |
| 225 | 234 |
| 226 extension_service->AddExtension(hosted_app.get()); | 235 extension_service->AddExtension(hosted_app.get()); |
| 227 EXPECT_TRUE(extension_service->extensions()->Contains(hosted_app->id())); | 236 EXPECT_TRUE(extension_service->extensions()->Contains(hosted_app->id())); |
| 228 | 237 |
| 229 ui_test_utils::NavigateToURL(browser(), kInstallUrl); | 238 ui_test_utils::NavigateToURL(browser(), kInstallUrl); |
| 230 | 239 |
| 231 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId)); | 240 EXPECT_FALSE(extension_service->extensions()->Contains(kTestExtensionId)); |
| 232 RunTest("runTest"); | 241 RunTest("runTest"); |
| 233 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); | 242 EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? | 315 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? |
| 307 int browser_open_count_; | 316 int browser_open_count_; |
| 308 }; | 317 }; |
| 309 | 318 |
| 310 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { | 319 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { |
| 311 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 320 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 312 command_line->AppendSwitchASCII( | 321 command_line->AppendSwitchASCII( |
| 313 switches::kInstallFromWebstore, kTestExtensionId); | 322 switches::kInstallFromWebstore, kTestExtensionId); |
| 314 command_line->AppendSwitchASCII( | 323 command_line->AppendSwitchASCII( |
| 315 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | 324 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); |
| 316 extensions::StartupHelper helper; | 325 StartupHelper helper; |
| 317 EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile())); | 326 EXPECT_TRUE(helper.InstallFromWebstore(*command_line, browser()->profile())); |
| 318 EXPECT_TRUE(saw_install()); | 327 EXPECT_TRUE(saw_install()); |
| 319 EXPECT_EQ(0, browser_open_count()); | 328 EXPECT_EQ(0, browser_open_count()); |
| 320 } | 329 } |
| 321 | 330 |
| 322 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) { | 331 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Cancel) { |
| 323 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 332 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 324 command_line->AppendSwitchASCII( | 333 command_line->AppendSwitchASCII( |
| 325 switches::kInstallFromWebstore, kTestExtensionId); | 334 switches::kInstallFromWebstore, kTestExtensionId); |
| 326 command_line->AppendSwitchASCII( | 335 command_line->AppendSwitchASCII( |
| 327 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); | 336 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); |
| 328 extensions::StartupHelper helper; | 337 StartupHelper helper; |
| 329 EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile())); | 338 EXPECT_FALSE(helper.InstallFromWebstore(*command_line, browser()->profile())); |
| 330 EXPECT_FALSE(saw_install()); | 339 EXPECT_FALSE(saw_install()); |
| 331 EXPECT_EQ(0, browser_open_count()); | 340 EXPECT_EQ(0, browser_open_count()); |
| 332 } | 341 } |
| 333 | 342 |
| 334 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedAccept) { | 343 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedAccept) { |
| 335 extensions::StartupHelper helper; | 344 StartupHelper helper; |
| 336 | 345 |
| 337 // Small test of "WebStoreIdFromLimitedInstallCmdLine" which made more | 346 // Small test of "WebStoreIdFromLimitedInstallCmdLine" which made more |
| 338 // sense together with the rest of the test for "LimitedInstallFromWebstore". | 347 // sense together with the rest of the test for "LimitedInstallFromWebstore". |
| 339 CommandLine command_line_test1(CommandLine::NO_PROGRAM); | 348 CommandLine command_line_test1(CommandLine::NO_PROGRAM); |
| 340 command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore, | 349 command_line_test1.AppendSwitchASCII(switches::kLimitedInstallFromWebstore, |
| 341 "1"); | 350 "1"); |
| 342 EXPECT_EQ("nckgahadagoaajjgafhacjanaoiihapd", | 351 EXPECT_EQ("nckgahadagoaajjgafhacjanaoiihapd", |
| 343 helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1)); | 352 helper.WebStoreIdFromLimitedInstallCmdLine(command_line_test1)); |
| 344 | 353 |
| 345 CommandLine command_line_test2(CommandLine::NO_PROGRAM); | 354 CommandLine command_line_test2(CommandLine::NO_PROGRAM); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 361 EXPECT_TRUE(saw_install()); | 370 EXPECT_TRUE(saw_install()); |
| 362 EXPECT_EQ(0, browser_open_count()); | 371 EXPECT_EQ(0, browser_open_count()); |
| 363 } | 372 } |
| 364 | 373 |
| 365 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedCancel) { | 374 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, LimitedCancel) { |
| 366 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 375 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 367 command_line->AppendSwitchASCII( | 376 command_line->AppendSwitchASCII( |
| 368 switches::kLimitedInstallFromWebstore, "2"); | 377 switches::kLimitedInstallFromWebstore, "2"); |
| 369 command_line->AppendSwitchASCII( | 378 command_line->AppendSwitchASCII( |
| 370 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); | 379 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); |
| 371 extensions::StartupHelper helper; | 380 StartupHelper helper; |
| 372 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), | 381 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), |
| 373 MessageLoop::QuitWhenIdleClosure()); | 382 MessageLoop::QuitWhenIdleClosure()); |
| 374 MessageLoop::current()->Run(); | 383 MessageLoop::current()->Run(); |
| 375 EXPECT_FALSE(saw_install()); | 384 EXPECT_FALSE(saw_install()); |
| 376 EXPECT_EQ(0, browser_open_count()); | 385 EXPECT_EQ(0, browser_open_count()); |
| 377 } | 386 } |
| 387 |
| 388 } // namespace extensions |
| OLD | NEW |