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

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

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: MSVC compilation error Created 3 years, 11 months 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
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_split.h" 16 #include "base/run_loop.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" 18 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h"
19 #include "chrome/browser/prerender/prerender_manager.h" 19 #include "chrome/browser/prerender/prerender_manager.h"
20 #include "chrome/browser/prerender/prerender_manager_factory.h" 20 #include "chrome/browser/prerender/prerender_manager_factory.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/safe_browsing/local_database_manager.h" 22 #include "chrome/browser/safe_browsing/local_database_manager.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 contents_ = nullptr; 529 contents_ = nullptr;
530 final_status_ = contents->final_status(); 530 final_status_ = contents->final_status();
531 stopped_ = true; 531 stopped_ = true;
532 stop_loop_.Quit(); 532 stop_loop_.Quit();
533 // If there is a WaitForLoads call and it has yet to see the expected number 533 // If there is a WaitForLoads call and it has yet to see the expected number
534 // of loads, stop the loop so the test fails instead of timing out. 534 // of loads, stop the loop so the test fails instead of timing out.
535 if (load_waiter_) 535 if (load_waiter_)
536 load_waiter_->Quit(); 536 load_waiter_->Quit();
537 } 537 }
538 538
539 // static
540 FirstContentfulPaintManagerWaiter* FirstContentfulPaintManagerWaiter::Create(
541 PrerenderManager* manager) {
542 auto fcp_waiter = base::WrapUnique(new FirstContentfulPaintManagerWaiter());
543 auto fcp_waiter_ptr = fcp_waiter.get();
544 manager->AddObserver(std::move(fcp_waiter));
545 return fcp_waiter_ptr;
546 }
547
548 FirstContentfulPaintManagerWaiter::FirstContentfulPaintManagerWaiter()
549 : saw_fcp_(false) {}
550
551 FirstContentfulPaintManagerWaiter::~FirstContentfulPaintManagerWaiter() {}
552
553 void FirstContentfulPaintManagerWaiter::OnFirstContentfulPaint() {
554 saw_fcp_ = true;
555 if (waiter_)
556 waiter_->Quit();
557 }
558
559 void FirstContentfulPaintManagerWaiter::Wait() {
560 if (saw_fcp_)
561 return;
562 waiter_ = base::MakeUnique<base::RunLoop>();
563 waiter_->Run();
564 waiter_.reset();
565 }
566
539 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} 567 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {}
540 568
541 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { 569 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() {
542 EXPECT_TRUE(expected_contents_queue_.empty()); 570 EXPECT_TRUE(expected_contents_queue_.empty());
543 } 571 }
544 572
545 std::unique_ptr<TestPrerender> 573 std::unique_ptr<TestPrerender>
546 TestPrerenderContentsFactory::ExpectPrerenderContents( 574 TestPrerenderContentsFactory::ExpectPrerenderContents(
547 FinalStatus final_status) { 575 FinalStatus final_status) {
548 std::unique_ptr<TestPrerender> handle(new TestPrerender()); 576 std::unique_ptr<TestPrerender> handle(new TestPrerender());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 805 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
778 std::unique_ptr<net::URLRequestInterceptor> interceptor( 806 std::unique_ptr<net::URLRequestInterceptor> interceptor(
779 new HangingFirstRequestInterceptor(file, callback)); 807 new HangingFirstRequestInterceptor(file, callback));
780 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 808 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
781 url, std::move(interceptor)); 809 url, std::move(interceptor));
782 } 810 }
783 811
784 } // namespace test_utils 812 } // namespace test_utils
785 813
786 } // namespace prerender 814 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698