| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void MarkDestruction(FinalStatus reason); | 236 void MarkDestruction(FinalStatus reason); |
| 236 | 237 |
| 237 base::RunLoop wait_loop_; | 238 base::RunLoop wait_loop_; |
| 238 FinalStatus expected_final_status_; | 239 FinalStatus expected_final_status_; |
| 239 bool saw_correct_status_; | 240 bool saw_correct_status_; |
| 240 std::unique_ptr<DestructionMarker> marker_; | 241 std::unique_ptr<DestructionMarker> marker_; |
| 241 | 242 |
| 242 DISALLOW_COPY_AND_ASSIGN(DestructionWaiter); | 243 DISALLOW_COPY_AND_ASSIGN(DestructionWaiter); |
| 243 }; | 244 }; |
| 244 | 245 |
| 246 // Wait until a PrerenderManager has seen a first contentful paint. |
| 247 class FirstContentfulPaintManagerWaiter : public PrerenderManagerObserver { |
| 248 public: |
| 249 // Create and return a pointer to a |FirstContentfulPaintManagerWaiter|. The |
| 250 // instance is owned by the |PrerenderManager|. |
| 251 static FirstContentfulPaintManagerWaiter* Create(PrerenderManager* manager); |
| 252 ~FirstContentfulPaintManagerWaiter(); |
| 253 |
| 254 void OnFirstContentfulPaint() override; |
| 255 |
| 256 // Wait for a first contentful paint to be seen by our PrerenderManager. |
| 257 void Wait(); |
| 258 |
| 259 private: |
| 260 FirstContentfulPaintManagerWaiter(); |
| 261 |
| 262 std::unique_ptr<base::RunLoop> waiter_; |
| 263 bool saw_fcp_; |
| 264 }; |
| 265 |
| 245 // PrerenderContentsFactory that uses TestPrerenderContents. | 266 // PrerenderContentsFactory that uses TestPrerenderContents. |
| 246 class TestPrerenderContentsFactory : public PrerenderContents::Factory { | 267 class TestPrerenderContentsFactory : public PrerenderContents::Factory { |
| 247 public: | 268 public: |
| 248 TestPrerenderContentsFactory(); | 269 TestPrerenderContentsFactory(); |
| 249 | 270 |
| 250 ~TestPrerenderContentsFactory() override; | 271 ~TestPrerenderContentsFactory() override; |
| 251 | 272 |
| 252 std::unique_ptr<TestPrerender> ExpectPrerenderContents( | 273 std::unique_ptr<TestPrerender> ExpectPrerenderContents( |
| 253 FinalStatus final_status); | 274 FinalStatus final_status); |
| 254 | 275 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 safe_browsing_factory_; | 382 safe_browsing_factory_; |
| 362 TestPrerenderContentsFactory* prerender_contents_factory_; | 383 TestPrerenderContentsFactory* prerender_contents_factory_; |
| 363 Browser* explicitly_set_browser_; | 384 Browser* explicitly_set_browser_; |
| 364 bool autostart_test_server_; | 385 bool autostart_test_server_; |
| 365 base::HistogramTester histogram_tester_; | 386 base::HistogramTester histogram_tester_; |
| 366 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; | 387 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; |
| 367 | 388 |
| 368 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); | 389 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); |
| 369 }; | 390 }; |
| 370 | 391 |
| 392 // A test observer that allows the observed navigation start time to be set. |
| 393 class TestPrerenderPageLoadMetricsObserver |
| 394 : public PrerenderPageLoadMetricsObserver { |
| 395 public: |
| 396 using PrerenderPageLoadMetricsObserver::PrerenderPageLoadMetricsObserver; |
| 397 |
| 398 void SetNavigationStartMilliseconds(int ms) { |
| 399 SetNavigationStartTicksForTesting(base::TimeTicks() + |
| 400 base::TimeDelta::FromMilliseconds(ms)); |
| 401 } |
| 402 |
| 403 void SetNavigationStartFromZero(base::TimeDelta delta) { |
| 404 SetNavigationStartTicksForTesting(base::TimeTicks() + delta); |
| 405 } |
| 406 }; |
| 407 |
| 371 // Makes |url| respond to requests with the contents of |file|, counting the | 408 // Makes |url| respond to requests with the contents of |file|, counting the |
| 372 // number that start in |counter|. | 409 // number that start in |counter|. |
| 373 void CreateCountingInterceptorOnIO( | 410 void CreateCountingInterceptorOnIO( |
| 374 const GURL& url, | 411 const GURL& url, |
| 375 const base::FilePath& file, | 412 const base::FilePath& file, |
| 376 const base::WeakPtr<RequestCounter>& counter); | 413 const base::WeakPtr<RequestCounter>& counter); |
| 377 | 414 |
| 378 // Makes |url| respond to requests with the contents of |file|. | 415 // Makes |url| respond to requests with the contents of |file|. |
| 379 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); | 416 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); |
| 380 | 417 |
| 381 } // namespace test_utils | 418 } // namespace test_utils |
| 382 | 419 |
| 383 } // namespace prerender | 420 } // namespace prerender |
| 384 | 421 |
| 385 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ | 422 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ |
| OLD | NEW |