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

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

Issue 580093003: Factor Google Now welcome notifications out of DesktopNotificationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 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/pref_registry/pref_registry_syncable.h" 19 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "sync/api/fake_sync_change_processor.h" 20 #include "sync/api/fake_sync_change_processor.h"
21 #include "sync/api/sync_error_factory_mock.h" 21 #include "sync/api/sync_error_factory_mock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/message_center/fake_message_center.h" 23 #include "ui/message_center/fake_message_center.h"
24 #include "ui/message_center/notification.h" 24 #include "ui/message_center/notification.h"
25 25
26 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh";
27
28 class MockMessageCenter : public message_center::FakeMessageCenter { 26 class MockMessageCenter : public message_center::FakeMessageCenter {
29 public: 27 public:
30 MockMessageCenter() 28 MockMessageCenter()
31 : add_notification_calls_(0), 29 : add_notification_calls_(0),
32 remove_notification_calls_(0), 30 remove_notification_calls_(0),
33 notifications_with_shown_as_popup_(0) { 31 notifications_with_shown_as_popup_(0) {
34 } 32 }
35 33
36 int add_notification_calls() { return add_notification_calls_; } 34 int add_notification_calls() { return add_notification_calls_; }
37 int remove_notification_calls() { return remove_notification_calls_; } 35 int remove_notification_calls() { return remove_notification_calls_; }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 new user_prefs::PrefRegistrySyncable()); 131 new user_prefs::PrefRegistrySyncable());
134 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get()); 132 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
135 } 133 }
136 134
137 virtual void SetUp() { 135 virtual void SetUp() {
138 task_runner_ = new base::TestSimpleTaskRunner(); 136 task_runner_ = new base::TestSimpleTaskRunner();
139 thread_task_runner_handle_.reset( 137 thread_task_runner_handle_.reset(
140 new base::ThreadTaskRunnerHandle(task_runner_)); 138 new base::ThreadTaskRunnerHandle(task_runner_));
141 profile_.reset(new TestingProfile()); 139 profile_.reset(new TestingProfile());
142 delegate_ = new WelcomeNotificationDelegate(); 140 delegate_ = new WelcomeNotificationDelegate();
143 welcome_notification_ = ExtensionWelcomeNotification::Create( 141 welcome_notification_.reset(
144 kChromeNowExtensionID, profile_.get(), delegate_); 142 ExtensionWelcomeNotification::Create(profile_.get(), delegate_));
145 } 143 }
146 144
147 virtual void TearDown() { 145 virtual void TearDown() {
148 delegate_ = NULL; 146 delegate_ = NULL;
149 welcome_notification_.reset(); 147 welcome_notification_.reset();
150 profile_.reset(); 148 profile_.reset();
151 thread_task_runner_handle_.reset(); 149 thread_task_runner_handle_.reset();
152 task_runner_ = NULL; 150 task_runner_ = NULL;
153 } 151 }
154 152
155 void StartPreferenceSyncing() const { 153 void StartPreferenceSyncing() const {
156 PrefServiceSyncable::FromProfile(profile_.get()) 154 PrefServiceSyncable::FromProfile(profile_.get())
157 ->GetSyncableService(syncer::PREFERENCES) 155 ->GetSyncableService(syncer::PREFERENCES)
158 ->MergeDataAndStartSyncing(syncer::PREFERENCES, 156 ->MergeDataAndStartSyncing(syncer::PREFERENCES,
159 syncer::SyncDataList(), 157 syncer::SyncDataList(),
160 scoped_ptr<syncer::SyncChangeProcessor>( 158 scoped_ptr<syncer::SyncChangeProcessor>(
161 new syncer::FakeSyncChangeProcessor), 159 new syncer::FakeSyncChangeProcessor),
162 scoped_ptr<syncer::SyncErrorFactory>( 160 scoped_ptr<syncer::SyncErrorFactory>(
163 new syncer::SyncErrorFactoryMock())); 161 new syncer::SyncErrorFactoryMock()));
164 } 162 }
165 163
166 void ShowChromeNowNotification() const { 164 void ShowChromeNowNotification() const {
167 ShowNotification( 165 ShowNotification(
168 "ChromeNowNotification", 166 "ChromeNowNotification",
169 message_center::NotifierId(message_center::NotifierId::APPLICATION, 167 message_center::NotifierId(
170 kChromeNowExtensionID)); 168 message_center::NotifierId::APPLICATION,
169 ExtensionWelcomeNotification::kChromeNowExtensionID));
171 } 170 }
172 171
173 void ShowRegularNotification() const { 172 void ShowRegularNotification() const {
174 ShowNotification( 173 ShowNotification(
175 "RegularNotification", 174 "RegularNotification",
176 message_center::NotifierId(message_center::NotifierId::APPLICATION, 175 message_center::NotifierId(message_center::NotifierId::APPLICATION,
177 "aaaabbbbccccddddeeeeffffggghhhhi")); 176 "aaaabbbbccccddddeeeeffffggghhhhi"));
178 } 177 }
179 178
180 void FlushMessageLoop() { delegate_->RunPendingTask(); } 179 void FlushMessageLoop() { delegate_->RunPendingTask(); }
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 541
543 EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); 542 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
544 EXPECT_EQ(message_center()->add_notification_calls(), 0); 543 EXPECT_EQ(message_center()->add_notification_calls(), 0);
545 EXPECT_EQ(message_center()->remove_notification_calls(), 0); 544 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
546 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); 545 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
547 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); 546 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
548 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); 547 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
549 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); 548 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
550 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); 549 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
551 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698