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

Side by Side Diff: chrome/browser/net/proxy_browsertest.cc

Issue 2841163002: Make ProfileIOData's ProxyService fetch PACs with the main URLRequestContext (Closed)
Patch Set: Merge fix Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/location.h"
7 #include "base/macros.h" 8 #include "base/macros.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/login/login_handler.h" 15 #include "chrome/browser/ui/login/login_handler.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_contents_observer.h" 25 #include "content/public/browser/web_contents_observer.h"
23 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
24 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "net/base/load_flags.h"
25 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
30 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h"
26 #include "net/test/spawned_test_server/spawned_test_server.h" 31 #include "net/test/spawned_test_server/spawned_test_server.h"
27 #include "net/test/test_data_directory.h" 32 #include "net/test/test_data_directory.h"
33 #include "net/url_request/url_fetcher.h"
34 #include "net/url_request/url_fetcher_delegate.h"
35 #include "url/gurl.h"
28 36
29 namespace { 37 namespace {
30 38
31 // PAC script that sends all requests to an invalid proxy server. 39 // PAC script that sends all requests to an invalid proxy server.
32 const base::FilePath::CharType kPACScript[] = FILE_PATH_LITERAL( 40 const base::FilePath::CharType kPACScript[] = FILE_PATH_LITERAL(
33 "bad_server.pac"); 41 "bad_server.pac");
34 42
35 // Verify kPACScript is installed as the PAC script. 43 // Verify kPACScript is installed as the PAC script.
36 void VerifyProxyScript(Browser* browser) { 44 void VerifyProxyScript(Browser* browser) {
37 ui_test_utils::NavigateToURL(browser, GURL("http://google.com")); 45 ui_test_utils::NavigateToURL(browser, GURL("http://google.com"));
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 276 }
269 277
270 private: 278 private:
271 DISALLOW_COPY_AND_ASSIGN(OutOfProcessProxyResolverBrowserTest); 279 DISALLOW_COPY_AND_ASSIGN(OutOfProcessProxyResolverBrowserTest);
272 }; 280 };
273 281
274 IN_PROC_BROWSER_TEST_F(OutOfProcessProxyResolverBrowserTest, Verify) { 282 IN_PROC_BROWSER_TEST_F(OutOfProcessProxyResolverBrowserTest, Verify) {
275 VerifyProxyScript(browser()); 283 VerifyProxyScript(browser());
276 } 284 }
277 285
286 // Waits for the one connection. It's fine if there are more.
287 class WaitForConnectionsListener
288 : public net::test_server::EmbeddedTestServerConnectionListener {
289 public:
290 WaitForConnectionsListener() {}
291
292 void AcceptedSocket(const net::StreamSocket& socket) override {
293 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
294 run_loop_.QuitClosure());
295 }
296
297 void ReadFromSocket(const net::StreamSocket& socket, int rv) override {}
298
299 void Wait() { run_loop_.Run(); }
300
301 private:
302 scoped_refptr<base::SequencedTaskRunner> task_runner_;
303
304 base::RunLoop run_loop_;
305
306 DISALLOW_COPY_AND_ASSIGN(WaitForConnectionsListener);
307 };
308
309 // Fetch PAC script via a hanging http:// URL.
310 class HangingPacRequestProxyScriptBrowserTest : public InProcessBrowserTest {
311 public:
312 HangingPacRequestProxyScriptBrowserTest() {
313 http_server_.ServeFilesFromSourceDirectory("chrome/test/data");
314 }
315 ~HangingPacRequestProxyScriptBrowserTest() override {}
316
317 void SetUp() override {
318 // Must start listening (And get a port for the proxy) before calling
319 // SetUp().
320 ASSERT_TRUE(http_server_.InitializeAndListen());
321 InProcessBrowserTest::SetUp();
322 }
323
324 void SetUpOnMainThread() override {
325 // This must be created after the main message loop has been set up.
326 connection_listener_ = base::MakeUnique<WaitForConnectionsListener>();
327 http_server_.SetConnectionListener(connection_listener_.get());
328 http_server_.StartAcceptingConnections();
329
330 InProcessBrowserTest::SetUpOnMainThread();
331 }
332
333 void SetUpCommandLine(base::CommandLine* command_line) override {
334 command_line->AppendSwitchASCII(switches::kProxyPacUrl,
335 http_server_.GetURL("/hung").spec());
336 }
337
338 protected:
339 std::unique_ptr<WaitForConnectionsListener> connection_listener_;
340 net::EmbeddedTestServer http_server_;
341
342 private:
343 DISALLOW_COPY_AND_ASSIGN(HangingPacRequestProxyScriptBrowserTest);
344 };
345
346 class TestURLFetcherDelegate : public net::URLFetcherDelegate {
347 public:
348 TestURLFetcherDelegate() {}
349 ~TestURLFetcherDelegate() override {}
350
351 void OnURLFetchComplete(const net::URLFetcher* source) override {
352 ADD_FAILURE() << "This request should never complete.";
353 }
354
355 private:
356 DISALLOW_COPY_AND_ASSIGN(TestURLFetcherDelegate);
357 };
358
359 // Check that the URLRequest for a PAC that is still alive during shutdown is
360 // safely cleaned up. This test relies on AssertNoURLRequests being called on
361 // the main URLRequestContext.
362 IN_PROC_BROWSER_TEST_F(HangingPacRequestProxyScriptBrowserTest, Shutdown) {
363 // Request that should hang while trying to request the PAC script.
364 // Enough requests are created on startup that this probably isn't needed, but
365 // best to be safe.
366 TestURLFetcherDelegate hung_request_delegate;
367 std::unique_ptr<net::URLFetcher> hung_fetcher = net::URLFetcher::Create(
368 http_server_.base_url(), net::URLFetcher::GET, &hung_request_delegate);
369 hung_fetcher->SetRequestContext(browser()->profile()->GetRequestContext());
370 hung_fetcher->Start();
371
372 connection_listener_->Wait();
373 }
374
278 } // namespace 375 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698