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

Side by Side Diff: chrome/browser/notifications/extension_welcome_notification_unittest.cc

Issue 151963002: Remove duplicated code from sync related unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed a const qualifier. Created 6 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/notifications/extension_welcome_notification.h" 5 #include "chrome/browser/notifications/extension_welcome_notification.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/test_simple_task_runner.h" 13 #include "base/test/test_simple_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "chrome/browser/notifications/notification.h" 15 #include "chrome/browser/notifications/notification.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/testing_pref_service_syncable.h" 17 #include "chrome/test/base/testing_pref_service_syncable.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "components/user_prefs/pref_registry_syncable.h" 19 #include "components/user_prefs/pref_registry_syncable.h"
20 #include "sync/api/fake_sync_change_processor.h"
20 #include "sync/api/sync_error_factory_mock.h" 21 #include "sync/api/sync_error_factory_mock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/message_center/fake_message_center.h" 23 #include "ui/message_center/fake_message_center.h"
23 #include "ui/message_center/notification.h" 24 #include "ui/message_center/notification.h"
24 25
25 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; 26 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh";
26 27
27 class MockMessageCenter : public message_center::FakeMessageCenter { 28 class MockMessageCenter : public message_center::FakeMessageCenter {
28 public: 29 public:
29 MockMessageCenter() 30 MockMessageCenter()
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 116
116 private: 117 private:
117 const base::Time start_time_; 118 const base::Time start_time_;
118 base::TimeDelta elapsed_time_; 119 base::TimeDelta elapsed_time_;
119 scoped_ptr<MockMessageCenter> message_center_; 120 scoped_ptr<MockMessageCenter> message_center_;
120 base::Closure pending_task_; 121 base::Closure pending_task_;
121 122
122 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate); 123 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate);
123 }; 124 };
124 125
125 class TestSyncProcessor : public syncer::SyncChangeProcessor {
126 public:
127 TestSyncProcessor() {}
128
129 virtual syncer::SyncError ProcessSyncChanges(
130 const tracked_objects::Location& from_here,
131 const syncer::SyncChangeList& change_list) OVERRIDE {
132 return syncer::SyncError();
133 }
134
135 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type)
136 const OVERRIDE {
137 return syncer::SyncDataList();
138 }
139
140 private:
141 DISALLOW_COPY_AND_ASSIGN(TestSyncProcessor);
142 };
143
144 class ExtensionWelcomeNotificationTest : public testing::Test { 126 class ExtensionWelcomeNotificationTest : public testing::Test {
145 protected: 127 protected:
146 ExtensionWelcomeNotificationTest() { 128 ExtensionWelcomeNotificationTest() {
147 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry( 129 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
148 new user_prefs::PrefRegistrySyncable()); 130 new user_prefs::PrefRegistrySyncable());
149 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get()); 131 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
150 } 132 }
151 133
152 virtual void SetUp() { 134 virtual void SetUp() {
153 task_runner_ = new base::TestSimpleTaskRunner(); 135 task_runner_ = new base::TestSimpleTaskRunner();
154 thread_task_runner_handle_.reset( 136 thread_task_runner_handle_.reset(
155 new base::ThreadTaskRunnerHandle(task_runner_)); 137 new base::ThreadTaskRunnerHandle(task_runner_));
156 profile_.reset(new TestingProfile()); 138 profile_.reset(new TestingProfile());
157 delegate_ = new WelcomeNotificationDelegate(); 139 delegate_ = new WelcomeNotificationDelegate();
158 welcome_notification_ = ExtensionWelcomeNotification::Create( 140 welcome_notification_ = ExtensionWelcomeNotification::Create(
159 kChromeNowExtensionID, profile_.get(), delegate_); 141 kChromeNowExtensionID, profile_.get(), delegate_);
160 } 142 }
161 143
162 virtual void TearDown() { 144 virtual void TearDown() {
163 delegate_ = NULL; 145 delegate_ = NULL;
164 welcome_notification_.reset(); 146 welcome_notification_.reset();
165 profile_.reset(); 147 profile_.reset();
166 thread_task_runner_handle_.reset(); 148 thread_task_runner_handle_.reset();
167 task_runner_ = NULL; 149 task_runner_ = NULL;
168 } 150 }
169 151
170 void StartPreferenceSyncing() const { 152 void StartPreferenceSyncing() const {
171 PrefServiceSyncable::FromProfile(profile_.get()) 153 PrefServiceSyncable::FromProfile(profile_.get())
172 ->GetSyncableService(syncer::PREFERENCES) 154 ->GetSyncableService(syncer::PREFERENCES)
173 ->MergeDataAndStartSyncing( 155 ->MergeDataAndStartSyncing(syncer::PREFERENCES,
174 syncer::PREFERENCES, 156 syncer::SyncDataList(),
175 syncer::SyncDataList(), 157 scoped_ptr<syncer::SyncChangeProcessor>(
176 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessor), 158 new syncer::FakeSyncChangeProcessor),
177 scoped_ptr<syncer::SyncErrorFactory>( 159 scoped_ptr<syncer::SyncErrorFactory>(
178 new syncer::SyncErrorFactoryMock())); 160 new syncer::SyncErrorFactoryMock()));
179 } 161 }
180 162
181 void ShowChromeNowNotification() const { 163 void ShowChromeNowNotification() const {
182 ShowNotification( 164 ShowNotification(
183 "ChromeNowNotification", 165 "ChromeNowNotification",
184 message_center::NotifierId(message_center::NotifierId::APPLICATION, 166 message_center::NotifierId(message_center::NotifierId::APPLICATION,
185 kChromeNowExtensionID)); 167 kChromeNowExtensionID));
186 } 168 }
187 169
188 void ShowRegularNotification() const { 170 void ShowRegularNotification() const {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); 474 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
493 EXPECT_EQ(message_center()->add_notification_calls(), 0); 475 EXPECT_EQ(message_center()->add_notification_calls(), 0);
494 EXPECT_EQ(message_center()->remove_notification_calls(), 0); 476 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
495 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); 477 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
496 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); 478 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
497 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); 479 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
498 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); 480 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
499 } 481 }
500 482
501 // C++ Readability Review Change Trigger 483 // C++ Readability Review Change Trigger
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698