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

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: Rename SyncChangeProcessorDelgate to SyncChangeProcessorDelgator. 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 task_to_run.Run(); 110 task_to_run.Run();
110 } 111 }
111 112
112 private: 113 private:
113 base::Time start_time_; 114 base::Time start_time_;
114 base::TimeDelta elapsed_time_; 115 base::TimeDelta elapsed_time_;
115 scoped_ptr<MockMessageCenter> message_center_; 116 scoped_ptr<MockMessageCenter> message_center_;
116 base::Closure pending_task_; 117 base::Closure pending_task_;
117 }; 118 };
118 119
119 class TestSyncProcessor : public syncer::SyncChangeProcessor {
120 virtual syncer::SyncError ProcessSyncChanges(
121 const tracked_objects::Location& from_here,
122 const syncer::SyncChangeList& change_list) OVERRIDE {
123 return syncer::SyncError();
124 }
125
126 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type)
127 const OVERRIDE {
128 return syncer::SyncDataList();
129 }
130 };
131
132 class ExtensionWelcomeNotificationTest : public testing::Test { 120 class ExtensionWelcomeNotificationTest : public testing::Test {
133 protected: 121 protected:
134 ExtensionWelcomeNotificationTest() { 122 ExtensionWelcomeNotificationTest() {
135 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry( 123 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
136 new user_prefs::PrefRegistrySyncable()); 124 new user_prefs::PrefRegistrySyncable());
137 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get()); 125 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
138 } 126 }
139 127
140 virtual void SetUp() { 128 virtual void SetUp() {
141 task_runner_ = new base::TestSimpleTaskRunner(); 129 task_runner_ = new base::TestSimpleTaskRunner();
142 thread_task_runner_handle_.reset( 130 thread_task_runner_handle_.reset(
143 new base::ThreadTaskRunnerHandle(task_runner_)); 131 new base::ThreadTaskRunnerHandle(task_runner_));
144 profile_.reset(new TestingProfile()); 132 profile_.reset(new TestingProfile());
145 delegate_ = new WelcomeNotificationDelegate(); 133 delegate_ = new WelcomeNotificationDelegate();
146 welcome_notification_ = ExtensionWelcomeNotification::Create( 134 welcome_notification_ = ExtensionWelcomeNotification::Create(
147 kChromeNowExtensionID, profile_.get(), delegate_); 135 kChromeNowExtensionID, profile_.get(), delegate_);
148 } 136 }
149 137
150 virtual void TearDown() { 138 virtual void TearDown() {
151 delegate_ = NULL; 139 delegate_ = NULL;
152 welcome_notification_.reset(); 140 welcome_notification_.reset();
153 profile_.reset(); 141 profile_.reset();
154 thread_task_runner_handle_.reset(); 142 thread_task_runner_handle_.reset();
155 task_runner_ = NULL; 143 task_runner_ = NULL;
156 } 144 }
157 145
158 void StartPreferenceSyncing() { 146 void StartPreferenceSyncing() {
159 PrefServiceSyncable::FromProfile(profile_.get()) 147 PrefServiceSyncable::FromProfile(profile_.get())
160 ->GetSyncableService(syncer::PREFERENCES) 148 ->GetSyncableService(syncer::PREFERENCES)
161 ->MergeDataAndStartSyncing( 149 ->MergeDataAndStartSyncing(syncer::PREFERENCES,
162 syncer::PREFERENCES, 150 syncer::SyncDataList(),
163 syncer::SyncDataList(), 151 scoped_ptr<syncer::SyncChangeProcessor>(
164 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessor), 152 new syncer::FakeSyncChangeProcessor),
165 scoped_ptr<syncer::SyncErrorFactory>( 153 scoped_ptr<syncer::SyncErrorFactory>(
166 new syncer::SyncErrorFactoryMock())); 154 new syncer::SyncErrorFactoryMock()));
167 } 155 }
168 156
169 void ShowChromeNowNotification() { 157 void ShowChromeNowNotification() {
170 ShowNotification( 158 ShowNotification(
171 "ChromeNowNotification", 159 "ChromeNowNotification",
172 message_center::NotifierId(message_center::NotifierId::APPLICATION, 160 message_center::NotifierId(message_center::NotifierId::APPLICATION,
173 kChromeNowExtensionID)); 161 kChromeNowExtensionID));
174 } 162 }
175 163
176 void ShowRegularNotification() { 164 void ShowRegularNotification() {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); 433 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
446 EXPECT_TRUE(message_center()->add_notification_calls() == 1); 434 EXPECT_TRUE(message_center()->add_notification_calls() == 1);
447 EXPECT_TRUE(message_center()->remove_notification_calls() == 1); 435 EXPECT_TRUE(message_center()->remove_notification_calls() == 1);
448 EXPECT_TRUE(message_center()->notifications_with_shown_as_popup() == 0); 436 EXPECT_TRUE(message_center()->notifications_with_shown_as_popup() == 0);
449 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); 437 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
450 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); 438 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
451 EXPECT_TRUE( 439 EXPECT_TRUE(
452 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp) == 440 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp) ==
453 (GetStartTime() + requested_show_time).ToInternalValue()); 441 (GetStartTime() + requested_show_time).ToInternalValue());
454 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698