[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame^] | 5 | #include "base/bind.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 6 | #include "base/command_line.h" |
svaldez | e274587 | 2015-11-04 23:30:20 | [diff] [blame] | 7 | #include "base/files/file_path.h" |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 8 | #include "base/location.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 9 | #include "base/macros.h" |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 10 | #include "base/run_loop.h" |
[email protected] | f9b29436 | 2013-06-10 20:22:31 | [diff] [blame] | 11 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 12 | #include "base/strings/utf_string_conversions.h" |
Jay Civelli | 1ba11572 | 2018-07-16 17:41:01 | [diff] [blame] | 13 | #include "base/test/bind_test_util.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 15 | #include "chrome/browser/chrome_notification_types.h" |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 17 | #include "chrome/browser/ui/browser.h" |
tfarina | 535e6f5 | 2016-03-31 13:46:49 | [diff] [blame] | 18 | #include "chrome/browser/ui/login/login_handler.h" |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 19 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 20 | #include "chrome/common/chrome_paths.h" |
| 21 | #include "chrome/common/chrome_switches.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 22 | #include "chrome/test/base/in_process_browser_test.h" |
| 23 | #include "chrome/test/base/ui_test_utils.h" |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 24 | #include "content/public/browser/browser_thread.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 25 | #include "content/public/browser/notification_details.h" |
| 26 | #include "content/public/browser/notification_source.h" |
Sergio Villar Senin | c4f55f7 | 2018-07-19 07:49:15 | [diff] [blame] | 27 | #include "content/public/browser/storage_partition.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 28 | #include "content/public/browser/web_contents.h" |
| 29 | #include "content/public/browser/web_contents_observer.h" |
yzshen | a90291c | 2017-04-26 16:22:52 | [diff] [blame] | 30 | #include "content/public/common/content_switches.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 31 | #include "content/public/test/browser_test_utils.h" |
Jay Civelli | 1ba11572 | 2018-07-16 17:41:01 | [diff] [blame] | 32 | #include "content/public/test/url_loader_interceptor.h" |
| 33 | #include "google_apis/gaia/gaia_urls.h" |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 34 | #include "net/base/load_flags.h" |
svaldez | e274587 | 2015-11-04 23:30:20 | [diff] [blame] | 35 | #include "net/test/embedded_test_server/embedded_test_server.h" |
mmenke | ab0c11d | 2017-05-30 17:15:17 | [diff] [blame] | 36 | #include "net/test/embedded_test_server/simple_connection_listener.h" |
[email protected] | 89b3252 | 2013-05-07 20:04:21 | [diff] [blame] | 37 | #include "net/test/spawned_test_server/spawned_test_server.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 38 | #include "net/test/test_data_directory.h" |
rhalavati | 8aa3fbb7 | 2017-05-22 23:27:18 | [diff] [blame] | 39 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Sergio Villar Senin | c4f55f7 | 2018-07-19 07:49:15 | [diff] [blame] | 40 | #include "services/network/public/cpp/simple_url_loader.h" |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 41 | #include "url/gurl.h" |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 42 | |
| 43 | namespace { |
| 44 | |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 45 | // Verify kPACScript is installed as the PAC script. |
| 46 | void VerifyProxyScript(Browser* browser) { |
| 47 | ui_test_utils::NavigateToURL(browser, GURL("http://google.com")); |
| 48 | |
| 49 | // Verify we get the ERR_PROXY_CONNECTION_FAILED screen. |
| 50 | bool result = false; |
| 51 | EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 52 | browser->tab_strip_model()->GetActiveWebContents(), |
| 53 | "var textContent = document.body.textContent;" |
| 54 | "var hasError = textContent.indexOf('ERR_PROXY_CONNECTION_FAILED') >= 0;" |
| 55 | "domAutomationController.send(hasError);", |
| 56 | &result)); |
| 57 | EXPECT_TRUE(result); |
| 58 | } |
| 59 | |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 60 | // This class observes chrome::NOTIFICATION_AUTH_NEEDED and supplies |
| 61 | // the credential which is required by the test proxy server. |
| 62 | // "foo:bar" is the required username and password for our test proxy server. |
| 63 | class LoginPromptObserver : public content::NotificationObserver { |
| 64 | public: |
| 65 | LoginPromptObserver() : auth_handled_(false) {} |
| 66 | |
dcheng | fce29ad | 2014-10-23 03:47:47 | [diff] [blame] | 67 | void Observe(int type, |
| 68 | const content::NotificationSource& source, |
| 69 | const content::NotificationDetails& details) override { |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 70 | if (type == chrome::NOTIFICATION_AUTH_NEEDED) { |
| 71 | LoginNotificationDetails* login_details = |
| 72 | content::Details<LoginNotificationDetails>(details).ptr(); |
| 73 | // |login_details->handler()| is the associated LoginHandler object. |
| 74 | // SetAuth() will close the login dialog. |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 75 | login_details->handler()->SetAuth(base::ASCIIToUTF16("foo"), |
| 76 | base::ASCIIToUTF16("bar")); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 77 | auth_handled_ = true; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | bool auth_handled() const { return auth_handled_; } |
| 82 | |
| 83 | private: |
| 84 | bool auth_handled_; |
[email protected] | 5b7115b3 | 2012-12-05 21:38:09 | [diff] [blame] | 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(LoginPromptObserver); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | class ProxyBrowserTest : public InProcessBrowserTest { |
| 90 | public: |
| 91 | ProxyBrowserTest() |
[email protected] | ce7d0cbc | 2013-05-03 18:57:22 | [diff] [blame] | 92 | : proxy_server_(net::SpawnedTestServer::TYPE_BASIC_AUTH_PROXY, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 93 | base::FilePath()) { |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 94 | } |
| 95 | |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 96 | void SetUp() override { |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 97 | ASSERT_TRUE(proxy_server_.Start()); |
Jay Civelli | 1ba11572 | 2018-07-16 17:41:01 | [diff] [blame] | 98 | // Block the GaiaAuthFetcher related requests, they somehow interfere with |
| 99 | // the test when the network service is running. |
| 100 | url_loader_interceptor_ = std::make_unique<content::URLLoaderInterceptor>( |
| 101 | base::BindLambdaForTesting( |
| 102 | [&](content::URLLoaderInterceptor::RequestParams* params) -> bool { |
| 103 | if (params->url_request.url.host() == |
| 104 | GaiaUrls::GetInstance()->gaia_url().host()) { |
| 105 | return true; |
| 106 | } |
| 107 | return false; |
| 108 | })); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 109 | InProcessBrowserTest::SetUp(); |
| 110 | } |
| 111 | |
Jay Civelli | 1ba11572 | 2018-07-16 17:41:01 | [diff] [blame] | 112 | void PostRunTestOnMainThread() override { |
| 113 | url_loader_interceptor_.reset(); |
| 114 | InProcessBrowserTest::PostRunTestOnMainThread(); |
| 115 | } |
| 116 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 117 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 118 | command_line->AppendSwitchASCII(switches::kProxyServer, |
| 119 | proxy_server_.host_port_pair().ToString()); |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 120 | |
| 121 | // TODO(https://crbug.com/901896): Don't rely on proxying localhost (Relied |
| 122 | // on by BasicAuthWSConnect) |
| 123 | command_line->AppendSwitchASCII( |
| 124 | switches::kProxyBypassList, |
| 125 | net::ProxyBypassRules::GetRulesToSubtractImplicit()); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | protected: |
[email protected] | ce7d0cbc | 2013-05-03 18:57:22 | [diff] [blame] | 129 | net::SpawnedTestServer proxy_server_; |
[email protected] | 5b7115b3 | 2012-12-05 21:38:09 | [diff] [blame] | 130 | |
| 131 | private: |
Jay Civelli | 1ba11572 | 2018-07-16 17:41:01 | [diff] [blame] | 132 | std::unique_ptr<content::URLLoaderInterceptor> url_loader_interceptor_; |
[email protected] | 5b7115b3 | 2012-12-05 21:38:09 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(ProxyBrowserTest); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 134 | }; |
| 135 | |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 136 | // Test that the browser can establish a WebSocket connection via a proxy |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 137 | // that requires basic authentication. This test also checks the headers |
| 138 | // arrive at WebSocket server. |
Eric Roman | efdf315b | 2018-11-12 16:57:08 | [diff] [blame] | 139 | IN_PROC_BROWSER_TEST_F(ProxyBrowserTest, BasicAuthWSConnect) { |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 140 | // Launch WebSocket server. |
[email protected] | ce7d0cbc | 2013-05-03 18:57:22 | [diff] [blame] | 141 | net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, |
[email protected] | ce7d0cbc | 2013-05-03 18:57:22 | [diff] [blame] | 142 | net::GetWebSocketTestDataDirectory()); |
[email protected] | e0e6f9f | 2012-10-24 05:35:44 | [diff] [blame] | 143 | ASSERT_TRUE(ws_server.Start()); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 144 | |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 145 | content::WebContents* tab = |
| 146 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 147 | content::NavigationController* controller = &tab->GetController(); |
| 148 | content::NotificationRegistrar registrar; |
| 149 | // The proxy server will request basic authentication. |
| 150 | // |observer| supplies the credential. |
| 151 | LoginPromptObserver observer; |
| 152 | registrar.Add(&observer, chrome::NOTIFICATION_AUTH_NEEDED, |
| 153 | content::Source<content::NavigationController>(controller)); |
| 154 | |
[email protected] | 6778fed | 2013-12-24 20:09:37 | [diff] [blame] | 155 | content::TitleWatcher watcher(tab, base::ASCIIToUTF16("PASS")); |
| 156 | watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 157 | |
| 158 | // Visit a page that tries to establish WebSocket connection. The title |
| 159 | // of the page will be 'PASS' on success. |
[email protected] | e0e6f9f | 2012-10-24 05:35:44 | [diff] [blame] | 160 | GURL::Replacements replacements; |
mgiuca | 77752c3 | 2015-02-05 07:31:18 | [diff] [blame] | 161 | replacements.SetSchemeStr("http"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 162 | ui_test_utils::NavigateToURL(browser(), |
| 163 | ws_server.GetURL("proxied_request_check.html") |
| 164 | .ReplaceComponents(replacements)); |
[email protected] | f20dead | 2013-03-02 03:01:48 | [diff] [blame] | 165 | |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 166 | const base::string16 result = watcher.WaitAndGetTitle(); |
brettw | 00a56b7 | 2015-06-10 03:47:26 | [diff] [blame] | 167 | EXPECT_TRUE(base::EqualsASCII(result, "PASS")); |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 168 | EXPECT_TRUE(observer.auth_handled()); |
| 169 | } |
| 170 | |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 171 | // Fetches a PAC script via an http:// URL, and ensures that requests to |
| 172 | // http://www.google.com fail with ERR_PROXY_CONNECTION_FAILED (by virtue of |
| 173 | // PAC file having selected a non-existent PROXY server). |
| 174 | class BaseHttpProxyScriptBrowserTest : public InProcessBrowserTest { |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 175 | public: |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 176 | BaseHttpProxyScriptBrowserTest() { |
svaldez | e274587 | 2015-11-04 23:30:20 | [diff] [blame] | 177 | http_server_.ServeFilesFromSourceDirectory("chrome/test/data"); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 178 | } |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 179 | ~BaseHttpProxyScriptBrowserTest() override {} |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 180 | |
dcheng | e1bc798 | 2014-10-30 00:32:40 | [diff] [blame] | 181 | void SetUp() override { |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 182 | ASSERT_TRUE(http_server_.Start()); |
| 183 | InProcessBrowserTest::SetUp(); |
| 184 | } |
| 185 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 186 | void SetUpCommandLine(base::CommandLine* command_line) override { |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 187 | command_line->AppendSwitchASCII( |
| 188 | switches::kProxyPacUrl, |
| 189 | http_server_.GetURL("/" + GetPacFilename()).spec()); |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 190 | } |
| 191 | |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 192 | protected: |
| 193 | virtual std::string GetPacFilename() = 0; |
| 194 | |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 195 | private: |
svaldez | e274587 | 2015-11-04 23:30:20 | [diff] [blame] | 196 | net::EmbeddedTestServer http_server_; |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 197 | DISALLOW_COPY_AND_ASSIGN(BaseHttpProxyScriptBrowserTest); |
| 198 | }; |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 199 | |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 200 | // Tests the use of a PAC script that rejects requests to http://www.google.com/ |
| 201 | class HttpProxyScriptBrowserTest : public BaseHttpProxyScriptBrowserTest { |
| 202 | public: |
| 203 | HttpProxyScriptBrowserTest() = default; |
| 204 | ~HttpProxyScriptBrowserTest() override {} |
| 205 | |
| 206 | std::string GetPacFilename() override { |
| 207 | // PAC script that sends all requests to an invalid proxy server. |
| 208 | return "bad_server.pac"; |
| 209 | } |
| 210 | |
| 211 | private: |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 212 | DISALLOW_COPY_AND_ASSIGN(HttpProxyScriptBrowserTest); |
| 213 | }; |
| 214 | |
| 215 | IN_PROC_BROWSER_TEST_F(HttpProxyScriptBrowserTest, Verify) { |
| 216 | VerifyProxyScript(browser()); |
| 217 | } |
| 218 | |
Eric Roman | 7193c9f | 2018-11-22 01:39:58 | [diff] [blame] | 219 | // Tests the use of a PAC script that rejects requests to http://www.google.com/ |
| 220 | // when myIpAddress() and myIpAddressEx() appear to be working. |
| 221 | class MyIpAddressProxyScriptBrowserTest |
| 222 | : public BaseHttpProxyScriptBrowserTest { |
| 223 | public: |
| 224 | MyIpAddressProxyScriptBrowserTest() = default; |
| 225 | ~MyIpAddressProxyScriptBrowserTest() override {} |
| 226 | |
| 227 | std::string GetPacFilename() override { |
| 228 | // PAC script that sends all requests to an invalid proxy server provided |
| 229 | // myIpAddress() and myIpAddressEx() are not loopback addresses. |
| 230 | return "my_ip_address.pac"; |
| 231 | } |
| 232 | |
| 233 | private: |
| 234 | DISALLOW_COPY_AND_ASSIGN(MyIpAddressProxyScriptBrowserTest); |
| 235 | }; |
| 236 | |
| 237 | IN_PROC_BROWSER_TEST_F(MyIpAddressProxyScriptBrowserTest, Verify) { |
| 238 | VerifyProxyScript(browser()); |
| 239 | } |
| 240 | |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 241 | // Fetch PAC script via a hanging http:// URL. |
| 242 | class HangingPacRequestProxyScriptBrowserTest : public InProcessBrowserTest { |
| 243 | public: |
| 244 | HangingPacRequestProxyScriptBrowserTest() {} |
| 245 | ~HangingPacRequestProxyScriptBrowserTest() override {} |
| 246 | |
| 247 | void SetUp() override { |
| 248 | // Must start listening (And get a port for the proxy) before calling |
| 249 | // SetUp(). |
| 250 | ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
| 251 | InProcessBrowserTest::SetUp(); |
| 252 | } |
| 253 | |
mmenke | ab0c11d | 2017-05-30 17:15:17 | [diff] [blame] | 254 | void TearDown() override { |
| 255 | // Need to stop this before |connection_listener_| is destroyed. |
| 256 | EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
| 257 | InProcessBrowserTest::TearDown(); |
| 258 | } |
| 259 | |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 260 | void SetUpOnMainThread() override { |
| 261 | // This must be created after the main message loop has been set up. |
mmenke | ab0c11d | 2017-05-30 17:15:17 | [diff] [blame] | 262 | // Waits for one connection. Additional connections are fine. |
| 263 | connection_listener_ = |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 264 | std::make_unique<net::test_server::SimpleConnectionListener>( |
mmenke | ab0c11d | 2017-05-30 17:15:17 | [diff] [blame] | 265 | 1, net::test_server::SimpleConnectionListener:: |
| 266 | ALLOW_ADDITIONAL_CONNECTIONS); |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 267 | embedded_test_server()->SetConnectionListener(connection_listener_.get()); |
| 268 | embedded_test_server()->StartAcceptingConnections(); |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 272 | command_line->AppendSwitchASCII( |
| 273 | switches::kProxyPacUrl, embedded_test_server()->GetURL("/hung").spec()); |
| 274 | } |
| 275 | |
| 276 | protected: |
mmenke | ab0c11d | 2017-05-30 17:15:17 | [diff] [blame] | 277 | std::unique_ptr<net::test_server::SimpleConnectionListener> |
| 278 | connection_listener_; |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 279 | |
| 280 | private: |
| 281 | DISALLOW_COPY_AND_ASSIGN(HangingPacRequestProxyScriptBrowserTest); |
| 282 | }; |
| 283 | |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 284 | // Check that the URLRequest for a PAC that is still alive during shutdown is |
| 285 | // safely cleaned up. This test relies on AssertNoURLRequests being called on |
| 286 | // the main URLRequestContext. |
| 287 | IN_PROC_BROWSER_TEST_F(HangingPacRequestProxyScriptBrowserTest, Shutdown) { |
| 288 | // Request that should hang while trying to request the PAC script. |
| 289 | // Enough requests are created on startup that this probably isn't needed, but |
| 290 | // best to be safe. |
Sergio Villar Senin | c4f55f7 | 2018-07-19 07:49:15 | [diff] [blame] | 291 | auto resource_request = std::make_unique<network::ResourceRequest>(); |
| 292 | resource_request->url = GURL("http://blah/"); |
| 293 | auto simple_loader = network::SimpleURLLoader::Create( |
| 294 | std::move(resource_request), TRAFFIC_ANNOTATION_FOR_TESTS); |
| 295 | |
| 296 | auto* storage_partition = |
| 297 | content::BrowserContext::GetDefaultStoragePartition(browser()->profile()); |
| 298 | auto url_loader_factory = |
| 299 | storage_partition->GetURLLoaderFactoryForBrowserProcess(); |
| 300 | simple_loader->DownloadToStringOfUnboundedSizeUntilCrashAndDie( |
| 301 | url_loader_factory.get(), |
| 302 | base::BindOnce([](std::unique_ptr<std::string> body) { |
| 303 | ADD_FAILURE() << "This request should never complete."; |
| 304 | })); |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 305 | |
mmenke | ab0c11d | 2017-05-30 17:15:17 | [diff] [blame] | 306 | connection_listener_->WaitForConnections(); |
mmenke | 0a8ca0d1 | 2017-05-03 18:40:07 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | d46ca730 | 2012-09-08 17:37:24 | [diff] [blame] | 309 | } // namespace |