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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc

Issue 2569663004: [NTPSnippets] Switch from TickClock to Clock for storing the last background fetched time. (Closed)
Patch Set: Add a DCHECK to check that the num or args passed to the new method is 0 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 unified diff | Download patch
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestions_provider.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ntp_snippets/remote/remote_suggestions_provider.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/test/histogram_tester.h" 22 #include "base/test/histogram_tester.h"
23 #include "base/test/simple_test_tick_clock.h" 23 #include "base/test/simple_test_clock.h"
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "components/image_fetcher/image_decoder.h" 26 #include "components/image_fetcher/image_decoder.h"
27 #include "components/image_fetcher/image_fetcher.h" 27 #include "components/image_fetcher/image_fetcher.h"
28 #include "components/image_fetcher/image_fetcher_delegate.h" 28 #include "components/image_fetcher/image_fetcher_delegate.h"
29 #include "components/ntp_snippets/category_factory.h" 29 #include "components/ntp_snippets/category_factory.h"
30 #include "components/ntp_snippets/category_info.h" 30 #include "components/ntp_snippets/category_info.h"
31 #include "components/ntp_snippets/ntp_snippets_constants.h" 31 #include "components/ntp_snippets/ntp_snippets_constants.h"
32 #include "components/ntp_snippets/pref_names.h" 32 #include "components/ntp_snippets/pref_names.h"
33 #include "components/ntp_snippets/remote/ntp_snippet.h" 33 #include "components/ntp_snippets/remote/ntp_snippet.h"
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), 1593 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()),
1594 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); 1594 SizeIs(service->GetMaxSnippetCountForTesting() + 1));
1595 } 1595 }
1596 1596
1597 TEST_F(RemoteSuggestionsProviderTest, StoreLastSuccessfullBackgroundFetchTime) { 1597 TEST_F(RemoteSuggestionsProviderTest, StoreLastSuccessfullBackgroundFetchTime) {
1598 // On initialization of the RemoteSuggestionsProvider a background fetch is 1598 // On initialization of the RemoteSuggestionsProvider a background fetch is
1599 // triggered since the snippets DB is empty. Therefore the service must not be 1599 // triggered since the snippets DB is empty. Therefore the service must not be
1600 // initialized until the test clock is set. 1600 // initialized until the test clock is set.
1601 auto service = MakeSnippetsServiceWithoutInitialization(); 1601 auto service = MakeSnippetsServiceWithoutInitialization();
1602 1602
1603 auto simple_test_tick_clock = base::MakeUnique<base::SimpleTestTickClock>(); 1603 auto simple_test_clock = base::MakeUnique<base::SimpleTestClock>();
1604 base::SimpleTestTickClock* simple_test_tick_clock_ptr = 1604 base::SimpleTestClock* simple_test_clock_ptr = simple_test_clock.get();
1605 simple_test_tick_clock.get(); 1605 service->SetClockForTesting(std::move(simple_test_clock));
1606 service->SetTickClockForTesting(std::move(simple_test_tick_clock));
1607 1606
1608 // Test that the preference is correctly initialized with the default value 0. 1607 // Test that the preference is correctly initialized with the default value 0.
1609 EXPECT_EQ( 1608 EXPECT_EQ(
1610 0, pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); 1609 0, pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime));
1611 1610
1612 WaitForSnippetsServiceInitialization(service.get(), 1611 WaitForSnippetsServiceInitialization(service.get(),
1613 /*set_empty_response=*/true); 1612 /*set_empty_response=*/true);
1614 EXPECT_EQ( 1613 EXPECT_EQ(
1615 simple_test_tick_clock_ptr->NowTicks().ToInternalValue(), 1614 simple_test_clock_ptr->Now().ToInternalValue(),
1616 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); 1615 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime));
1617 1616
1618 // Advance the time and check whether the time was updated correctly after the 1617 // Advance the time and check whether the time was updated correctly after the
1619 // background fetch. 1618 // background fetch.
1620 simple_test_tick_clock_ptr->Advance(TimeDelta::FromHours(1)); 1619 simple_test_clock_ptr->Advance(TimeDelta::FromHours(1));
1621 service->FetchSnippetsInTheBackground(); 1620 service->FetchSnippetsInTheBackground();
1622 base::RunLoop().RunUntilIdle(); 1621 base::RunLoop().RunUntilIdle();
1623 EXPECT_EQ( 1622 EXPECT_EQ(
1624 simple_test_tick_clock_ptr->NowTicks().ToInternalValue(), 1623 simple_test_clock_ptr->Now().ToInternalValue(),
1625 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); 1624 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime));
1626 // TODO(markusheintz): Add a test that simulates a browser restart once the 1625 // TODO(markusheintz): Add a test that simulates a browser restart once the
1627 // scheduler refactoring is done (crbug.com/672434). 1626 // scheduler refactoring is done (crbug.com/672434).
1628 } 1627 }
1629 1628
1630 } // namespace ntp_snippets 1629 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestions_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698