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

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: Change test URL to not be the test (proxy) server's URL 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
« no previous file with comments | « no previous file | chrome/browser/profiles/off_the_record_profile_io_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ~HangingPacRequestProxyScriptBrowserTest() override {}
314
315 void SetUp() override {
316 // Must start listening (And get a port for the proxy) before calling
317 // SetUp().
318 ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
319 InProcessBrowserTest::SetUp();
320 }
321
322 void SetUpOnMainThread() override {
323 // This must be created after the main message loop has been set up.
324 connection_listener_ = base::MakeUnique<WaitForConnectionsListener>();
325 embedded_test_server()->SetConnectionListener(connection_listener_.get());
326 embedded_test_server()->StartAcceptingConnections();
327
328 InProcessBrowserTest::SetUpOnMainThread();
329 }
330
331 void SetUpCommandLine(base::CommandLine* command_line) override {
332 command_line->AppendSwitchASCII(
333 switches::kProxyPacUrl, embedded_test_server()->GetURL("/hung").spec());
334 }
335
336 protected:
337 std::unique_ptr<WaitForConnectionsListener> connection_listener_;
338
339 private:
340 DISALLOW_COPY_AND_ASSIGN(HangingPacRequestProxyScriptBrowserTest);
341 };
342
343 // URLFetcherDelegate that expects a request to hang.
344 class HangingURLFetcherDelegate : public net::URLFetcherDelegate {
345 public:
346 HangingURLFetcherDelegate() {}
347 ~HangingURLFetcherDelegate() override {}
348
349 void OnURLFetchComplete(const net::URLFetcher* source) override {
350 ADD_FAILURE() << "This request should never complete.";
351 }
352
353 private:
354 DISALLOW_COPY_AND_ASSIGN(HangingURLFetcherDelegate);
355 };
356
357 // Check that the URLRequest for a PAC that is still alive during shutdown is
358 // safely cleaned up. This test relies on AssertNoURLRequests being called on
359 // the main URLRequestContext.
360 IN_PROC_BROWSER_TEST_F(HangingPacRequestProxyScriptBrowserTest, Shutdown) {
361 // Request that should hang while trying to request the PAC script.
362 // Enough requests are created on startup that this probably isn't needed, but
363 // best to be safe.
364 HangingURLFetcherDelegate hanging_request_delegate;
365 std::unique_ptr<net::URLFetcher> hanging_fetcher = net::URLFetcher::Create(
366 GURL("http://blah/"), net::URLFetcher::GET, &hanging_request_delegate);
367 hanging_fetcher->SetRequestContext(browser()->profile()->GetRequestContext());
368 hanging_fetcher->Start();
369
370 connection_listener_->Wait();
371 }
372
278 } // namespace 373 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/off_the_record_profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698