Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: chrome/browser/prerender/prerender_test_utils.cc

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 contents_ = nullptr; 470 contents_ = nullptr;
470 final_status_ = contents->final_status(); 471 final_status_ = contents->final_status();
471 stopped_ = true; 472 stopped_ = true;
472 stop_loop_.Quit(); 473 stop_loop_.Quit();
473 // If there is a WaitForLoads call and it has yet to see the expected number 474 // If there is a WaitForLoads call and it has yet to see the expected number
474 // of loads, stop the loop so the test fails instead of timing out. 475 // of loads, stop the loop so the test fails instead of timing out.
475 if (load_waiter_) 476 if (load_waiter_)
476 load_waiter_->Quit(); 477 load_waiter_->Quit();
477 } 478 }
478 479
480 // static
481 FirstContentfulPaintManagerWaiter* FirstContentfulPaintManagerWaiter::Create(
482 PrerenderManager* manager) {
483 auto fcp_waiter = base::WrapUnique(new FirstContentfulPaintManagerWaiter());
484 auto fcp_waiter_ptr = fcp_waiter.get();
485 manager->AddObserver(std::move(fcp_waiter));
486 return fcp_waiter_ptr;
487 }
488
489 FirstContentfulPaintManagerWaiter::FirstContentfulPaintManagerWaiter()
490 : saw_fcp_(false) {}
491
492 FirstContentfulPaintManagerWaiter::~FirstContentfulPaintManagerWaiter() {}
493
494 void FirstContentfulPaintManagerWaiter::OnFirstContentfulPaint() {
495 saw_fcp_ = true;
496 if (waiter_)
497 waiter_->Quit();
498 }
499
500 void FirstContentfulPaintManagerWaiter::Wait() {
501 if (saw_fcp_)
502 return;
503 waiter_ = base::MakeUnique<base::RunLoop>();
504 waiter_->Run();
505 waiter_.reset();
506 }
507
479 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} 508 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {}
480 509
481 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { 510 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() {
482 EXPECT_TRUE(expected_contents_queue_.empty()); 511 EXPECT_TRUE(expected_contents_queue_.empty());
483 } 512 }
484 513
485 std::unique_ptr<TestPrerender> 514 std::unique_ptr<TestPrerender>
486 TestPrerenderContentsFactory::ExpectPrerenderContents( 515 TestPrerenderContentsFactory::ExpectPrerenderContents(
487 FinalStatus final_status) { 516 FinalStatus final_status) {
488 std::unique_ptr<TestPrerender> handle(new TestPrerender()); 517 std::unique_ptr<TestPrerender> handle(new TestPrerender());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 739 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
711 std::unique_ptr<net::URLRequestInterceptor> interceptor( 740 std::unique_ptr<net::URLRequestInterceptor> interceptor(
712 new HangingFirstRequestInterceptor(file, callback)); 741 new HangingFirstRequestInterceptor(file, callback));
713 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 742 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
714 url, std::move(interceptor)); 743 url, std::move(interceptor));
715 } 744 }
716 745
717 } // namespace test_utils 746 } // namespace test_utils
718 747
719 } // namespace prerender 748 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698