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
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/extension_welcome_notification.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/test_simple_task_runner.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "chrome/browser/notifications/notification.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/testing_pref_service_syncable.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "components/user_prefs/pref_registry_syncable.h"
20 #include "sync/api/fake_sync_change_processor.h"
21 #include "sync/api/sync_error_factory_mock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/message_center/fake_message_center.h"
24 #include "ui/message_center/notification.h"
26 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh";
28 class MockMessageCenter : public message_center::FakeMessageCenter {
31 : add_notification_calls_(0),
32 remove_notification_calls_(0),
33 notifications_with_shown_as_popup_(0) {
36 int add_notification_calls() { return add_notification_calls_; }
37 int remove_notification_calls() { return remove_notification_calls_; }
38 int notifications_with_shown_as_popup() {
39 return notifications_with_shown_as_popup_;
42 // message_center::FakeMessageCenter Overrides
43 virtual bool HasNotification(const std::string& id) OVERRIDE {
44 return last_notification.get() && (last_notification->id() == id);
47 virtual void AddNotification(
48 scoped_ptr<message_center::Notification> notification) OVERRIDE {
49 EXPECT_FALSE(last_notification.get());
50 last_notification.swap(notification);
51 add_notification_calls_++;
52 if (last_notification->shown_as_popup())
53 notifications_with_shown_as_popup_++;
56 virtual void RemoveNotification(const std::string& id,
57 bool by_user) OVERRIDE {
58 EXPECT_TRUE(last_notification.get());
59 last_notification.reset();
60 remove_notification_calls_++;
63 void CloseCurrentNotification() {
64 EXPECT_TRUE(last_notification.get());
65 last_notification->delegate()->Close(true);
66 RemoveNotification(last_notification->id(), true);
70 scoped_ptr<message_center::Notification> last_notification;
71 int add_notification_calls_;
72 int remove_notification_calls_;
73 int notifications_with_shown_as_popup_;
75 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter);
78 class WelcomeNotificationDelegate
79 : public ExtensionWelcomeNotification::Delegate {
81 WelcomeNotificationDelegate()
82 : start_time_(base::Time::Now()),
83 message_center_(new MockMessageCenter()) {
86 // ExtensionWelcomeNotification::Delegate
87 virtual message_center::MessageCenter* GetMessageCenter() OVERRIDE {
88 return message_center_.get();
91 virtual base::Time GetCurrentTime() OVERRIDE {
92 return start_time_ + elapsed_time_;
95 virtual void PostTask(
96 const tracked_objects::Location& from_here,
97 const base::Closure& task) OVERRIDE {
98 EXPECT_TRUE(pending_task_.is_null());
102 // WelcomeNotificationDelegate
103 MockMessageCenter* message_center() const { return message_center_.get(); }
105 base::Time GetStartTime() const { return start_time_; }
107 void SetElapsedTime(base::TimeDelta elapsed_time) {
108 elapsed_time_ = elapsed_time;
111 void RunPendingTask() {
112 base::Closure task_to_run = pending_task_;
113 pending_task_.Reset();
118 const base::Time start_time_;
119 base::TimeDelta elapsed_time_;
120 scoped_ptr<MockMessageCenter> message_center_;
121 base::Closure pending_task_;
123 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate);
126 class ExtensionWelcomeNotificationTest : public testing::Test {
128 ExtensionWelcomeNotificationTest() {
129 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
130 new user_prefs::PrefRegistrySyncable());
131 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
134 virtual void SetUp() {
135 task_runner_ = new base::TestSimpleTaskRunner();
136 thread_task_runner_handle_.reset(
137 new base::ThreadTaskRunnerHandle(task_runner_));
138 profile_.reset(new TestingProfile());
139 delegate_ = new WelcomeNotificationDelegate();
140 welcome_notification_ = ExtensionWelcomeNotification::Create(
141 kChromeNowExtensionID, profile_.get(), delegate_);
144 virtual void TearDown() {
146 welcome_notification_.reset();
148 thread_task_runner_handle_.reset();
152 void StartPreferenceSyncing() const {
153 PrefServiceSyncable::FromProfile(profile_.get())
154 ->GetSyncableService(syncer::PREFERENCES)
155 ->MergeDataAndStartSyncing(syncer::PREFERENCES,
156 syncer::SyncDataList(),
157 scoped_ptr<syncer::SyncChangeProcessor>(
158 new syncer::FakeSyncChangeProcessor),
159 scoped_ptr<syncer::SyncErrorFactory>(
160 new syncer::SyncErrorFactoryMock()));
163 void ShowChromeNowNotification() const {
165 "ChromeNowNotification",
166 message_center::NotifierId(message_center::NotifierId::APPLICATION,
167 kChromeNowExtensionID));
170 void ShowRegularNotification() const {
172 "RegularNotification",
173 message_center::NotifierId(message_center::NotifierId::APPLICATION,
174 "aaaabbbbccccddddeeeeffffggghhhhi"));
177 void FlushMessageLoop() { delegate_->RunPendingTask(); }
179 MockMessageCenter* message_center() const {
180 return delegate_->message_center();
182 base::TestSimpleTaskRunner* task_runner() const {
183 return task_runner_.get();
185 base::Time GetStartTime() const {
186 return delegate_->GetStartTime();
188 void SetElapsedTime(base::TimeDelta elapsed_time) const {
189 delegate_->SetElapsedTime(elapsed_time);
191 bool GetBooleanPref(const char* path) const {
192 return profile_->GetPrefs()->GetBoolean(path);
194 void SetBooleanPref(const char* path, bool value) const {
195 profile_->GetPrefs()->SetBoolean(path, value);
197 int64 GetInt64Pref(const char* path) const {
198 return profile_->GetPrefs()->GetInt64(path);
200 void SetInt64Pref(const char* path, int64 value) const {
201 profile_->GetPrefs()->SetInt64(path, value);
205 class TestNotificationDelegate : public NotificationDelegate {
207 explicit TestNotificationDelegate(const std::string& id) : id_(id) {}
209 // Overridden from NotificationDelegate:
210 virtual void Display() OVERRIDE {}
211 virtual void Error() OVERRIDE {}
212 virtual void Close(bool by_user) OVERRIDE {}
213 virtual void Click() OVERRIDE {}
214 virtual void ButtonClick(int index) OVERRIDE {}
216 virtual std::string id() const OVERRIDE { return id_; }
218 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE {
223 virtual ~TestNotificationDelegate() {}
225 const std::string id_;
227 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate);
230 void ShowNotification(std::string notification_id,
231 const message_center::NotifierId& notifier_id) const {
232 message_center::RichNotificationData rich_notification_data;
233 rich_notification_data.priority = 0;
234 Notification notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
235 GURL("http://tests.url"),
236 base::UTF8ToUTF16("Title"),
237 base::UTF8ToUTF16("Body"),
239 blink::WebTextDirectionDefault,
241 base::UTF8ToUTF16("Source"),
242 base::UTF8ToUTF16(notification_id),
243 rich_notification_data,
244 new TestNotificationDelegate("TestNotification"));
245 welcome_notification_->ShowWelcomeNotificationIfNecessary(notification);
248 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
249 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
250 scoped_ptr<TestingProfile> profile_;
251 // Weak Ref owned by welcome_notification_
252 WelcomeNotificationDelegate* delegate_;
253 scoped_ptr<ExtensionWelcomeNotification> welcome_notification_;
255 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest);
258 // Show a regular notification. Expect that WelcomeNotification will
259 // not show a welcome notification.
260 TEST_F(ExtensionWelcomeNotificationTest, FirstRunShowRegularNotification) {
261 StartPreferenceSyncing();
262 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
263 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
264 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
266 ShowRegularNotification();
268 EXPECT_EQ(message_center()->add_notification_calls(), 0);
269 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
270 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
271 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
272 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
273 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
276 // Show a Chrome Now notification. Expect that WelcomeNotification will
277 // show a welcome notification.
278 TEST_F(ExtensionWelcomeNotificationTest, FirstRunChromeNowNotification) {
279 StartPreferenceSyncing();
280 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
281 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
282 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
284 ShowChromeNowNotification();
286 EXPECT_EQ(message_center()->add_notification_calls(), 1);
287 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
288 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
289 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
290 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
291 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
294 // Show a Chrome Now notification that was already shown before.
295 TEST_F(ExtensionWelcomeNotificationTest, ShowWelcomeNotificationAgain) {
296 StartPreferenceSyncing();
297 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
298 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
299 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
300 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
302 ShowChromeNowNotification();
304 EXPECT_EQ(message_center()->add_notification_calls(), 1);
305 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
306 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1);
307 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
308 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
309 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
312 // Don't show a welcome notification if it was previously dismissed on another
313 // machine that wrote the synced flag.
314 TEST_F(ExtensionWelcomeNotificationTest,
315 WelcomeNotificationPreviouslyDismissed) {
316 StartPreferenceSyncing();
317 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
318 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
319 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
320 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
322 ShowChromeNowNotification();
324 EXPECT_EQ(message_center()->add_notification_calls(), 0);
325 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
326 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
327 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
328 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
329 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
332 // Don't show a welcome notification if it was previously dismissed on this
334 TEST_F(ExtensionWelcomeNotificationTest,
335 WelcomeNotificationPreviouslyDismissedLocal) {
336 StartPreferenceSyncing();
337 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
338 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
339 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
340 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
342 ShowChromeNowNotification();
344 EXPECT_EQ(message_center()->add_notification_calls(), 0);
345 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
346 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
347 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
348 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
349 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
352 // Don't show a welcome notification if it was previously dismissed with the
353 // local flag and synced flag. This case is possible but rare.
354 TEST_F(ExtensionWelcomeNotificationTest,
355 WelcomeNotificationPreviouslyDismissedSyncedAndLocal) {
356 StartPreferenceSyncing();
357 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
358 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
359 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
360 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
361 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
363 ShowChromeNowNotification();
365 EXPECT_EQ(message_center()->add_notification_calls(), 0);
366 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
367 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
368 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
369 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
370 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
373 // Show a Chrome Now notification and dismiss it.
374 // Expect welcome toast dismissed to be true.
375 TEST_F(ExtensionWelcomeNotificationTest, DismissWelcomeNotification) {
376 StartPreferenceSyncing();
377 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
378 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
379 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
381 ShowChromeNowNotification();
382 message_center()->CloseCurrentNotification();
385 EXPECT_EQ(message_center()->add_notification_calls(), 1);
386 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
387 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
388 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
389 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
390 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
393 // Show a Chrome Now notification and dismiss it via a synced preference change.
394 // Expect welcome toast dismissed to be true.
395 TEST_F(ExtensionWelcomeNotificationTest, SyncedDismissalWelcomeNotification) {
396 StartPreferenceSyncing();
397 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
398 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
399 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
401 ShowChromeNowNotification();
402 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
404 EXPECT_EQ(message_center()->add_notification_calls(), 1);
405 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
406 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
407 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
408 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
409 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
412 // Simulate a delayed preference sync when the welcome notification was
413 // previously dismissed.
414 TEST_F(ExtensionWelcomeNotificationTest,
415 DelayedPreferenceSyncPreviouslyDismissed) {
416 // Show a notification while the preference system is not syncing.
417 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
418 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
419 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
421 ShowChromeNowNotification();
423 EXPECT_EQ(message_center()->add_notification_calls(), 0);
424 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
425 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
426 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
427 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
428 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
430 // Now start the preference syncing with a previously dismissed welcome.
431 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
432 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
433 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
434 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
436 StartPreferenceSyncing();
438 EXPECT_EQ(message_center()->add_notification_calls(), 0);
439 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
440 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
441 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
442 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
443 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
446 // Simulate a delayed preference sync when the welcome notification was
448 TEST_F(ExtensionWelcomeNotificationTest, DelayedPreferenceSyncNeverShown) {
449 // Show a notification while the preference system is not syncing.
450 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
451 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
452 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
454 ShowChromeNowNotification();
456 EXPECT_EQ(message_center()->add_notification_calls(), 0);
457 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
458 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
459 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
460 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
461 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
463 // Now start the preference syncing with the default preference values.
464 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
465 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
466 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
468 StartPreferenceSyncing();
470 EXPECT_EQ(message_center()->add_notification_calls(), 1);
471 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
472 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
473 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
474 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
475 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
478 // Simulate the passage of time when the welcome notification
479 // automatically dismisses.
480 TEST_F(ExtensionWelcomeNotificationTest, TimeExpiredNotification) {
481 StartPreferenceSyncing();
482 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
483 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
484 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
485 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 0);
486 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
488 ShowChromeNowNotification();
490 base::TimeDelta requested_show_time =
491 base::TimeDelta::FromDays(
492 ExtensionWelcomeNotification::kRequestedShowTimeDays);
494 EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U);
495 EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time);
497 EXPECT_EQ(message_center()->add_notification_calls(), 1);
498 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
499 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
500 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
501 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
502 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
504 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
505 (GetStartTime() + requested_show_time).ToInternalValue());
507 SetElapsedTime(requested_show_time);
508 task_runner()->RunPendingTasks();
510 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
511 EXPECT_EQ(message_center()->add_notification_calls(), 1);
512 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
513 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
514 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
515 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
516 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
518 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
519 (GetStartTime() + requested_show_time).ToInternalValue());
522 // Simulate the passage of time after Chrome is closed and the welcome
523 // notification expiration elapses.
524 TEST_F(ExtensionWelcomeNotificationTest, NotificationPreviouslyExpired) {
525 StartPreferenceSyncing();
526 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
527 SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp, 1);
528 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
529 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
530 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
531 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
532 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
534 const base::TimeDelta requested_show_time =
535 base::TimeDelta::FromDays(
536 ExtensionWelcomeNotification::kRequestedShowTimeDays);
537 SetElapsedTime(requested_show_time);
538 ShowChromeNowNotification();
540 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
541 EXPECT_EQ(message_center()->add_notification_calls(), 0);
542 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
543 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
544 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
545 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
546 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
547 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
550 // C++ Readability Review Change Trigger