Chromium Code Reviews| 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()); | |
|
pasko
2016/11/17 19:52:16
WrapUnique is discouraged, is MakeUnique somehow n
mattcary
2016/11/18 09:21:11
The constructor for FirstContentfulPaintManagerWai
| |
| 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 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
|
pasko
2016/11/17 19:52:16
Confused.
I assumed this class lives on UI thread
mattcary
2016/11/18 09:21:11
This is how I think things are happening. I may ve
| |
| 449 waiter_->QuitClosure()); | |
| 450 } | |
| 451 | |
| 452 void FirstContentfulPaintManagerWaiter::Wait() { | |
| 453 if (saw_fcp_) | |
| 454 return; | |
| 455 waiter_ = base::MakeUnique<base::RunLoop>(); | |
| 456 waiter_->Run(); | |
| 457 waiter_.reset(); | |
| 458 } | |
| 459 | |
| 430 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} | 460 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} |
| 431 | 461 |
| 432 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { | 462 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { |
| 433 EXPECT_TRUE(expected_contents_queue_.empty()); | 463 EXPECT_TRUE(expected_contents_queue_.empty()); |
| 434 } | 464 } |
| 435 | 465 |
| 436 std::unique_ptr<TestPrerender> | 466 std::unique_ptr<TestPrerender> |
| 437 TestPrerenderContentsFactory::ExpectPrerenderContents( | 467 TestPrerenderContentsFactory::ExpectPrerenderContents( |
| 438 FinalStatus final_status) { | 468 FinalStatus final_status) { |
| 439 std::unique_ptr<TestPrerender> handle(new TestPrerender()); | 469 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) { | 682 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| 653 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 683 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 654 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 684 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 655 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 685 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 656 file, content::BrowserThread::GetBlockingPool())); | 686 file, content::BrowserThread::GetBlockingPool())); |
| 657 } | 687 } |
| 658 | 688 |
| 659 } // namespace test_utils | 689 } // namespace test_utils |
| 660 | 690 |
| 661 } // namespace prerender | 691 } // namespace prerender |
| OLD | NEW |