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

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/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/strings/string_split.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" 18 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h"
18 #include "chrome/browser/prerender/prerender_manager.h" 19 #include "chrome/browser/prerender/prerender_manager.h"
19 #include "chrome/browser/prerender/prerender_manager_factory.h" 20 #include "chrome/browser/prerender/prerender_manager_factory.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/safe_browsing/local_database_manager.h" 22 #include "chrome/browser/safe_browsing/local_database_manager.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 contents_ = nullptr; 525 contents_ = nullptr;
525 final_status_ = contents->final_status(); 526 final_status_ = contents->final_status();
526 stopped_ = true; 527 stopped_ = true;
527 stop_loop_.Quit(); 528 stop_loop_.Quit();
528 // If there is a WaitForLoads call and it has yet to see the expected number 529 // If there is a WaitForLoads call and it has yet to see the expected number
529 // of loads, stop the loop so the test fails instead of timing out. 530 // of loads, stop the loop so the test fails instead of timing out.
530 if (load_waiter_) 531 if (load_waiter_)
531 load_waiter_->Quit(); 532 load_waiter_->Quit();
532 } 533 }
533 534
535 // static
536 FirstContentfulPaintManagerWaiter* FirstContentfulPaintManagerWaiter::Create(
537 PrerenderManager* manager) {
538 auto fcp_waiter = base::WrapUnique(new FirstContentfulPaintManagerWaiter());
539 auto fcp_waiter_ptr = fcp_waiter.get();
540 manager->AddObserver(std::move(fcp_waiter));
541 return fcp_waiter_ptr;
542 }
543
544 FirstContentfulPaintManagerWaiter::FirstContentfulPaintManagerWaiter()
545 : saw_fcp_(false) {}
546
547 FirstContentfulPaintManagerWaiter::~FirstContentfulPaintManagerWaiter() {}
548
549 void FirstContentfulPaintManagerWaiter::OnFirstContentfulPaint() {
550 saw_fcp_ = true;
551 if (waiter_)
552 waiter_->Quit();
553 }
554
555 void FirstContentfulPaintManagerWaiter::Wait() {
556 if (saw_fcp_)
557 return;
558 waiter_ = base::MakeUnique<base::RunLoop>();
559 waiter_->Run();
560 waiter_.reset();
561 }
562
534 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} 563 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {}
535 564
536 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { 565 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() {
537 EXPECT_TRUE(expected_contents_queue_.empty()); 566 EXPECT_TRUE(expected_contents_queue_.empty());
538 } 567 }
539 568
540 std::unique_ptr<TestPrerender> 569 std::unique_ptr<TestPrerender>
541 TestPrerenderContentsFactory::ExpectPrerenderContents( 570 TestPrerenderContentsFactory::ExpectPrerenderContents(
542 FinalStatus final_status) { 571 FinalStatus final_status) {
543 std::unique_ptr<TestPrerender> handle(new TestPrerender()); 572 std::unique_ptr<TestPrerender> handle(new TestPrerender());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 801 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
773 std::unique_ptr<net::URLRequestInterceptor> interceptor( 802 std::unique_ptr<net::URLRequestInterceptor> interceptor(
774 new HangingFirstRequestInterceptor(file, callback)); 803 new HangingFirstRequestInterceptor(file, callback));
775 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 804 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
776 url, std::move(interceptor)); 805 url, std::move(interceptor));
777 } 806 }
778 807
779 } // namespace test_utils 808 } // namespace test_utils
780 809
781 } // namespace prerender 810 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698