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

Unified Diff: components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc

Issue 2549163002: RemoteContentSuggestions: Stores the time of the last successful background fetch in a pref (Closed)
Patch Set: Address comments treib Created 4 years 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 side-by-side diff with in-line comments
Download patch
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..27ac0a2efee7c070fe71981ad46f0b1da1bf3161 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,37 @@ 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(),
tschumann 2016/12/08 18:18:51 can you add a comment explaining that a fetch requ
+ /*set_empty_response=*/true);
+ EXPECT_EQ(
+ simple_test_tick_clock_ptr->NowTicks().ToInternalValue(),
tschumann 2016/12/08 18:18:51 can you set up the clock's current time when initi
+ 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));
+ // TODO(markusheintz): Add a test that simulates a browser restart once the
+ // scheduler refactoring is done (crbug.com/672434).
+}
+
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698