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

Side by Side Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc

Issue 2371883002: Add PLMObserver::FlushMetricsOnAppEnterBackground. (Closed)
Patch Set: fix comment Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/page_load_metrics/metrics_web_contents_observer.h" 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 void OnTimingUpdate(const PageLoadTiming& timing, 52 void OnTimingUpdate(const PageLoadTiming& timing,
53 const PageLoadExtraInfo& extra_info) override { 53 const PageLoadExtraInfo& extra_info) override {
54 updated_timings_->push_back(timing); 54 updated_timings_->push_back(timing);
55 } 55 }
56 56
57 void OnComplete(const PageLoadTiming& timing, 57 void OnComplete(const PageLoadTiming& timing,
58 const PageLoadExtraInfo& extra_info) override { 58 const PageLoadExtraInfo& extra_info) override {
59 complete_timings_->push_back(timing); 59 complete_timings_->push_back(timing);
60 } 60 }
61 61
62 ObservePolicy FlushMetricsOnAppEnterBackground(
63 const PageLoadTiming& timing,
64 const PageLoadExtraInfo& extra_info) override {
65 return STOP_OBSERVING;
66 }
67
62 private: 68 private:
63 std::vector<PageLoadTiming>* const updated_timings_; 69 std::vector<PageLoadTiming>* const updated_timings_;
64 std::vector<PageLoadTiming>* const complete_timings_; 70 std::vector<PageLoadTiming>* const complete_timings_;
65 std::vector<GURL>* const observed_committed_urls_; 71 std::vector<GURL>* const observed_committed_urls_;
66 }; 72 };
67 73
68 class TestPageLoadMetricsEmbedderInterface 74 class TestPageLoadMetricsEmbedderInterface
69 : public PageLoadMetricsEmbedderInterface { 75 : public PageLoadMetricsEmbedderInterface {
70 public: 76 public:
71 TestPageLoadMetricsEmbedderInterface() 77 TestPageLoadMetricsEmbedderInterface()
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 183
178 private: 184 private:
179 int num_errors_; 185 int num_errors_;
180 186
181 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserverTest); 187 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserverTest);
182 }; 188 };
183 189
184 TEST_F(MetricsWebContentsObserverTest, SuccessfulMainFrameNavigation) { 190 TEST_F(MetricsWebContentsObserverTest, SuccessfulMainFrameNavigation) {
185 PageLoadTiming timing; 191 PageLoadTiming timing;
186 timing.navigation_start = base::Time::FromDoubleT(1); 192 timing.navigation_start = base::Time::FromDoubleT(1);
187 timing.response_start = base::TimeDelta::FromMilliseconds(2);
188 193
189 content::WebContentsTester* web_contents_tester = 194 content::WebContentsTester* web_contents_tester =
190 content::WebContentsTester::For(web_contents()); 195 content::WebContentsTester::For(web_contents());
191 196
192 ASSERT_TRUE(observed_committed_urls_from_on_start().empty()); 197 ASSERT_TRUE(observed_committed_urls_from_on_start().empty());
193 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 198 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
194 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); 199 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size());
195 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); 200 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty());
196 201
197 ASSERT_EQ(0, CountUpdatedTimingReported()); 202 ASSERT_EQ(0, CountUpdatedTimingReported());
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 496
492 observer_->FlushMetricsOnAppEnterBackground(); 497 observer_->FlushMetricsOnAppEnterBackground();
493 498
494 histogram_tester_.ExpectTotalCount( 499 histogram_tester_.ExpectTotalCount(
495 internal::kPageLoadCompletedAfterAppBackground, 1); 500 internal::kPageLoadCompletedAfterAppBackground, 1);
496 histogram_tester_.ExpectBucketCount( 501 histogram_tester_.ExpectBucketCount(
497 internal::kPageLoadCompletedAfterAppBackground, false, 1); 502 internal::kPageLoadCompletedAfterAppBackground, false, 1);
498 histogram_tester_.ExpectBucketCount( 503 histogram_tester_.ExpectBucketCount(
499 internal::kPageLoadCompletedAfterAppBackground, true, 0); 504 internal::kPageLoadCompletedAfterAppBackground, true, 0);
500 505
506 // Navigate again, which forces completion callbacks on the previous
507 // navigation to be invoked.
508 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
509
510 // Verify that, even though the page load completed, no complete timings were
511 // reported, because the TestPageLoadMetricsObserver's
512 // FlushMetricsOnAppEnterBackground implementation returned STOP_OBSERVING,
513 // thus preventing OnComplete from being invoked.
514 ASSERT_EQ(0, CountCompleteTimingReported());
515
501 DeleteContents(); 516 DeleteContents();
502 517
503 histogram_tester_.ExpectTotalCount( 518 histogram_tester_.ExpectTotalCount(
504 internal::kPageLoadCompletedAfterAppBackground, 2); 519 internal::kPageLoadCompletedAfterAppBackground, 2);
505 histogram_tester_.ExpectBucketCount( 520 histogram_tester_.ExpectBucketCount(
506 internal::kPageLoadCompletedAfterAppBackground, false, 1); 521 internal::kPageLoadCompletedAfterAppBackground, false, 1);
507 histogram_tester_.ExpectBucketCount( 522 histogram_tester_.ExpectBucketCount(
508 internal::kPageLoadCompletedAfterAppBackground, true, 1); 523 internal::kPageLoadCompletedAfterAppBackground, true, 1);
509 } 524 }
510 525
511 } // namespace page_load_metrics 526 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698