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

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

Issue 2776973003: [Doodle] Move ttl clamping from fetcher to service (Closed)
Patch Set: Created 3 years, 8 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 | « components/doodle/doodle_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // Now load an expired config again. The cached one should go away. 350 // Now load an expired config again. The cached one should go away.
351 service()->Refresh(); 351 service()->Refresh();
352 EXPECT_CALL(observer, OnDoodleConfigUpdated(Eq(base::nullopt))); 352 EXPECT_CALL(observer, OnDoodleConfigUpdated(Eq(base::nullopt)));
353 fetcher()->ServeAllCallbacks(DoodleState::AVAILABLE, 353 fetcher()->ServeAllCallbacks(DoodleState::AVAILABLE,
354 base::TimeDelta::FromSeconds(0), config); 354 base::TimeDelta::FromSeconds(0), config);
355 355
356 // Remove the observer before the service gets destroyed. 356 // Remove the observer before the service gets destroyed.
357 service()->RemoveObserver(&observer); 357 service()->RemoveObserver(&observer);
358 } 358 }
359 359
360 TEST_F(DoodleServiceTest, ClampsTimeToLive) {
361 // Load a config with an excessive time-to-live.
362 service()->Refresh();
363 DoodleConfig config = CreateConfig(DoodleType::SIMPLE);
364 fetcher()->ServeAllCallbacks(DoodleState::AVAILABLE,
365 base::TimeDelta::FromDays(100), config);
366 ASSERT_THAT(service()->config(), Eq(config));
367
368 // The time-to-live should have been clamped to a reasonable maximum.
369 ASSERT_THAT(task_runner()->GetPendingTaskCount(), Eq(1u));
370 EXPECT_THAT(task_runner()->NextPendingTaskDelay(),
371 Eq(base::TimeDelta::FromDays(30)));
372 }
373
360 TEST_F(DoodleServiceTest, RecordsMetricsForSuccessfulDownload) { 374 TEST_F(DoodleServiceTest, RecordsMetricsForSuccessfulDownload) {
361 base::HistogramTester histograms; 375 base::HistogramTester histograms;
362 376
363 // Load a doodle config as usual, but let it take some time. 377 // Load a doodle config as usual, but let it take some time.
364 service()->Refresh(); 378 service()->Refresh();
365 task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5)); 379 task_runner()->FastForwardBy(base::TimeDelta::FromSeconds(5));
366 DoodleConfig config = CreateConfig(DoodleType::SIMPLE); 380 DoodleConfig config = CreateConfig(DoodleType::SIMPLE);
367 fetcher()->ServeAllCallbacks(DoodleState::AVAILABLE, 381 fetcher()->ServeAllCallbacks(DoodleState::AVAILABLE,
368 base::TimeDelta::FromHours(1), config); 382 base::TimeDelta::FromHours(1), config);
369 ASSERT_THAT(service()->config(), Eq(config)); 383 ASSERT_THAT(service()->config(), Eq(config));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // Fast-forward time so that the config expires. 467 // Fast-forward time so that the config expires.
454 task_runner()->FastForwardBy(base::TimeDelta::FromHours(1)); 468 task_runner()->FastForwardBy(base::TimeDelta::FromHours(1));
455 ASSERT_THAT(service()->config(), Eq(base::nullopt)); 469 ASSERT_THAT(service()->config(), Eq(base::nullopt));
456 470
457 // This should not have resulted in any metrics being emitted. 471 // This should not have resulted in any metrics being emitted.
458 histograms.ExpectTotalCount("Doodle.ConfigDownloadOutcome", 0); 472 histograms.ExpectTotalCount("Doodle.ConfigDownloadOutcome", 0);
459 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0); 473 histograms.ExpectTotalCount("Doodle.ConfigDownloadTime", 0);
460 } 474 }
461 475
462 } // namespace doodle 476 } // namespace doodle
OLDNEW
« no previous file with comments | « components/doodle/doodle_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698