| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ |
| 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 safe_browsing_factory_; | 379 safe_browsing_factory_; |
| 380 TestPrerenderContentsFactory* prerender_contents_factory_; | 380 TestPrerenderContentsFactory* prerender_contents_factory_; |
| 381 Browser* explicitly_set_browser_; | 381 Browser* explicitly_set_browser_; |
| 382 bool autostart_test_server_; | 382 bool autostart_test_server_; |
| 383 base::HistogramTester histogram_tester_; | 383 base::HistogramTester histogram_tester_; |
| 384 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; | 384 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; |
| 385 | 385 |
| 386 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); | 386 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); |
| 387 }; | 387 }; |
| 388 | 388 |
| 389 // RAII class to save and restore the prerender mode. |
| 390 class RestorePrerenderMode { |
| 391 public: |
| 392 RestorePrerenderMode() |
| 393 : prev_mode_(PrerenderManager::GetMode(ORIGIN_NONE)), |
| 394 prev_omnibox_mode_(PrerenderManager::GetMode(ORIGIN_OMNIBOX)), |
| 395 prev_instant_mode_(PrerenderManager::GetMode(ORIGIN_INSTANT)) {} |
| 396 |
| 397 ~RestorePrerenderMode() { |
| 398 PrerenderManager::SetMode(prev_mode_); |
| 399 PrerenderManager::SetOmniboxMode(prev_omnibox_mode_); |
| 400 PrerenderManager::SetInstantMode(prev_instant_mode_); |
| 401 } |
| 402 |
| 403 private: |
| 404 PrerenderManager::PrerenderManagerMode prev_mode_; |
| 405 PrerenderManager::PrerenderManagerMode prev_omnibox_mode_; |
| 406 PrerenderManager::PrerenderManagerMode prev_instant_mode_; |
| 407 |
| 408 DISALLOW_COPY_AND_ASSIGN(RestorePrerenderMode); |
| 409 }; |
| 410 |
| 389 // Makes |url| respond to requests with the contents of |file|, counting the | 411 // Makes |url| respond to requests with the contents of |file|, counting the |
| 390 // number that start in |counter|. | 412 // number that start in |counter|. |
| 391 void CreateCountingInterceptorOnIO( | 413 void CreateCountingInterceptorOnIO( |
| 392 const GURL& url, | 414 const GURL& url, |
| 393 const base::FilePath& file, | 415 const base::FilePath& file, |
| 394 const base::WeakPtr<RequestCounter>& counter); | 416 const base::WeakPtr<RequestCounter>& counter); |
| 395 | 417 |
| 396 // When the |url| hits the net::URLRequestFilter (on the IO thread), executes | 418 // When the |url| hits the net::URLRequestFilter (on the IO thread), executes |
| 397 // the |callback_io| providing the request to it, also pings the |counter| on UI | 419 // the |callback_io| providing the request to it, also pings the |counter| on UI |
| 398 // thread. Does not modify the behavior or the request job. | 420 // thread. Does not modify the behavior or the request job. |
| 399 void InterceptRequestAndCount( | 421 void InterceptRequestAndCount( |
| 400 const GURL& url, | 422 const GURL& url, |
| 401 RequestCounter* counter, | 423 RequestCounter* counter, |
| 402 base::Callback<void(net::URLRequest*)> callback_io); | 424 base::Callback<void(net::URLRequest*)> callback_io); |
| 403 | 425 |
| 404 // Makes |url| respond to requests with the contents of |file|. | 426 // Makes |url| respond to requests with the contents of |file|. |
| 405 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); | 427 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); |
| 406 | 428 |
| 407 // Makes |url| never respond on the first load, and then with the contents of | 429 // Makes |url| never respond on the first load, and then with the contents of |
| 408 // |file| afterwards. When the first load has been scheduled, runs |callback| on | 430 // |file| afterwards. When the first load has been scheduled, runs |callback| on |
| 409 // the UI thread. | 431 // the UI thread. |
| 410 void CreateHangingFirstRequestInterceptorOnIO( | 432 void CreateHangingFirstRequestInterceptorOnIO( |
| 411 const GURL& url, const base::FilePath& file, base::Closure callback); | 433 const GURL& url, const base::FilePath& file, base::Closure callback); |
| 412 | 434 |
| 413 } // namespace test_utils | 435 } // namespace test_utils |
| 414 | 436 |
| 415 } // namespace prerender | 437 } // namespace prerender |
| 416 | 438 |
| 417 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ | 439 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ |
| OLD | NEW |