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

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

Issue 2655823002: Include referrer chain with inline install requests. (Closed)
Patch Set: cleanup Created 3 years, 11 months 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"
(...skipping 19 matching lines...) Expand all
30 #include "net/test/embedded_test_server/embedded_test_server.h" 30 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "url/gurl.h" 31 #include "url/gurl.h"
32 32
33 using content::WebContents; 33 using content::WebContents;
34 using extensions::Extension; 34 using extensions::Extension;
35 using extensions::TabHelper; 35 using extensions::TabHelper;
36 using extensions::WebstoreInlineInstaller; 36 using extensions::WebstoreInlineInstaller;
37 using extensions::WebstoreInlineInstallerFactory; 37 using extensions::WebstoreInlineInstallerFactory;
38 using extensions::WebstoreStandaloneInstaller; 38 using extensions::WebstoreStandaloneInstaller;
39 39
40 using net::test_server::HttpRequest;
41
40 WebstoreInstallerTest::WebstoreInstallerTest( 42 WebstoreInstallerTest::WebstoreInstallerTest(
41 const std::string& webstore_domain, 43 const std::string& webstore_domain,
42 const std::string& test_data_path, 44 const std::string& test_data_path,
43 const std::string& crx_filename, 45 const std::string& crx_filename,
44 const std::string& verified_domain, 46 const std::string& verified_domain,
45 const std::string& unverified_domain) 47 const std::string& unverified_domain)
46 : webstore_domain_(webstore_domain), 48 : webstore_domain_(webstore_domain),
47 test_data_path_(test_data_path), 49 test_data_path_(test_data_path),
48 crx_filename_(crx_filename), 50 crx_filename_(crx_filename),
49 verified_domain_(verified_domain), 51 verified_domain_(verified_domain),
50 unverified_domain_(unverified_domain) { 52 unverified_domain_(unverified_domain) {
51 } 53 }
52 54
53 WebstoreInstallerTest::~WebstoreInstallerTest() {} 55 WebstoreInstallerTest::~WebstoreInstallerTest() {}
54 56
55 void WebstoreInstallerTest::SetUpCommandLine(base::CommandLine* command_line) { 57 void WebstoreInstallerTest::SetUpCommandLine(base::CommandLine* command_line) {
56 ExtensionBrowserTest::SetUpCommandLine(command_line); 58 ExtensionBrowserTest::SetUpCommandLine(command_line);
59
60 embedded_test_server()->RegisterRequestMonitor(base::Bind(
61 &WebstoreInstallerTest::MonitorServerRequest, base::Unretained(this)));
Devlin 2017/01/27 20:31:34 Why not bind to ProcessServerRequest directly?
robertshield 2017/01/28 03:58:48 Hrmm.. I think I had MonitorServerRequest doing so
57 // We start the test server now instead of in 62 // We start the test server now instead of in
58 // SetUpInProcessBrowserTestFixture so that we can get its port number. 63 // SetUpInProcessBrowserTestFixture so that we can get its port number.
59 ASSERT_TRUE(embedded_test_server()->Start()); 64 ASSERT_TRUE(embedded_test_server()->Start());
60 65
61 net::HostPortPair host_port = embedded_test_server()->host_port_pair(); 66 net::HostPortPair host_port = embedded_test_server()->host_port_pair();
62 test_gallery_url_ = 67 test_gallery_url_ =
63 base::StringPrintf("http://%s:%d/%s", webstore_domain_.c_str(), 68 base::StringPrintf("http://%s:%d/%s", webstore_domain_.c_str(),
64 host_port.port(), test_data_path_.c_str()); 69 host_port.port(), test_data_path_.c_str());
65 command_line->AppendSwitchASCII( 70 command_line->AppendSwitchASCII(
66 switches::kAppsGalleryURL, test_gallery_url_); 71 switches::kAppsGalleryURL, test_gallery_url_);
(...skipping 14 matching lines...) Expand all
81 } 86 }
82 87
83 void WebstoreInstallerTest::SetUpOnMainThread() { 88 void WebstoreInstallerTest::SetUpOnMainThread() {
84 ExtensionBrowserTest::SetUpOnMainThread(); 89 ExtensionBrowserTest::SetUpOnMainThread();
85 ASSERT_TRUE(download_directory_.CreateUniqueTempDir()); 90 ASSERT_TRUE(download_directory_.CreateUniqueTempDir());
86 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( 91 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
87 browser()->profile()); 92 browser()->profile());
88 download_prefs->SetDownloadPath(download_directory_.GetPath()); 93 download_prefs->SetDownloadPath(download_directory_.GetPath());
89 } 94 }
90 95
96 void WebstoreInstallerTest::MonitorServerRequest(const HttpRequest& request) {
97 ProcessServerRequest(request);
98 }
99
91 GURL WebstoreInstallerTest::GenerateTestServerUrl( 100 GURL WebstoreInstallerTest::GenerateTestServerUrl(
92 const std::string& domain, 101 const std::string& domain,
93 const std::string& page_filename) { 102 const std::string& page_filename) {
94 GURL page_url = embedded_test_server()->GetURL(base::StringPrintf( 103 GURL page_url = embedded_test_server()->GetURL(base::StringPrintf(
95 "/%s/%s", test_data_path_.c_str(), page_filename.c_str())); 104 "/%s/%s", test_data_path_.c_str(), page_filename.c_str()));
96 105
97 GURL::Replacements replace_host; 106 GURL::Replacements replace_host;
98 replace_host.SetHostStr(domain); 107 replace_host.SetHostStr(domain);
99 return page_url.ReplaceComponents(replace_host); 108 return page_url.ReplaceComponents(replace_host);
100 } 109 }
(...skipping 29 matching lines...) Expand all
130 } 139 }
131 140
132 void WebstoreInstallerTest::RunTestAsync( 141 void WebstoreInstallerTest::RunTestAsync(
133 const std::string& test_function_name) { 142 const std::string& test_function_name) {
134 std::string script = base::StringPrintf( 143 std::string script = base::StringPrintf(
135 "%s('%s')", test_function_name.c_str(), test_gallery_url_.c_str()); 144 "%s('%s')", test_function_name.c_str(), test_gallery_url_.c_str());
136 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> 145 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()->
137 ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); 146 ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script));
138 } 147 }
139 148
149 void WebstoreInstallerTest::ProcessServerRequest(const HttpRequest& request) {}
150
140 void WebstoreInstallerTest::AutoAcceptInstall() { 151 void WebstoreInstallerTest::AutoAcceptInstall() {
141 install_auto_confirm_.reset(); // Destroy any old override first. 152 install_auto_confirm_.reset(); // Destroy any old override first.
142 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm( 153 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm(
143 extensions::ScopedTestDialogAutoConfirm::ACCEPT)); 154 extensions::ScopedTestDialogAutoConfirm::ACCEPT));
144 } 155 }
145 156
146 void WebstoreInstallerTest::AutoCancelInstall() { 157 void WebstoreInstallerTest::AutoCancelInstall() {
147 install_auto_confirm_.reset(); // Destroy any old override first. 158 install_auto_confirm_.reset(); // Destroy any old override first.
148 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm( 159 install_auto_confirm_.reset(new extensions::ScopedTestDialogAutoConfirm(
149 extensions::ScopedTestDialogAutoConfirm::CANCEL)); 160 extensions::ScopedTestDialogAutoConfirm::CANCEL));
150 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698