| 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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <unordered_map> | 13 #include <unordered_map> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 19 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 20 #include "chrome/browser/page_load_metrics/observers/prerender_page_load_metrics
_observer.h" |
| 20 #include "chrome/browser/prerender/prerender_contents.h" | 21 #include "chrome/browser/prerender/prerender_contents.h" |
| 21 #include "chrome/browser/prerender/prerender_manager.h" | 22 #include "chrome/browser/prerender/prerender_manager.h" |
| 22 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 23 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "components/safe_browsing_db/test_database_manager.h" | 25 #include "components/safe_browsing_db/test_database_manager.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "net/test/url_request/url_request_mock_http_job.h" | 27 #include "net/test/url_request/url_request_mock_http_job.h" |
| 27 #include "net/url_request/url_request_interceptor.h" | 28 #include "net/url_request/url_request_interceptor.h" |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 void MarkDestruction(FinalStatus reason); | 231 void MarkDestruction(FinalStatus reason); |
| 231 | 232 |
| 232 base::RunLoop wait_loop_; | 233 base::RunLoop wait_loop_; |
| 233 FinalStatus expected_final_status_; | 234 FinalStatus expected_final_status_; |
| 234 bool saw_correct_status_; | 235 bool saw_correct_status_; |
| 235 std::unique_ptr<DestructionMarker> marker_; | 236 std::unique_ptr<DestructionMarker> marker_; |
| 236 | 237 |
| 237 DISALLOW_COPY_AND_ASSIGN(DestructionWaiter); | 238 DISALLOW_COPY_AND_ASSIGN(DestructionWaiter); |
| 238 }; | 239 }; |
| 239 | 240 |
| 241 // Wait until a PrerenderManager has seen a first contentful paint. |
| 242 class FirstContentfulPaintManagerWaiter : public PrerenderManagerObserver { |
| 243 public: |
| 244 // Create and return a pointer to a |FirstContentfulPaintManagerWaiter|. The |
| 245 // instance is owned by the |PrerenderManager|. |
| 246 static FirstContentfulPaintManagerWaiter* Create(PrerenderManager* manager); |
| 247 ~FirstContentfulPaintManagerWaiter(); |
| 248 |
| 249 void OnFirstContentfulPaint() override; |
| 250 |
| 251 // Wait for a first contentful paint to be seen by our PrerenderManager. |
| 252 void Wait(); |
| 253 |
| 254 private: |
| 255 FirstContentfulPaintManagerWaiter(); |
| 256 |
| 257 std::unique_ptr<base::RunLoop> waiter_; |
| 258 bool saw_fcp_; |
| 259 }; |
| 260 |
| 240 // PrerenderContentsFactory that uses TestPrerenderContents. | 261 // PrerenderContentsFactory that uses TestPrerenderContents. |
| 241 class TestPrerenderContentsFactory : public PrerenderContents::Factory { | 262 class TestPrerenderContentsFactory : public PrerenderContents::Factory { |
| 242 public: | 263 public: |
| 243 TestPrerenderContentsFactory(); | 264 TestPrerenderContentsFactory(); |
| 244 | 265 |
| 245 ~TestPrerenderContentsFactory() override; | 266 ~TestPrerenderContentsFactory() override; |
| 246 | 267 |
| 247 std::unique_ptr<TestPrerender> ExpectPrerenderContents( | 268 std::unique_ptr<TestPrerender> ExpectPrerenderContents( |
| 248 FinalStatus final_status); | 269 FinalStatus final_status); |
| 249 | 270 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 safe_browsing_factory_; | 377 safe_browsing_factory_; |
| 357 TestPrerenderContentsFactory* prerender_contents_factory_; | 378 TestPrerenderContentsFactory* prerender_contents_factory_; |
| 358 Browser* explicitly_set_browser_; | 379 Browser* explicitly_set_browser_; |
| 359 bool autostart_test_server_; | 380 bool autostart_test_server_; |
| 360 base::HistogramTester histogram_tester_; | 381 base::HistogramTester histogram_tester_; |
| 361 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; | 382 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; |
| 362 | 383 |
| 363 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); | 384 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); |
| 364 }; | 385 }; |
| 365 | 386 |
| 387 // A test observer that allows the observed navigation start time to be set. |
| 388 class TestPrerenderPageLoadMetricsObserver |
| 389 : public PrerenderPageLoadMetricsObserver { |
| 390 public: |
| 391 using PrerenderPageLoadMetricsObserver::PrerenderPageLoadMetricsObserver; |
| 392 |
| 393 void SetNavigationStartTo(base::TimeTicks ticks) { |
| 394 SetNavigationStartTicksForTesting(ticks); |
| 395 } |
| 396 }; |
| 397 |
| 366 // Makes |url| respond to requests with the contents of |file|, counting the | 398 // Makes |url| respond to requests with the contents of |file|, counting the |
| 367 // number that start in |counter|. | 399 // number that start in |counter|. |
| 368 void CreateCountingInterceptorOnIO( | 400 void CreateCountingInterceptorOnIO( |
| 369 const GURL& url, | 401 const GURL& url, |
| 370 const base::FilePath& file, | 402 const base::FilePath& file, |
| 371 const base::WeakPtr<RequestCounter>& counter); | 403 const base::WeakPtr<RequestCounter>& counter); |
| 372 | 404 |
| 373 // Checks that |url| has been requested with net::LOAD_PREFETCH. Pings |counter| | 405 // Checks that |url| has been requested with net::LOAD_PREFETCH. Pings |counter| |
| 374 // after the flag is checked. | 406 // after the flag is checked. |
| 375 void CreatePrefetchOnlyInterceptorOnIO( | 407 void CreatePrefetchOnlyInterceptorOnIO( |
| 376 const GURL& url, | 408 const GURL& url, |
| 377 const base::WeakPtr<RequestCounter>& counter); | 409 const base::WeakPtr<RequestCounter>& counter); |
| 378 | 410 |
| 379 // Makes |url| respond to requests with the contents of |file|. | 411 // Makes |url| respond to requests with the contents of |file|. |
| 380 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); | 412 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); |
| 381 | 413 |
| 382 // Makes |url| never respond on the first load, and then with the contents of | 414 // Makes |url| never respond on the first load, and then with the contents of |
| 383 // |file| afterwards. When the first load has been scheduled, runs |callback| on | 415 // |file| afterwards. When the first load has been scheduled, runs |callback| on |
| 384 // the UI thread. | 416 // the UI thread. |
| 385 void CreateHangingFirstRequestInterceptorOnIO( | 417 void CreateHangingFirstRequestInterceptorOnIO( |
| 386 const GURL& url, const base::FilePath& file, base::Closure callback); | 418 const GURL& url, const base::FilePath& file, base::Closure callback); |
| 387 | 419 |
| 388 } // namespace test_utils | 420 } // namespace test_utils |
| 389 | 421 |
| 390 } // namespace prerender | 422 } // namespace prerender |
| 391 | 423 |
| 392 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ | 424 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ |
| OLD | NEW |