Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/webstore_inline_installer.h" | 5 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | |
| 7 #include "base/macros.h" | 8 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 11 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/tab_helper.h" | 15 #include "chrome/browser/extensions/tab_helper.h" |
| 14 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 16 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 15 #include "chrome/browser/extensions/webstore_installer_test.h" | 17 #include "chrome/browser/extensions/webstore_installer_test.h" |
| 16 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 18 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "components/content_settings/core/browser/host_content_settings_map.h" | 24 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 23 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 25 #include "extensions/browser/extension_registry.h" | 27 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
| 27 #include "extensions/common/permissions/permission_set.h" | 29 #include "extensions/common/permissions/permission_set.h" |
| 30 #include "net/dns/mock_host_resolver.h" | |
| 31 #include "net/test/embedded_test_server/http_request.h" | |
| 28 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 29 | 33 |
| 30 using content::WebContents; | 34 using content::WebContents; |
| 35 using net::test_server::HttpRequest; | |
|
Devlin
2017/01/27 20:31:34
nit: avoid using 'using' for single uses. :)
robertshield
2017/01/28 03:58:48
Done.
| |
| 31 | 36 |
| 32 namespace extensions { | 37 namespace extensions { |
| 33 | 38 |
| 34 namespace { | 39 namespace { |
| 35 | 40 |
| 36 const char kWebstoreDomain[] = "cws.com"; | 41 const char kWebstoreDomain[] = "cws.com"; |
| 37 const char kAppDomain[] = "app.com"; | 42 const char kAppDomain[] = "app.com"; |
| 38 const char kNonAppDomain[] = "nonapp.com"; | 43 const char kNonAppDomain[] = "nonapp.com"; |
| 39 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; | 44 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; |
| 40 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; | 45 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; |
| 41 const char kCrxFilename[] = "extension.crx"; | 46 const char kCrxFilename[] = "extension.crx"; |
| 42 | 47 |
| 48 const char kRedirect1Domain[] = "redirect1.com"; | |
| 49 const char kRedirect2Domain[] = "redirect2.com"; | |
| 50 | |
| 43 // A struct for letting us store the actual parameters that were passed to | 51 // A struct for letting us store the actual parameters that were passed to |
| 44 // the install callback. | 52 // the install callback. |
| 45 struct InstallResult { | 53 struct InstallResult { |
| 46 bool success = false; | 54 bool success = false; |
| 47 std::string error; | 55 std::string error; |
| 48 webstore_install::Result result = webstore_install::RESULT_LAST; | 56 webstore_install::Result result = webstore_install::RESULT_LAST; |
| 49 }; | 57 }; |
| 50 | 58 |
| 51 } // namespace | 59 } // namespace |
| 52 | 60 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 } | 364 } |
| 357 | 365 |
| 358 // Test calling chrome.webstore.install() twice without waiting for the first to | 366 // Test calling chrome.webstore.install() twice without waiting for the first to |
| 359 // finish. | 367 // finish. |
| 360 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, DoubleInlineInstallTest) { | 368 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, DoubleInlineInstallTest) { |
| 361 ui_test_utils::NavigateToURL( | 369 ui_test_utils::NavigateToURL( |
| 362 browser(), GenerateTestServerUrl(kAppDomain, "double_install.html")); | 370 browser(), GenerateTestServerUrl(kAppDomain, "double_install.html")); |
| 363 RunTest("runTest"); | 371 RunTest("runTest"); |
| 364 } | 372 } |
| 365 | 373 |
| 374 class WebstoreInlineInstallerRedirectTest : public WebstoreInlineInstallerTest { | |
| 375 public: | |
| 376 WebstoreInlineInstallerRedirectTest() | |
| 377 : cws_request_received_(false), cws_request_redirects_(0) {} | |
| 378 ~WebstoreInlineInstallerRedirectTest() override {} | |
| 379 | |
| 380 void SetUpInProcessBrowserTestFixture() override { | |
| 381 WebstoreInstallerTest::SetUpInProcessBrowserTestFixture(); | |
| 382 host_resolver()->AddRule(kRedirect1Domain, "127.0.0.1"); | |
| 383 host_resolver()->AddRule(kRedirect2Domain, "127.0.0.1"); | |
| 384 } | |
| 385 | |
| 386 void ProcessServerRequest(const HttpRequest& request) override { | |
| 387 if (request.content.find("redirect_chain") != std::string::npos) { | |
| 388 cws_request_received_ = true; | |
| 389 | |
| 390 std::unique_ptr<base::Value> contents = | |
| 391 base::JSONReader::Read(request.content); | |
| 392 base::DictionaryValue* contents_dict = nullptr; | |
| 393 contents->GetAsDictionary(&contents_dict); | |
| 394 if (contents_dict) { | |
| 395 base::ListValue* redirect_chain = nullptr; | |
| 396 contents_dict->GetList("redirect_chain", &redirect_chain); | |
| 397 if (redirect_chain) { | |
| 398 cws_request_redirects_ = redirect_chain->GetSize(); | |
| 399 } | |
| 400 } | |
| 401 } | |
| 402 } | |
| 403 | |
| 404 bool cws_request_received_; | |
| 405 int cws_request_redirects_; | |
| 406 }; | |
| 407 | |
| 408 // Test that an install from a page arrived at via redirects includes the | |
| 409 // redirect information in the webstore request. | |
| 410 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerRedirectTest, | |
| 411 IncludesRedirectData) { | |
| 412 // Hand craft a url that will cause the test server to issue redirects. | |
| 413 const std::vector<std::string> redirects{kRedirect1Domain, kRedirect2Domain}; | |
| 414 | |
| 415 net::HostPortPair host_port = embedded_test_server()->host_port_pair(); | |
| 416 | |
| 417 std::string redirect_chain; | |
| 418 for (auto redirect : redirects) { | |
|
Devlin
2017/01/27 20:31:34
const auto&
robertshield
2017/01/28 03:58:48
Done.
| |
| 419 std::string redir = base::StringPrintf("http://%s:%d/server-redirect?", | |
|
Devlin
2017/01/27 20:31:34
maybe s/redir/url or redirect_url?
robertshield
2017/01/28 03:58:48
Done.
| |
| 420 redirect.c_str(), host_port.port()); | |
| 421 redirect_chain += redir; | |
| 422 } | |
| 423 const GURL install_url = | |
| 424 GURL(redirect_chain + | |
| 425 GenerateTestServerUrl(kAppDomain, "install.html").spec()); | |
| 426 | |
| 427 AutoAcceptInstall(); | |
| 428 ui_test_utils::NavigateToURL(browser(), install_url); | |
| 429 RunTest("runTest"); | |
| 430 | |
| 431 EXPECT_TRUE(cws_request_received_); | |
| 432 // Three items, two for the items in |redirects| and one more for the final | |
| 433 // install url. | |
| 434 EXPECT_EQ(3, cws_request_redirects_); | |
|
Devlin
2017/01/27 20:31:34
It'd be nice to verify the contents, too. Maybe j
robertshield
2017/01/28 03:58:48
Done.
| |
| 435 } | |
| 436 | |
| 366 class WebstoreInlineInstallerListenerTest : public WebstoreInlineInstallerTest { | 437 class WebstoreInlineInstallerListenerTest : public WebstoreInlineInstallerTest { |
| 367 public: | 438 public: |
| 368 WebstoreInlineInstallerListenerTest() {} | 439 WebstoreInlineInstallerListenerTest() {} |
| 369 ~WebstoreInlineInstallerListenerTest() override {} | 440 ~WebstoreInlineInstallerListenerTest() override {} |
| 370 | 441 |
| 371 protected: | 442 protected: |
| 372 void RunTest(const std::string& file_name) { | 443 void RunTest(const std::string& file_name) { |
| 373 AutoAcceptInstall(); | 444 AutoAcceptInstall(); |
| 374 ui_test_utils::NavigateToURL(browser(), | 445 ui_test_utils::NavigateToURL(browser(), |
| 375 GenerateTestServerUrl(kAppDomain, file_name)); | 446 GenerateTestServerUrl(kAppDomain, file_name)); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 406 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 477 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 407 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 478 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 408 DCHECK_NE(old_tab_index, browser()->tab_strip_model()->active_index()); | 479 DCHECK_NE(old_tab_index, browser()->tab_strip_model()->active_index()); |
| 409 browser()->tab_strip_model()->CloseWebContentsAt(old_tab_index, | 480 browser()->tab_strip_model()->CloseWebContentsAt(old_tab_index, |
| 410 TabStripModel::CLOSE_NONE); | 481 TabStripModel::CLOSE_NONE); |
| 411 WebstoreInstallerTest::RunTest("runTest"); | 482 WebstoreInstallerTest::RunTest("runTest"); |
| 412 EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); | 483 EXPECT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); |
| 413 } | 484 } |
| 414 | 485 |
| 415 } // namespace extensions | 486 } // namespace extensions |
| OLD | NEW |