Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 25 #include "components/image_fetcher/image_decoder.h" | 26 #include "components/image_fetcher/image_decoder.h" |
| 26 #include "components/image_fetcher/image_fetcher.h" | 27 #include "components/image_fetcher/image_fetcher.h" |
| 27 #include "components/image_fetcher/image_fetcher_delegate.h" | 28 #include "components/image_fetcher/image_fetcher_delegate.h" |
| 28 #include "components/ntp_snippets/category_factory.h" | 29 #include "components/ntp_snippets/category_factory.h" |
| 29 #include "components/ntp_snippets/category_info.h" | 30 #include "components/ntp_snippets/category_info.h" |
| 30 #include "components/ntp_snippets/ntp_snippets_constants.h" | 31 #include "components/ntp_snippets/ntp_snippets_constants.h" |
| 31 #include "components/ntp_snippets/pref_names.h" | 32 #include "components/ntp_snippets/pref_names.h" |
| 32 #include "components/ntp_snippets/remote/ntp_snippet.h" | 33 #include "components/ntp_snippets/remote/ntp_snippet.h" |
| (...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1586 suggestions.push_back(GetSnippetWithUrl( | 1587 suggestions.push_back(GetSnippetWithUrl( |
| 1587 base::StringPrintf("http://localhost/snippet-id-%d", i))); | 1588 base::StringPrintf("http://localhost/snippet-id-%d", i))); |
| 1588 } | 1589 } |
| 1589 LoadFromJSONString(service.get(), GetTestJson(suggestions)); | 1590 LoadFromJSONString(service.get(), GetTestJson(suggestions)); |
| 1590 // TODO(tschumann): We should probably trim out any additional results and | 1591 // TODO(tschumann): We should probably trim out any additional results and |
| 1591 // only serve the MaxSnippetCount items. | 1592 // only serve the MaxSnippetCount items. |
| 1592 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), | 1593 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), |
| 1593 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); | 1594 SizeIs(service->GetMaxSnippetCountForTesting() + 1)); |
| 1594 } | 1595 } |
| 1595 | 1596 |
| 1597 TEST_F(RemoteSuggestionsProviderTest, StoreLastSuccessfullBackgroundFetchTime) { | |
| 1598 // On initialization of the RemoteSuggestionsProvider a background fetch is | |
| 1599 // triggered since the snippets DB is empty. Therefore the service must not be | |
| 1600 // initialized until the test clock is set. | |
| 1601 auto service = MakeSnippetsServiceWithoutInitialization(); | |
| 1602 | |
| 1603 base::SimpleTestTickClock* simple_test_tick_clock = | |
| 1604 new base::SimpleTestTickClock(); | |
|
Marc Treib
2016/12/07 14:42:13
I dislike raw pointers :) How about:
- Make a uni
markusheintz_
2016/12/08 09:47:41
Done
| |
| 1605 std::unique_ptr<base::TickClock> tick_clock(simple_test_tick_clock); | |
| 1606 service->SetTickClockForTesting(std::move(tick_clock)); | |
| 1607 | |
| 1608 base::TimeTicks test_now = base::TimeTicks::Now(); | |
| 1609 simple_test_tick_clock->SetNowTicks(test_now); | |
|
Marc Treib
2016/12/07 14:42:13
Should this happen before passing the clock to the
markusheintz_
2016/12/08 09:47:41
SGTM done
| |
| 1610 | |
| 1611 // Test that the preference is correclty initialized with the default value 0. | |
|
Marc Treib
2016/12/07 14:42:13
s/correclty/correctly/
markusheintz_
2016/12/08 09:47:41
Done.
| |
| 1612 EXPECT_EQ( | |
| 1613 0, pref_service()->GetInt64(prefs::kLastSuccessfullBackgroundFetchTime)); | |
| 1614 | |
| 1615 // Initialize the service. Setting |set_empty_response| to true will trigger a | |
| 1616 // background fetch on initialization since the snippets DB is still empty. | |
|
Marc Treib
2016/12/07 14:42:13
This isn't really accurate - the background fetch
markusheintz_
2016/12/08 09:47:41
This is not what I experienced when I wrote this.
| |
| 1617 WaitForSnippetsServiceInitialization(service.get(), | |
| 1618 /*set_empty_response=*/true); | |
| 1619 | |
| 1620 EXPECT_EQ( | |
| 1621 test_now.ToInternalValue(), | |
| 1622 pref_service()->GetInt64(prefs::kLastSuccessfullBackgroundFetchTime)); | |
| 1623 | |
| 1624 simple_test_tick_clock->Advance(TimeDelta::FromHours(1)); | |
| 1625 service->FetchSnippetsInTheBackground(); | |
| 1626 base::RunLoop().RunUntilIdle(); | |
| 1627 | |
| 1628 EXPECT_EQ( | |
| 1629 (test_now + TimeDelta::FromHours(1)).ToInternalValue(), | |
|
Marc Treib
2016/12/07 14:42:13
This could just use simple_test_tick_clock->NowTic
| |
| 1630 pref_service()->GetInt64(prefs::kLastSuccessfullBackgroundFetchTime)); | |
| 1631 } | |
| 1632 | |
| 1596 } // namespace ntp_snippets | 1633 } // namespace ntp_snippets |
| OLD | NEW |