OLD | NEW |
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/location.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/login/login_handler.h" | 15 #include "chrome/browser/ui/login/login_handler.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.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/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.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/load_flags.h" | 28 #include "net/base/load_flags.h" |
29 #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" | 30 #include "net/test/embedded_test_server/simple_connection_listener.h" |
31 #include "net/test/spawned_test_server/spawned_test_server.h" | 31 #include "net/test/spawned_test_server/spawned_test_server.h" |
32 #include "net/test/test_data_directory.h" | 32 #include "net/test/test_data_directory.h" |
33 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 33 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
34 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
35 #include "net/url_request/url_fetcher_delegate.h" | 35 #include "net/url_request/url_fetcher_delegate.h" |
36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // PAC script that sends all requests to an invalid proxy server. | 40 // PAC script that sends all requests to an invalid proxy server. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 private: | 279 private: |
280 DISALLOW_COPY_AND_ASSIGN(OutOfProcessProxyResolverBrowserTest); | 280 DISALLOW_COPY_AND_ASSIGN(OutOfProcessProxyResolverBrowserTest); |
281 }; | 281 }; |
282 | 282 |
283 IN_PROC_BROWSER_TEST_F(OutOfProcessProxyResolverBrowserTest, Verify) { | 283 IN_PROC_BROWSER_TEST_F(OutOfProcessProxyResolverBrowserTest, Verify) { |
284 VerifyProxyScript(browser()); | 284 VerifyProxyScript(browser()); |
285 } | 285 } |
286 | 286 |
287 // Waits for the one connection. It's fine if there are more. | |
288 class WaitForConnectionsListener | |
289 : public net::test_server::EmbeddedTestServerConnectionListener { | |
290 public: | |
291 WaitForConnectionsListener() {} | |
292 | |
293 void AcceptedSocket(const net::StreamSocket& socket) override { | |
294 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
295 run_loop_.QuitClosure()); | |
296 } | |
297 | |
298 void ReadFromSocket(const net::StreamSocket& socket, int rv) override {} | |
299 | |
300 void Wait() { run_loop_.Run(); } | |
301 | |
302 private: | |
303 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
304 | |
305 base::RunLoop run_loop_; | |
306 | |
307 DISALLOW_COPY_AND_ASSIGN(WaitForConnectionsListener); | |
308 }; | |
309 | |
310 // Fetch PAC script via a hanging http:// URL. | 287 // Fetch PAC script via a hanging http:// URL. |
311 class HangingPacRequestProxyScriptBrowserTest : public InProcessBrowserTest { | 288 class HangingPacRequestProxyScriptBrowserTest : public InProcessBrowserTest { |
312 public: | 289 public: |
313 HangingPacRequestProxyScriptBrowserTest() {} | 290 HangingPacRequestProxyScriptBrowserTest() {} |
314 ~HangingPacRequestProxyScriptBrowserTest() override {} | 291 ~HangingPacRequestProxyScriptBrowserTest() override {} |
315 | 292 |
316 void SetUp() override { | 293 void SetUp() override { |
317 // Must start listening (And get a port for the proxy) before calling | 294 // Must start listening (And get a port for the proxy) before calling |
318 // SetUp(). | 295 // SetUp(). |
319 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); | 296 ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); |
320 InProcessBrowserTest::SetUp(); | 297 InProcessBrowserTest::SetUp(); |
321 } | 298 } |
322 | 299 |
| 300 void TearDown() override { |
| 301 // Need to stop this before |connection_listener_| is destroyed. |
| 302 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
| 303 InProcessBrowserTest::TearDown(); |
| 304 } |
| 305 |
323 void SetUpOnMainThread() override { | 306 void SetUpOnMainThread() override { |
324 // This must be created after the main message loop has been set up. | 307 // This must be created after the main message loop has been set up. |
325 connection_listener_ = base::MakeUnique<WaitForConnectionsListener>(); | 308 // Waits for one connection. Additional connections are fine. |
| 309 connection_listener_ = |
| 310 base::MakeUnique<net::test_server::SimpleConnectionListener>( |
| 311 1, net::test_server::SimpleConnectionListener:: |
| 312 ALLOW_ADDITIONAL_CONNECTIONS); |
326 embedded_test_server()->SetConnectionListener(connection_listener_.get()); | 313 embedded_test_server()->SetConnectionListener(connection_listener_.get()); |
327 embedded_test_server()->StartAcceptingConnections(); | 314 embedded_test_server()->StartAcceptingConnections(); |
328 | 315 |
329 InProcessBrowserTest::SetUpOnMainThread(); | 316 InProcessBrowserTest::SetUpOnMainThread(); |
330 } | 317 } |
331 | 318 |
332 void SetUpCommandLine(base::CommandLine* command_line) override { | 319 void SetUpCommandLine(base::CommandLine* command_line) override { |
333 command_line->AppendSwitchASCII( | 320 command_line->AppendSwitchASCII( |
334 switches::kProxyPacUrl, embedded_test_server()->GetURL("/hung").spec()); | 321 switches::kProxyPacUrl, embedded_test_server()->GetURL("/hung").spec()); |
335 } | 322 } |
336 | 323 |
337 protected: | 324 protected: |
338 std::unique_ptr<WaitForConnectionsListener> connection_listener_; | 325 std::unique_ptr<net::test_server::SimpleConnectionListener> |
| 326 connection_listener_; |
339 | 327 |
340 private: | 328 private: |
341 DISALLOW_COPY_AND_ASSIGN(HangingPacRequestProxyScriptBrowserTest); | 329 DISALLOW_COPY_AND_ASSIGN(HangingPacRequestProxyScriptBrowserTest); |
342 }; | 330 }; |
343 | 331 |
344 // URLFetcherDelegate that expects a request to hang. | 332 // URLFetcherDelegate that expects a request to hang. |
345 class HangingURLFetcherDelegate : public net::URLFetcherDelegate { | 333 class HangingURLFetcherDelegate : public net::URLFetcherDelegate { |
346 public: | 334 public: |
347 HangingURLFetcherDelegate() {} | 335 HangingURLFetcherDelegate() {} |
348 ~HangingURLFetcherDelegate() override {} | 336 ~HangingURLFetcherDelegate() override {} |
(...skipping 13 matching lines...) Expand all Loading... |
362 // Request that should hang while trying to request the PAC script. | 350 // Request that should hang while trying to request the PAC script. |
363 // Enough requests are created on startup that this probably isn't needed, but | 351 // Enough requests are created on startup that this probably isn't needed, but |
364 // best to be safe. | 352 // best to be safe. |
365 HangingURLFetcherDelegate hanging_request_delegate; | 353 HangingURLFetcherDelegate hanging_request_delegate; |
366 std::unique_ptr<net::URLFetcher> hanging_fetcher = net::URLFetcher::Create( | 354 std::unique_ptr<net::URLFetcher> hanging_fetcher = net::URLFetcher::Create( |
367 GURL("http://blah/"), net::URLFetcher::GET, &hanging_request_delegate, | 355 GURL("http://blah/"), net::URLFetcher::GET, &hanging_request_delegate, |
368 TRAFFIC_ANNOTATION_FOR_TESTS); | 356 TRAFFIC_ANNOTATION_FOR_TESTS); |
369 hanging_fetcher->SetRequestContext(browser()->profile()->GetRequestContext()); | 357 hanging_fetcher->SetRequestContext(browser()->profile()->GetRequestContext()); |
370 hanging_fetcher->Start(); | 358 hanging_fetcher->Start(); |
371 | 359 |
372 connection_listener_->Wait(); | 360 connection_listener_->WaitForConnections(); |
373 } | 361 } |
374 | 362 |
375 } // namespace | 363 } // namespace |
OLD | NEW |