| 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 "chrome/browser/prerender/prerender_test_utils.h" | 5 #include "chrome/browser/prerender/prerender_test_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" | 17 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
| 17 #include "chrome/browser/prerender/prerender_manager.h" | 18 #include "chrome/browser/prerender/prerender_manager.h" |
| 18 #include "chrome/browser/prerender/prerender_manager_factory.h" | 19 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/safe_browsing/local_database_manager.h" | 21 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 contents_ = nullptr; | 493 contents_ = nullptr; |
| 493 final_status_ = contents->final_status(); | 494 final_status_ = contents->final_status(); |
| 494 stopped_ = true; | 495 stopped_ = true; |
| 495 stop_loop_.Quit(); | 496 stop_loop_.Quit(); |
| 496 // If there is a WaitForLoads call and it has yet to see the expected number | 497 // If there is a WaitForLoads call and it has yet to see the expected number |
| 497 // of loads, stop the loop so the test fails instead of timing out. | 498 // of loads, stop the loop so the test fails instead of timing out. |
| 498 if (load_waiter_) | 499 if (load_waiter_) |
| 499 load_waiter_->Quit(); | 500 load_waiter_->Quit(); |
| 500 } | 501 } |
| 501 | 502 |
| 503 // static |
| 504 FirstContentfulPaintManagerWaiter* FirstContentfulPaintManagerWaiter::Create( |
| 505 PrerenderManager* manager) { |
| 506 auto fcp_waiter = base::WrapUnique(new FirstContentfulPaintManagerWaiter()); |
| 507 auto fcp_waiter_ptr = fcp_waiter.get(); |
| 508 manager->AddObserver(std::move(fcp_waiter)); |
| 509 return fcp_waiter_ptr; |
| 510 } |
| 511 |
| 512 FirstContentfulPaintManagerWaiter::FirstContentfulPaintManagerWaiter() |
| 513 : saw_fcp_(false) {} |
| 514 |
| 515 FirstContentfulPaintManagerWaiter::~FirstContentfulPaintManagerWaiter() {} |
| 516 |
| 517 void FirstContentfulPaintManagerWaiter::OnFirstContentfulPaint() { |
| 518 saw_fcp_ = true; |
| 519 if (waiter_) |
| 520 waiter_->Quit(); |
| 521 } |
| 522 |
| 523 void FirstContentfulPaintManagerWaiter::Wait() { |
| 524 if (saw_fcp_) |
| 525 return; |
| 526 waiter_ = base::MakeUnique<base::RunLoop>(); |
| 527 waiter_->Run(); |
| 528 waiter_.reset(); |
| 529 } |
| 530 |
| 502 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} | 531 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} |
| 503 | 532 |
| 504 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { | 533 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { |
| 505 EXPECT_TRUE(expected_contents_queue_.empty()); | 534 EXPECT_TRUE(expected_contents_queue_.empty()); |
| 506 } | 535 } |
| 507 | 536 |
| 508 std::unique_ptr<TestPrerender> | 537 std::unique_ptr<TestPrerender> |
| 509 TestPrerenderContentsFactory::ExpectPrerenderContents( | 538 TestPrerenderContentsFactory::ExpectPrerenderContents( |
| 510 FinalStatus final_status) { | 539 FinalStatus final_status) { |
| 511 std::unique_ptr<TestPrerender> handle(new TestPrerender()); | 540 std::unique_ptr<TestPrerender> handle(new TestPrerender()); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 770 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 742 std::unique_ptr<net::URLRequestInterceptor> interceptor( | 771 std::unique_ptr<net::URLRequestInterceptor> interceptor( |
| 743 new HangingFirstRequestInterceptor(file, callback)); | 772 new HangingFirstRequestInterceptor(file, callback)); |
| 744 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 773 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 745 url, std::move(interceptor)); | 774 url, std::move(interceptor)); |
| 746 } | 775 } |
| 747 | 776 |
| 748 } // namespace test_utils | 777 } // namespace test_utils |
| 749 | 778 |
| 750 } // namespace prerender | 779 } // namespace prerender |
| OLD | NEW |