Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/extensions/webstore_installer_test.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/extensions/webstore_inline_installer.h" 11 #include "chrome/browser/extensions/webstore_inline_installer.h"
12 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" 12 #include "chrome/browser/extensions/webstore_inline_installer_factory.h"
13 #include "chrome/browser/extensions/webstore_installer_test.h" 13 #include "chrome/browser/extensions/webstore_installer_test.h"
14 #include "chrome/browser/extensions/webstore_standalone_installer.h" 14 #include "chrome/browser/extensions/webstore_standalone_installer.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/test_switches.h" 20 #include "chrome/test/base/test_switches.h"
21 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
24 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
27 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "net/base/host_port_pair.h" 28 #include "net/base/host_port_pair.h"
29 #include "net/dns/mock_host_resolver.h" 29 #include "net/dns/mock_host_resolver.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h"
30 #include "url/gurl.h" 31 #include "url/gurl.h"
31 32
32 using content::WebContents; 33 using content::WebContents;
33 using extensions::Extension; 34 using extensions::Extension;
34 using extensions::TabHelper; 35 using extensions::TabHelper;
35 using extensions::WebstoreInlineInstaller; 36 using extensions::WebstoreInlineInstaller;
36 using extensions::WebstoreInlineInstallerFactory; 37 using extensions::WebstoreInlineInstallerFactory;
37 using extensions::WebstoreStandaloneInstaller; 38 using extensions::WebstoreStandaloneInstaller;
38 39
39 WebstoreInstallerTest::WebstoreInstallerTest( 40 WebstoreInstallerTest::WebstoreInstallerTest(
40 const std::string& webstore_domain, 41 const std::string& webstore_domain,
41 const std::string& test_data_path, 42 const std::string& test_data_path,
42 const std::string& crx_filename, 43 const std::string& crx_filename,
43 const std::string& verified_domain, 44 const std::string& verified_domain,
44 const std::string& unverified_domain) 45 const std::string& unverified_domain)
45 : webstore_domain_(webstore_domain), 46 : webstore_domain_(webstore_domain),
46 test_data_path_(test_data_path), 47 test_data_path_(test_data_path),
47 crx_filename_(crx_filename), 48 crx_filename_(crx_filename),
48 verified_domain_(verified_domain), 49 verified_domain_(verified_domain),
49 unverified_domain_(unverified_domain) { 50 unverified_domain_(unverified_domain) {
50 } 51 }
51 52
52 WebstoreInstallerTest::~WebstoreInstallerTest() {} 53 WebstoreInstallerTest::~WebstoreInstallerTest() {}
53 54
54 void WebstoreInstallerTest::SetUpCommandLine(base::CommandLine* command_line) { 55 void WebstoreInstallerTest::SetUpCommandLine(base::CommandLine* command_line) {
55 ExtensionBrowserTest::SetUpCommandLine(command_line); 56 ExtensionBrowserTest::SetUpCommandLine(command_line);
56 // We start the test server now instead of in 57 // We start the test server now instead of in
57 // SetUpInProcessBrowserTestFixture so that we can get its port number. 58 // SetUpInProcessBrowserTestFixture so that we can get its port number.
58 ASSERT_TRUE(test_server()->Start()); 59 ASSERT_TRUE(embedded_test_server()->Start());
59 60
60 net::HostPortPair host_port = test_server()->host_port_pair(); 61 net::HostPortPair host_port = embedded_test_server()->host_port_pair();
61 test_gallery_url_ = base::StringPrintf( 62 test_gallery_url_ =
62 "http://%s:%d/files/%s", 63 base::StringPrintf("http://%s:%d/%s", webstore_domain_.c_str(),
63 webstore_domain_.c_str(), host_port.port(), test_data_path_.c_str()); 64 host_port.port(), test_data_path_.c_str());
64 command_line->AppendSwitchASCII( 65 command_line->AppendSwitchASCII(
65 switches::kAppsGalleryURL, test_gallery_url_); 66 switches::kAppsGalleryURL, test_gallery_url_);
66 67
67 GURL crx_url = GenerateTestServerUrl(webstore_domain_, crx_filename_); 68 GURL crx_url = GenerateTestServerUrl(webstore_domain_, crx_filename_);
68 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 69 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
69 switches::kAppsGalleryUpdateURL, crx_url.spec()); 70 switches::kAppsGalleryUpdateURL, crx_url.spec());
70 71
71 // Allow tests to call window.gc(), so that we can check that callback 72 // Allow tests to call window.gc(), so that we can check that callback
72 // functions don't get collected prematurely. 73 // functions don't get collected prematurely.
73 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 74 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
74 } 75 }
75 76
76 void WebstoreInstallerTest::SetUpInProcessBrowserTestFixture() { 77 void WebstoreInstallerTest::SetUpInProcessBrowserTestFixture() {
77 host_resolver()->AddRule(webstore_domain_, "127.0.0.1"); 78 host_resolver()->AddRule(webstore_domain_, "127.0.0.1");
78 host_resolver()->AddRule(verified_domain_, "127.0.0.1"); 79 host_resolver()->AddRule(verified_domain_, "127.0.0.1");
79 host_resolver()->AddRule(unverified_domain_, "127.0.0.1"); 80 host_resolver()->AddRule(unverified_domain_, "127.0.0.1");
80 } 81 }
81 82
82 void WebstoreInstallerTest::SetUpOnMainThread() { 83 void WebstoreInstallerTest::SetUpOnMainThread() {
83 ExtensionBrowserTest::SetUpOnMainThread(); 84 ExtensionBrowserTest::SetUpOnMainThread();
84 ASSERT_TRUE(download_directory_.CreateUniqueTempDir()); 85 ASSERT_TRUE(download_directory_.CreateUniqueTempDir());
85 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( 86 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
86 browser()->profile()); 87 browser()->profile());
87 download_prefs->SetDownloadPath(download_directory_.path()); 88 download_prefs->SetDownloadPath(download_directory_.path());
88 } 89 }
89 90
90 GURL WebstoreInstallerTest::GenerateTestServerUrl( 91 GURL WebstoreInstallerTest::GenerateTestServerUrl(
91 const std::string& domain, 92 const std::string& domain,
92 const std::string& page_filename) { 93 const std::string& page_filename) {
93 GURL page_url = test_server()->GetURL( 94 GURL page_url = embedded_test_server()->GetURL(base::StringPrintf(
94 base::StringPrintf("files/%s/%s", 95 "/%s/%s", test_data_path_.c_str(), page_filename.c_str()));
95 test_data_path_.c_str(),
96 page_filename.c_str()));
97 96
98 GURL::Replacements replace_host; 97 GURL::Replacements replace_host;
99 replace_host.SetHostStr(domain); 98 replace_host.SetHostStr(domain);
100 return page_url.ReplaceComponents(replace_host); 99 return page_url.ReplaceComponents(replace_host);
101 } 100 }
102 101
103 void WebstoreInstallerTest::RunTest(WebContents* web_contents, 102 void WebstoreInstallerTest::RunTest(WebContents* web_contents,
104 const std::string& test_function_name) { 103 const std::string& test_function_name) {
105 bool result = false; 104 bool result = false;
106 std::string script = base::StringPrintf( 105 std::string script = base::StringPrintf(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 install_auto_confirm_.reset(); // Destroy any old override first. 141 install_auto_confirm_.reset(); // Destroy any old override first.
143 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm( 142 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm(
144 extensions::ScopedTestDialogAutoConfirm::ACCEPT)); 143 extensions::ScopedTestDialogAutoConfirm::ACCEPT));
145 } 144 }
146 145
147 void WebstoreInstallerTest::AutoCancelInstall() { 146 void WebstoreInstallerTest::AutoCancelInstall() {
148 install_auto_confirm_.reset(); // Destroy any old override first. 147 install_auto_confirm_.reset(); // Destroy any old override first.
149 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm( 148 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm(
150 extensions::ScopedTestDialogAutoConfirm::CANCEL)); 149 extensions::ScopedTestDialogAutoConfirm::CANCEL));
151 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698