Chromium Code Reviews| Index: components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc |
| diff --git a/components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc b/components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc |
| index b593ee4958589942d58af50c81b03cf56d745b34..f809e1e18d7ae1eb4baa9122159f2aaac663af5a 100644 |
| --- a/components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc |
| +++ b/components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc |
| @@ -20,6 +20,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/test/histogram_tester.h" |
| +#include "base/test/simple_test_tick_clock.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| #include "components/image_fetcher/image_decoder.h" |
| @@ -1593,4 +1594,35 @@ TEST_F(RemoteSuggestionsProviderTest, |
| SizeIs(service->GetMaxSnippetCountForTesting() + 1)); |
| } |
| +TEST_F(RemoteSuggestionsProviderTest, StoreLastSuccessfullBackgroundFetchTime) { |
| + // On initialization of the RemoteSuggestionsProvider a background fetch is |
| + // triggered since the snippets DB is empty. Therefore the service must not be |
| + // initialized until the test clock is set. |
| + auto service = MakeSnippetsServiceWithoutInitialization(); |
| + |
| + auto simple_test_tick_clock = base::MakeUnique<base::SimpleTestTickClock>(); |
| + base::SimpleTestTickClock* simple_test_tick_clock_ptr = |
| + simple_test_tick_clock.get(); |
| + service->SetTickClockForTesting(std::move(simple_test_tick_clock)); |
| + |
| + // Test that the preference is correctly initialized with the default value 0. |
| + EXPECT_EQ( |
| + 0, pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| + |
| + WaitForSnippetsServiceInitialization(service.get(), |
| + /*set_empty_response=*/true); |
| + EXPECT_EQ( |
| + simple_test_tick_clock_ptr->NowTicks().ToInternalValue(), |
| + pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| + |
| + // Advance the time and check whether the time was updated correctly after the |
| + // background fetch. |
| + simple_test_tick_clock_ptr->Advance(TimeDelta::FromHours(1)); |
| + service->FetchSnippetsInTheBackground(); |
| + base::RunLoop().RunUntilIdle(); |
| + EXPECT_EQ( |
| + simple_test_tick_clock_ptr->NowTicks().ToInternalValue(), |
| + pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| +} |
|
Marc Treib
2016/12/08 10:33:49
Optional: You could re-create the service here, to
markusheintz_
2016/12/08 11:37:18
Excellent idea. Once the scheduler refactoring is
|
| + |
| } // namespace ntp_snippets |