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/pref_registry/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 class MockMessageCenter
: public message_center::FakeMessageCenter
{
29 : add_notification_calls_(0),
30 remove_notification_calls_(0),
31 notifications_with_shown_as_popup_(0) {
34 int add_notification_calls() { return add_notification_calls_
; }
35 int remove_notification_calls() { return remove_notification_calls_
; }
36 int notifications_with_shown_as_popup() {
37 return notifications_with_shown_as_popup_
;
40 // message_center::FakeMessageCenter Overrides
41 virtual message_center::Notification
* FindVisibleNotificationById(
42 const std::string
& id
) override
{
43 if (last_notification
.get() && last_notification
->id() == id
)
44 return last_notification
.get();
48 virtual void AddNotification(
49 scoped_ptr
<message_center::Notification
> notification
) override
{
50 EXPECT_FALSE(last_notification
.get());
51 last_notification
.swap(notification
);
52 add_notification_calls_
++;
53 if (last_notification
->shown_as_popup())
54 notifications_with_shown_as_popup_
++;
57 virtual void RemoveNotification(const std::string
& id
,
58 bool by_user
) override
{
59 EXPECT_TRUE(last_notification
.get());
60 last_notification
.reset();
61 remove_notification_calls_
++;
64 void CloseCurrentNotification() {
65 EXPECT_TRUE(last_notification
.get());
66 last_notification
->delegate()->Close(true);
67 RemoveNotification(last_notification
->id(), true);
71 scoped_ptr
<message_center::Notification
> last_notification
;
72 int add_notification_calls_
;
73 int remove_notification_calls_
;
74 int notifications_with_shown_as_popup_
;
76 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter
);
79 class WelcomeNotificationDelegate
80 : public ExtensionWelcomeNotification::Delegate
{
82 WelcomeNotificationDelegate()
83 : start_time_(base::Time::Now()),
84 message_center_(new MockMessageCenter()) {
87 // ExtensionWelcomeNotification::Delegate
88 virtual message_center::MessageCenter
* GetMessageCenter() override
{
89 return message_center_
.get();
92 virtual base::Time
GetCurrentTime() override
{
93 return start_time_
+ elapsed_time_
;
96 virtual void PostTask(
97 const tracked_objects::Location
& from_here
,
98 const base::Closure
& task
) override
{
99 EXPECT_TRUE(pending_task_
.is_null());
100 pending_task_
= task
;
103 // WelcomeNotificationDelegate
104 MockMessageCenter
* message_center() const { return message_center_
.get(); }
106 base::Time
GetStartTime() const { return start_time_
; }
108 void SetElapsedTime(base::TimeDelta elapsed_time
) {
109 elapsed_time_
= elapsed_time
;
112 void RunPendingTask() {
113 base::Closure task_to_run
= pending_task_
;
114 pending_task_
.Reset();
119 const base::Time start_time_
;
120 base::TimeDelta elapsed_time_
;
121 scoped_ptr
<MockMessageCenter
> message_center_
;
122 base::Closure pending_task_
;
124 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate
);
127 class ExtensionWelcomeNotificationTest
: public testing::Test
{
129 ExtensionWelcomeNotificationTest() {
130 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry(
131 new user_prefs::PrefRegistrySyncable());
132 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry
.get());
135 virtual void SetUp() {
136 task_runner_
= new base::TestSimpleTaskRunner();
137 thread_task_runner_handle_
.reset(
138 new base::ThreadTaskRunnerHandle(task_runner_
));
139 profile_
.reset(new TestingProfile());
140 delegate_
= new WelcomeNotificationDelegate();
141 welcome_notification_
.reset(
142 ExtensionWelcomeNotification::Create(profile_
.get(), delegate_
));
145 virtual void TearDown() {
147 welcome_notification_
.reset();
149 thread_task_runner_handle_
.reset();
153 void StartPreferenceSyncing() const {
154 PrefServiceSyncable::FromProfile(profile_
.get())
155 ->GetSyncableService(syncer::PREFERENCES
)
156 ->MergeDataAndStartSyncing(syncer::PREFERENCES
,
157 syncer::SyncDataList(),
158 scoped_ptr
<syncer::SyncChangeProcessor
>(
159 new syncer::FakeSyncChangeProcessor
),
160 scoped_ptr
<syncer::SyncErrorFactory
>(
161 new syncer::SyncErrorFactoryMock()));
164 void ShowChromeNowNotification() const {
166 "ChromeNowNotification",
167 message_center::NotifierId(
168 message_center::NotifierId::APPLICATION
,
169 ExtensionWelcomeNotification::kChromeNowExtensionID
));
172 void ShowRegularNotification() const {
174 "RegularNotification",
175 message_center::NotifierId(message_center::NotifierId::APPLICATION
,
176 "aaaabbbbccccddddeeeeffffggghhhhi"));
179 void FlushMessageLoop() { delegate_
->RunPendingTask(); }
181 MockMessageCenter
* message_center() const {
182 return delegate_
->message_center();
184 base::TestSimpleTaskRunner
* task_runner() const {
185 return task_runner_
.get();
187 base::Time
GetStartTime() const {
188 return delegate_
->GetStartTime();
190 void SetElapsedTime(base::TimeDelta elapsed_time
) const {
191 delegate_
->SetElapsedTime(elapsed_time
);
193 bool GetBooleanPref(const char* path
) const {
194 return profile_
->GetPrefs()->GetBoolean(path
);
196 void SetBooleanPref(const char* path
, bool value
) const {
197 profile_
->GetPrefs()->SetBoolean(path
, value
);
199 int64
GetInt64Pref(const char* path
) const {
200 return profile_
->GetPrefs()->GetInt64(path
);
202 void SetInt64Pref(const char* path
, int64 value
) const {
203 profile_
->GetPrefs()->SetInt64(path
, value
);
207 class TestNotificationDelegate
: public NotificationDelegate
{
209 explicit TestNotificationDelegate(const std::string
& id
) : id_(id
) {}
211 // Overridden from NotificationDelegate:
212 virtual void Display() override
{}
213 virtual void Error() override
{}
214 virtual void Close(bool by_user
) override
{}
215 virtual void Click() override
{}
216 virtual void ButtonClick(int index
) override
{}
218 virtual std::string
id() const override
{ return id_
; }
221 virtual ~TestNotificationDelegate() {}
223 const std::string id_
;
225 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate
);
228 void ShowNotification(std::string notification_id
,
229 const message_center::NotifierId
& notifier_id
) const {
230 message_center::RichNotificationData rich_notification_data
;
231 rich_notification_data
.priority
= 0;
232 Notification
notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT
,
233 GURL("http://tests.url"),
234 base::UTF8ToUTF16("Title"),
235 base::UTF8ToUTF16("Body"),
237 blink::WebTextDirectionDefault
,
239 base::UTF8ToUTF16("Source"),
240 base::UTF8ToUTF16(notification_id
),
241 rich_notification_data
,
242 new TestNotificationDelegate("TestNotification"));
243 welcome_notification_
->ShowWelcomeNotificationIfNecessary(notification
);
246 scoped_refptr
<base::TestSimpleTaskRunner
> task_runner_
;
247 scoped_ptr
<base::ThreadTaskRunnerHandle
> thread_task_runner_handle_
;
248 scoped_ptr
<TestingProfile
> profile_
;
249 // Weak Ref owned by welcome_notification_
250 WelcomeNotificationDelegate
* delegate_
;
251 scoped_ptr
<ExtensionWelcomeNotification
> welcome_notification_
;
253 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest
);
256 // Show a regular notification. Expect that WelcomeNotification will
257 // not show a welcome notification.
258 TEST_F(ExtensionWelcomeNotificationTest
, FirstRunShowRegularNotification
) {
259 StartPreferenceSyncing();
260 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
261 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
262 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
264 ShowRegularNotification();
266 EXPECT_EQ(message_center()->add_notification_calls(), 0);
267 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
268 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
269 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
270 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
271 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
274 // Show a Chrome Now notification. Expect that WelcomeNotification will
275 // show a welcome notification.
276 TEST_F(ExtensionWelcomeNotificationTest
, FirstRunChromeNowNotification
) {
277 StartPreferenceSyncing();
278 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
279 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
280 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
282 ShowChromeNowNotification();
284 EXPECT_EQ(message_center()->add_notification_calls(), 1);
285 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
286 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
287 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
288 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
289 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
292 // Show a Chrome Now notification that was already shown before.
293 TEST_F(ExtensionWelcomeNotificationTest
, ShowWelcomeNotificationAgain
) {
294 StartPreferenceSyncing();
295 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
, true);
296 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
297 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
298 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
300 ShowChromeNowNotification();
302 EXPECT_EQ(message_center()->add_notification_calls(), 1);
303 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
304 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1);
305 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
306 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
307 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
310 // Don't show a welcome notification if it was previously dismissed on another
311 // machine that wrote the synced flag.
312 TEST_F(ExtensionWelcomeNotificationTest
,
313 WelcomeNotificationPreviouslyDismissed
) {
314 StartPreferenceSyncing();
315 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
316 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
317 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
318 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
320 ShowChromeNowNotification();
322 EXPECT_EQ(message_center()->add_notification_calls(), 0);
323 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
324 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
325 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
326 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
327 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
330 // Don't show a welcome notification if it was previously dismissed on this
332 TEST_F(ExtensionWelcomeNotificationTest
,
333 WelcomeNotificationPreviouslyDismissedLocal
) {
334 StartPreferenceSyncing();
335 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
, true);
336 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
337 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
338 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
340 ShowChromeNowNotification();
342 EXPECT_EQ(message_center()->add_notification_calls(), 0);
343 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
344 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
345 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
346 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
347 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
350 // Don't show a welcome notification if it was previously dismissed with the
351 // local flag and synced flag. This case is possible but rare.
352 TEST_F(ExtensionWelcomeNotificationTest
,
353 WelcomeNotificationPreviouslyDismissedSyncedAndLocal
) {
354 StartPreferenceSyncing();
355 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
356 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
, true);
357 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
358 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
359 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
361 ShowChromeNowNotification();
363 EXPECT_EQ(message_center()->add_notification_calls(), 0);
364 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
365 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
366 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
367 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
368 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
371 // Show a Chrome Now notification and dismiss it.
372 // Expect welcome toast dismissed to be true.
373 TEST_F(ExtensionWelcomeNotificationTest
, DismissWelcomeNotification
) {
374 StartPreferenceSyncing();
375 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
376 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
377 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
379 ShowChromeNowNotification();
380 message_center()->CloseCurrentNotification();
383 EXPECT_EQ(message_center()->add_notification_calls(), 1);
384 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
385 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
386 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
387 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
388 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
391 // Show a Chrome Now notification and dismiss it via a synced preference change.
392 // Expect welcome toast dismissed to be true.
393 TEST_F(ExtensionWelcomeNotificationTest
, SyncedDismissalWelcomeNotification
) {
394 StartPreferenceSyncing();
395 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
396 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
397 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
399 ShowChromeNowNotification();
400 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
402 EXPECT_EQ(message_center()->add_notification_calls(), 1);
403 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
404 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
405 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
406 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
407 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
410 // Simulate a delayed preference sync when the welcome notification was
411 // previously dismissed.
412 TEST_F(ExtensionWelcomeNotificationTest
,
413 DelayedPreferenceSyncPreviouslyDismissed
) {
414 // Show a notification while the preference system is not syncing.
415 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
416 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
417 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
419 ShowChromeNowNotification();
421 EXPECT_EQ(message_center()->add_notification_calls(), 0);
422 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
423 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
424 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
425 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
426 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
428 // Now start the preference syncing with a previously dismissed welcome.
429 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
430 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
431 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
432 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
434 StartPreferenceSyncing();
436 EXPECT_EQ(message_center()->add_notification_calls(), 0);
437 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
438 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
439 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
440 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
441 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
444 // Simulate a delayed preference sync when the welcome notification was
446 TEST_F(ExtensionWelcomeNotificationTest
, DelayedPreferenceSyncNeverShown
) {
447 // Show a notification while the preference system is not syncing.
448 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
449 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
450 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
452 ShowChromeNowNotification();
454 EXPECT_EQ(message_center()->add_notification_calls(), 0);
455 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
456 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
457 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
458 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
459 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
461 // Now start the preference syncing with the default preference values.
462 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
463 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
464 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
466 StartPreferenceSyncing();
468 EXPECT_EQ(message_center()->add_notification_calls(), 1);
469 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
470 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
471 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
472 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
473 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
476 // Simulate the passage of time when the welcome notification
477 // automatically dismisses.
478 TEST_F(ExtensionWelcomeNotificationTest
, TimeExpiredNotification
) {
479 StartPreferenceSyncing();
480 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
481 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
482 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
483 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
), 0);
484 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
486 ShowChromeNowNotification();
488 base::TimeDelta requested_show_time
=
489 base::TimeDelta::FromDays(
490 ExtensionWelcomeNotification::kRequestedShowTimeDays
);
492 EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U);
493 EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time
);
495 EXPECT_EQ(message_center()->add_notification_calls(), 1);
496 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
497 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
498 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
499 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
500 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
502 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
),
503 (GetStartTime() + requested_show_time
).ToInternalValue());
505 SetElapsedTime(requested_show_time
);
506 task_runner()->RunPendingTasks();
508 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
509 EXPECT_EQ(message_center()->add_notification_calls(), 1);
510 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
511 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
512 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
513 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
514 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
516 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
),
517 (GetStartTime() + requested_show_time
).ToInternalValue());
520 // Simulate the passage of time after Chrome is closed and the welcome
521 // notification expiration elapses.
522 TEST_F(ExtensionWelcomeNotificationTest
, NotificationPreviouslyExpired
) {
523 StartPreferenceSyncing();
524 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
, true);
525 SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
, 1);
526 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
527 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
528 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
529 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
), 1);
530 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
532 const base::TimeDelta requested_show_time
=
533 base::TimeDelta::FromDays(
534 ExtensionWelcomeNotification::kRequestedShowTimeDays
);
535 SetElapsedTime(requested_show_time
);
536 ShowChromeNowNotification();
538 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
539 EXPECT_EQ(message_center()->add_notification_calls(), 0);
540 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
541 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
542 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
543 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
544 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
545 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
), 1);