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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/browser/extensions/extension_install_prompt.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 : webstore_domain_(webstore_domain), | 45 : webstore_domain_(webstore_domain), |
| 46 test_data_path_(test_data_path), | 46 test_data_path_(test_data_path), |
| 47 crx_filename_(crx_filename), | 47 crx_filename_(crx_filename), |
| 48 verified_domain_(verified_domain), | 48 verified_domain_(verified_domain), |
| 49 unverified_domain_(unverified_domain) { | 49 unverified_domain_(unverified_domain) { |
| 50 } | 50 } |
| 51 | 51 |
| 52 WebstoreInstallerTest::~WebstoreInstallerTest() {} | 52 WebstoreInstallerTest::~WebstoreInstallerTest() {} |
| 53 | 53 |
| 54 void WebstoreInstallerTest::SetUpCommandLine(CommandLine* command_line) { | 54 void WebstoreInstallerTest::SetUpCommandLine(CommandLine* command_line) { |
| 55 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
| 55 // We start the test server now instead of in | 56 // We start the test server now instead of in |
| 56 // SetUpInProcessBrowserTestFixture so that we can get its port number. | 57 // SetUpInProcessBrowserTestFixture so that we can get its port number. |
| 57 ASSERT_TRUE(test_server()->Start()); | 58 ASSERT_TRUE(test_server()->Start()); |
| 58 | 59 |
| 59 net::HostPortPair host_port = test_server()->host_port_pair(); | 60 net::HostPortPair host_port = test_server()->host_port_pair(); |
| 60 test_gallery_url_ = base::StringPrintf( | 61 test_gallery_url_ = base::StringPrintf( |
| 61 "http://%s:%d/files/%s", | 62 "http://%s:%d/files/%s", |
| 62 webstore_domain_.c_str(), host_port.port(), test_data_path_.c_str()); | 63 webstore_domain_.c_str(), host_port.port(), test_data_path_.c_str()); |
| 63 command_line->AppendSwitchASCII( | 64 command_line->AppendSwitchASCII( |
| 64 switches::kAppsGalleryURL, test_gallery_url_); | 65 switches::kAppsGalleryURL, test_gallery_url_); |
| 65 | 66 |
| 66 GURL crx_url = GenerateTestServerUrl(webstore_domain_, crx_filename_); | 67 GURL crx_url = GenerateTestServerUrl(webstore_domain_, crx_filename_); |
| 67 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 68 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 68 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 69 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
| 69 | 70 |
| 70 // Allow tests to call window.gc(), so that we can check that callback | 71 // Allow tests to call window.gc(), so that we can check that callback |
| 71 // functions don't get collected prematurely. | 72 // functions don't get collected prematurely. |
| 72 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 73 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void WebstoreInstallerTest::SetUpInProcessBrowserTestFixture() { | 76 void WebstoreInstallerTest::SetUpInProcessBrowserTestFixture() { |
| 76 host_resolver()->AddRule(webstore_domain_, "127.0.0.1"); | 77 host_resolver()->AddRule(webstore_domain_, "127.0.0.1"); |
| 77 host_resolver()->AddRule(verified_domain_, "127.0.0.1"); | 78 host_resolver()->AddRule(verified_domain_, "127.0.0.1"); |
| 78 host_resolver()->AddRule(unverified_domain_, "127.0.0.1"); | 79 host_resolver()->AddRule(unverified_domain_, "127.0.0.1"); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void WebstoreInstallerTest::SetUpOnMainThread() { | 82 void WebstoreInstallerTest::SetUpOnMainThread() { |
| 82 InProcessBrowserTest::SetUpOnMainThread(); | 83 ExtensionBrowserTest::SetUpOnMainThread(); |
| 83 ASSERT_TRUE(download_directory_.CreateUniqueTempDir()); | 84 ASSERT_TRUE(download_directory_.CreateUniqueTempDir()); |
| 84 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( | 85 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
| 85 browser()->profile()); | 86 browser()->profile()); |
| 86 download_prefs->SetDownloadPath(download_directory_.path()); | 87 download_prefs->SetDownloadPath(download_directory_.path()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 GURL WebstoreInstallerTest::GenerateTestServerUrl( | 90 GURL WebstoreInstallerTest::GenerateTestServerUrl( |
| 90 const std::string& domain, | 91 const std::string& domain, |
| 91 const std::string& page_filename) { | 92 const std::string& page_filename) { |
| 92 GURL page_url = test_server()->GetURL( | 93 GURL page_url = test_server()->GetURL( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 return result == "KEEPGOING"; | 126 return result == "KEEPGOING"; |
| 126 } | 127 } |
| 127 | 128 |
| 128 void WebstoreInstallerTest::RunTestAsync( | 129 void WebstoreInstallerTest::RunTestAsync( |
| 129 const std::string& test_function_name) { | 130 const std::string& test_function_name) { |
| 130 std::string script = base::StringPrintf( | 131 std::string script = base::StringPrintf( |
| 131 "%s('%s')", test_function_name.c_str(), test_gallery_url_.c_str()); | 132 "%s('%s')", test_function_name.c_str(), test_gallery_url_.c_str()); |
| 132 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> | 133 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> |
| 133 ExecuteJavaScript(base::UTF8ToUTF16(script)); | 134 ExecuteJavaScript(base::UTF8ToUTF16(script)); |
| 134 } | 135 } |
| 136 | |
| 137 void WebstoreInstallerTest::AutoAcceptInstall() { | |
| 138 // TODO(tmdiep): Refactor and remove the use of the command line flag. | |
|
asargent_no_longer_on_chrome
2014/06/18 20:25:10
You can link to crbug.com/357774 here
tmdiep
2014/06/19 01:48:36
Done.
| |
| 139 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 140 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | |
| 141 } | |
| 142 | |
| 143 void WebstoreInstallerTest::AutoCancelInstall() { | |
| 144 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 145 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); | |
| 146 } | |
| OLD | NEW |