| 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 contents_ = nullptr; | 421 contents_ = nullptr; |
| 421 final_status_ = contents->final_status(); | 422 final_status_ = contents->final_status(); |
| 422 stopped_ = true; | 423 stopped_ = true; |
| 423 stop_loop_.Quit(); | 424 stop_loop_.Quit(); |
| 424 // If there is a WaitForLoads call and it has yet to see the expected number | 425 // If there is a WaitForLoads call and it has yet to see the expected number |
| 425 // of loads, stop the loop so the test fails instead of timing out. | 426 // of loads, stop the loop so the test fails instead of timing out. |
| 426 if (load_waiter_) | 427 if (load_waiter_) |
| 427 load_waiter_->Quit(); | 428 load_waiter_->Quit(); |
| 428 } | 429 } |
| 429 | 430 |
| 431 // static |
| 432 FirstContentfulPaintManagerWaiter* FirstContentfulPaintManagerWaiter::Create( |
| 433 PrerenderManager* manager) { |
| 434 auto fcp_waiter = base::WrapUnique(new FirstContentfulPaintManagerWaiter()); |
| 435 auto fcp_waiter_ptr = fcp_waiter.get(); |
| 436 manager->AddObserver(std::move(fcp_waiter)); |
| 437 return fcp_waiter_ptr; |
| 438 } |
| 439 |
| 440 FirstContentfulPaintManagerWaiter::FirstContentfulPaintManagerWaiter() |
| 441 : saw_fcp_(false) {} |
| 442 |
| 443 FirstContentfulPaintManagerWaiter::~FirstContentfulPaintManagerWaiter() {} |
| 444 |
| 445 void FirstContentfulPaintManagerWaiter::OnFirstContentfulPaint() { |
| 446 saw_fcp_ = true; |
| 447 if (waiter_) |
| 448 waiter_->Quit(); |
| 449 #if 0 |
| 450 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 451 waiter_->QuitClosure()); |
| 452 #endif |
| 453 } |
| 454 |
| 455 void FirstContentfulPaintManagerWaiter::Wait() { |
| 456 if (saw_fcp_) |
| 457 return; |
| 458 waiter_ = base::MakeUnique<base::RunLoop>(); |
| 459 waiter_->Run(); |
| 460 waiter_.reset(); |
| 461 } |
| 462 |
| 430 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} | 463 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} |
| 431 | 464 |
| 432 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { | 465 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { |
| 433 EXPECT_TRUE(expected_contents_queue_.empty()); | 466 EXPECT_TRUE(expected_contents_queue_.empty()); |
| 434 } | 467 } |
| 435 | 468 |
| 436 std::unique_ptr<TestPrerender> | 469 std::unique_ptr<TestPrerender> |
| 437 TestPrerenderContentsFactory::ExpectPrerenderContents( | 470 TestPrerenderContentsFactory::ExpectPrerenderContents( |
| 438 FinalStatus final_status) { | 471 FinalStatus final_status) { |
| 439 std::unique_ptr<TestPrerender> handle(new TestPrerender()); | 472 std::unique_ptr<TestPrerender> handle(new TestPrerender()); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { | 685 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| 653 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 686 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 654 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 687 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 655 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 688 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 656 file, content::BrowserThread::GetBlockingPool())); | 689 file, content::BrowserThread::GetBlockingPool())); |
| 657 } | 690 } |
| 658 | 691 |
| 659 } // namespace test_utils | 692 } // namespace test_utils |
| 660 | 693 |
| 661 } // namespace prerender | 694 } // namespace prerender |
| OLD | NEW |