| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |