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

Side by Side Diff: components/doodle/doodle_service_unittest.cc

Issue 2833473002: Record NTP.LogoShownTime for timely refreshs only (Closed)
Patch Set: Split refresh callback into own interface Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/doodle/doodle_service.h" 5 #include "components/doodle/doodle_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ASSERT_THAT(fetcher()->num_pending_callbacks(), Eq(0u)); 483 ASSERT_THAT(fetcher()->num_pending_callbacks(), Eq(0u));
484 484
485 // The outcome should still have been recorded, but not the time - we only 485 // The outcome should still have been recorded, but not the time - we only
486 // record that for successful downloads. 486 // record that for successful downloads.
487 histograms.ExpectUniqueSample("Doodle.ConfigDownloadOutcome", 487 histograms.ExpectUniqueSample("Doodle.ConfigDownloadOutcome",
488 7, // OUTCOME_REFRESH_INTERVAL_NOT_PASSED 488 7, // OUTCOME_REFRESH_INTERVAL_NOT_PASSED
489 1); 489 1);
490 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0); 490 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0);
491 } 491 }
492 492
493 TEST_F(DoodleServiceTest, RefreshReturnsFalseOnlyForSkippedRefreshAttempts) {
494 // Create a service with some refresh interval.
495 RecreateService(/*min_refresh_interval=*/base::TimeDelta::FromMinutes(10));
496
497 // Trigger a refresh resulting in a fetch that receives information about no
498 // newer doodle being available.
499 EXPECT_TRUE(service()->Refresh());
500 fetcher()->ServeAllCallbacks(DoodleState::NO_DOODLE, base::TimeDelta(),
501 base::nullopt);
502
503 // Request a refresh before the min refresh interval has passed which should
504 // not have resulted in a request.
505 EXPECT_FALSE(service()->Refresh());
506 EXPECT_THAT(fetcher()->num_pending_callbacks(), Eq(0u));
507 }
508
493 TEST_F(DoodleServiceTest, DoesNotRecordMetricsAtStartup) { 509 TEST_F(DoodleServiceTest, DoesNotRecordMetricsAtStartup) {
494 // Creating the service should not emit any histogram samples. 510 // Creating the service should not emit any histogram samples.
495 base::HistogramTester histograms; 511 base::HistogramTester histograms;
496 RecreateServiceWithZeroRefreshInterval(); 512 RecreateServiceWithZeroRefreshInterval();
497 ASSERT_THAT(service()->config(), Eq(base::nullopt)); 513 ASSERT_THAT(service()->config(), Eq(base::nullopt));
498 histograms.ExpectTotalCount("Doodle.ConfigDownloadOutcome", 0); 514 histograms.ExpectTotalCount("Doodle.ConfigDownloadOutcome", 0);
499 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0); 515 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0);
500 } 516 }
501 517
502 TEST_F(DoodleServiceTest, DoesNotRecordMetricsAtStartupWithConfig) { 518 TEST_F(DoodleServiceTest, DoesNotRecordMetricsAtStartupWithConfig) {
(...skipping 26 matching lines...) Expand all
529 // Fast-forward time so that the config expires. 545 // Fast-forward time so that the config expires.
530 task_runner()->FastForwardBy(base::TimeDelta::FromHours(1)); 546 task_runner()->FastForwardBy(base::TimeDelta::FromHours(1));
531 ASSERT_THAT(service()->config(), Eq(base::nullopt)); 547 ASSERT_THAT(service()->config(), Eq(base::nullopt));
532 548
533 // This should not have resulted in any metrics being emitted. 549 // This should not have resulted in any metrics being emitted.
534 histograms.ExpectTotalCount("Doodle.ConfigDownloadOutcome", 0); 550 histograms.ExpectTotalCount("Doodle.ConfigDownloadOutcome", 0);
535 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0); 551 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0);
536 } 552 }
537 553
538 } // namespace doodle 554 } // namespace doodle
OLDNEW
« components/doodle/doodle_service.h ('K') | « components/doodle/doodle_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698