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

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 1896423002: [NTP Snippets] Add tests for scheduling/unscheduling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/ntp_snippets_service_unittest.cc
diff --git a/components/ntp_snippets/ntp_snippets_service_unittest.cc b/components/ntp_snippets/ntp_snippets_service_unittest.cc
index 02be166a44d6c2cde072dac055773db58adedacb..63fc3c95329878677b447a219b482e65fcb73170 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -13,10 +13,14 @@
#include "base/time/time.h"
#include "components/ntp_snippets/ntp_snippet.h"
#include "components/ntp_snippets/ntp_snippets_fetcher.h"
+#include "components/ntp_snippets/ntp_snippets_scheduler.h"
#include "components/prefs/testing_pref_service.h"
#include "net/url_request/url_request_test_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::_;
+
namespace ntp_snippets {
namespace {
@@ -100,6 +104,19 @@ void ParseJson(
}
}
+class MockScheduler : public NTPSnippetsScheduler {
+ public:
+ MockScheduler() {}
Bernhard Bauer 2016/04/20 11:25:57 Nit: I would just remove the default constructor a
Marc Treib 2016/04/20 12:03:04 Done.
+ ~MockScheduler() {}
+
+ MOCK_METHOD4(Schedule,
+ bool(base::TimeDelta period_wifi_charging,
+ base::TimeDelta period_wifi,
+ base::TimeDelta period_fallback,
+ base::Time reschedule_time));
+ MOCK_METHOD0(Unschedule, bool());
+};
+
} // namespace
class NTPSnippetsServiceTest : public testing::Test {
@@ -114,24 +131,32 @@ class NTPSnippetsServiceTest : public testing::Test {
CreateSnippetsService();
}
- void CreateSnippetsService() {
+ virtual void CreateSnippetsService() {
+ CreateSnippetsServiceEnabled(true);
+ }
+
+ void CreateSnippetsServiceEnabled(bool enabled) {
+ scheduler_.reset(new MockScheduler);
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
base::ThreadTaskRunnerHandle::Get());
scoped_refptr<net::TestURLRequestContextGetter> request_context_getter =
new net::TestURLRequestContextGetter(task_runner.get());
service_.reset(new NTPSnippetsService(
- pref_service_.get(), nullptr, task_runner, std::string("fr"), nullptr,
+ pref_service_.get(), nullptr, task_runner, std::string("fr"),
+ scheduler_.get(),
make_scoped_ptr(new NTPSnippetsFetcher(
task_runner, std::move(request_context_getter), true)),
base::Bind(&ParseJson, true)));
- service_->Init(true);
+ if (enabled)
+ EXPECT_CALL(*scheduler_, Schedule(_, _, _, _));
+ else
+ EXPECT_CALL(*scheduler_, Unschedule());
+ service_->Init(enabled);
}
protected:
- NTPSnippetsService* service() {
- return service_.get();
- }
+ NTPSnippetsService* service() { return service_.get(); }
void LoadFromJSONString(const std::string& json) {
service_->OnSnippetsDownloaded(json);
@@ -145,10 +170,26 @@ class NTPSnippetsServiceTest : public testing::Test {
base::MessageLoop message_loop_;
scoped_ptr<TestingPrefServiceSimple> pref_service_;
scoped_ptr<NTPSnippetsService> service_;
+ scoped_ptr<MockScheduler> scheduler_;
DISALLOW_COPY_AND_ASSIGN(NTPSnippetsServiceTest);
};
+class NTPSnippetsServiceDisabledTest : public NTPSnippetsServiceTest {
+ public:
+ void CreateSnippetsService() override {
+ CreateSnippetsServiceEnabled(false);
+ }
+};
+
+TEST_F(NTPSnippetsServiceTest, Schedule) {
+ // CreateSnippetsServiceEnabled checks that Schedule is called.
Bernhard Bauer 2016/04/20 11:25:57 This is a bit strange, but I guess it works...
Marc Treib 2016/04/20 12:03:04 Well, suggestions for improvement welcome :)
+}
+
+TEST_F(NTPSnippetsServiceDisabledTest, Unschedule) {
+ // CreateSnippetsServiceEnabled checks that Unschedule is called.
+}
+
TEST_F(NTPSnippetsServiceTest, Loop) {
std::string json_str(
"{ \"recos\": [ "
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698