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 message_center::Notification
* FindVisibleNotificationById(
42 const std::string
& id
) override
{
43 if (last_notification
.get() && last_notification
->id() == id
)
44 return last_notification
.get();
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 void RemoveNotification(const std::string
& id
, 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 message_center::MessageCenter
* GetMessageCenter() override
{
88 return message_center_
.get();
91 base::Time
GetCurrentTime() override
{ return start_time_
+ elapsed_time_
; }
93 void PostTask(const tracked_objects::Location
& from_here
,
94 const base::Closure
& task
) override
{
95 EXPECT_TRUE(pending_task_
.is_null());
99 // WelcomeNotificationDelegate
100 MockMessageCenter
* message_center() const { return message_center_
.get(); }
102 base::Time
GetStartTime() const { return start_time_
; }
104 void SetElapsedTime(base::TimeDelta elapsed_time
) {
105 elapsed_time_
= elapsed_time
;
108 void RunPendingTask() {
109 base::Closure task_to_run
= pending_task_
;
110 pending_task_
.Reset();
115 const base::Time start_time_
;
116 base::TimeDelta elapsed_time_
;
117 scoped_ptr
<MockMessageCenter
> message_center_
;
118 base::Closure pending_task_
;
120 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate
);
123 class ExtensionWelcomeNotificationTest
: public testing::Test
{
125 ExtensionWelcomeNotificationTest() {
126 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry(
127 new user_prefs::PrefRegistrySyncable());
128 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry
.get());
131 void SetUp() override
{
132 task_runner_
= new base::TestSimpleTaskRunner();
133 thread_task_runner_handle_
.reset(
134 new base::ThreadTaskRunnerHandle(task_runner_
));
135 profile_
.reset(new TestingProfile());
136 delegate_
= new WelcomeNotificationDelegate();
137 welcome_notification_
.reset(
138 ExtensionWelcomeNotification::Create(profile_
.get(), delegate_
));
141 void TearDown() override
{
143 welcome_notification_
.reset();
145 thread_task_runner_handle_
.reset();
149 void StartPreferenceSyncing() const {
150 PrefServiceSyncable::FromProfile(profile_
.get())
151 ->GetSyncableService(syncer::PREFERENCES
)
152 ->MergeDataAndStartSyncing(syncer::PREFERENCES
,
153 syncer::SyncDataList(),
154 scoped_ptr
<syncer::SyncChangeProcessor
>(
155 new syncer::FakeSyncChangeProcessor
),
156 scoped_ptr
<syncer::SyncErrorFactory
>(
157 new syncer::SyncErrorFactoryMock()));
160 void ShowChromeNowNotification() const {
162 "ChromeNowNotification",
163 message_center::NotifierId(
164 message_center::NotifierId::APPLICATION
,
165 ExtensionWelcomeNotification::kChromeNowExtensionID
));
168 void ShowRegularNotification() const {
170 "RegularNotification",
171 message_center::NotifierId(message_center::NotifierId::APPLICATION
,
172 "aaaabbbbccccddddeeeeffffggghhhhi"));
175 void FlushMessageLoop() { delegate_
->RunPendingTask(); }
177 MockMessageCenter
* message_center() const {
178 return delegate_
->message_center();
180 base::TestSimpleTaskRunner
* task_runner() const {
181 return task_runner_
.get();
183 base::Time
GetStartTime() const {
184 return delegate_
->GetStartTime();
186 void SetElapsedTime(base::TimeDelta elapsed_time
) const {
187 delegate_
->SetElapsedTime(elapsed_time
);
189 bool GetBooleanPref(const char* path
) const {
190 return profile_
->GetPrefs()->GetBoolean(path
);
192 void SetBooleanPref(const char* path
, bool value
) const {
193 profile_
->GetPrefs()->SetBoolean(path
, value
);
195 int64
GetInt64Pref(const char* path
) const {
196 return profile_
->GetPrefs()->GetInt64(path
);
198 void SetInt64Pref(const char* path
, int64 value
) const {
199 profile_
->GetPrefs()->SetInt64(path
, value
);
203 class TestNotificationDelegate
: public NotificationDelegate
{
205 explicit TestNotificationDelegate(const std::string
& id
) : id_(id
) {}
207 // Overridden from NotificationDelegate:
208 std::string
id() const override
{ return id_
; }
211 ~TestNotificationDelegate() override
{}
213 const std::string id_
;
215 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate
);
218 void ShowNotification(std::string notification_id
,
219 const message_center::NotifierId
& notifier_id
) const {
220 message_center::RichNotificationData rich_notification_data
;
221 rich_notification_data
.priority
= 0;
222 Notification
notification(message_center::NOTIFICATION_TYPE_BASE_FORMAT
,
223 GURL("http://tests.url"),
224 base::UTF8ToUTF16("Title"),
225 base::UTF8ToUTF16("Body"),
228 base::UTF8ToUTF16("Source"),
230 rich_notification_data
,
231 new TestNotificationDelegate("TestNotification"));
232 welcome_notification_
->ShowWelcomeNotificationIfNecessary(notification
);
235 scoped_refptr
<base::TestSimpleTaskRunner
> task_runner_
;
236 scoped_ptr
<base::ThreadTaskRunnerHandle
> thread_task_runner_handle_
;
237 scoped_ptr
<TestingProfile
> profile_
;
238 // Weak Ref owned by welcome_notification_
239 WelcomeNotificationDelegate
* delegate_
;
240 scoped_ptr
<ExtensionWelcomeNotification
> welcome_notification_
;
242 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest
);
245 // Show a regular notification. Expect that WelcomeNotification will
246 // not show a welcome notification.
247 TEST_F(ExtensionWelcomeNotificationTest
, FirstRunShowRegularNotification
) {
248 StartPreferenceSyncing();
249 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
250 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
251 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
253 ShowRegularNotification();
255 EXPECT_EQ(message_center()->add_notification_calls(), 0);
256 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
257 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
258 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
259 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
260 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
263 // Show a Chrome Now notification. Expect that WelcomeNotification will
264 // show a welcome notification.
265 TEST_F(ExtensionWelcomeNotificationTest
, FirstRunChromeNowNotification
) {
266 StartPreferenceSyncing();
267 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
268 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
269 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
271 ShowChromeNowNotification();
273 EXPECT_EQ(message_center()->add_notification_calls(), 1);
274 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
275 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
276 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
277 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
278 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
281 // Show a Chrome Now notification that was already shown before.
282 TEST_F(ExtensionWelcomeNotificationTest
, ShowWelcomeNotificationAgain
) {
283 StartPreferenceSyncing();
284 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
, true);
285 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
286 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
287 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
289 ShowChromeNowNotification();
291 EXPECT_EQ(message_center()->add_notification_calls(), 1);
292 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
293 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1);
294 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
295 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
296 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
299 // Don't show a welcome notification if it was previously dismissed on another
300 // machine that wrote the synced flag.
301 TEST_F(ExtensionWelcomeNotificationTest
,
302 WelcomeNotificationPreviouslyDismissed
) {
303 StartPreferenceSyncing();
304 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
305 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
306 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
307 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
309 ShowChromeNowNotification();
311 EXPECT_EQ(message_center()->add_notification_calls(), 0);
312 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
313 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
314 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
315 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
316 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
319 // Don't show a welcome notification if it was previously dismissed on this
321 TEST_F(ExtensionWelcomeNotificationTest
,
322 WelcomeNotificationPreviouslyDismissedLocal
) {
323 StartPreferenceSyncing();
324 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
, true);
325 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
326 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
327 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
329 ShowChromeNowNotification();
331 EXPECT_EQ(message_center()->add_notification_calls(), 0);
332 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
333 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
334 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
335 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
336 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
339 // Don't show a welcome notification if it was previously dismissed with the
340 // local flag and synced flag. This case is possible but rare.
341 TEST_F(ExtensionWelcomeNotificationTest
,
342 WelcomeNotificationPreviouslyDismissedSyncedAndLocal
) {
343 StartPreferenceSyncing();
344 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
345 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
, true);
346 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
347 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
348 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
350 ShowChromeNowNotification();
352 EXPECT_EQ(message_center()->add_notification_calls(), 0);
353 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
354 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
355 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
356 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
357 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
360 // Show a Chrome Now notification and dismiss it.
361 // Expect welcome toast dismissed to be true.
362 TEST_F(ExtensionWelcomeNotificationTest
, DismissWelcomeNotification
) {
363 StartPreferenceSyncing();
364 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
365 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
366 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
368 ShowChromeNowNotification();
369 message_center()->CloseCurrentNotification();
372 EXPECT_EQ(message_center()->add_notification_calls(), 1);
373 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
374 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
375 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
376 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
377 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
380 // Show a Chrome Now notification and dismiss it via a synced preference change.
381 // Expect welcome toast dismissed to be true.
382 TEST_F(ExtensionWelcomeNotificationTest
, SyncedDismissalWelcomeNotification
) {
383 StartPreferenceSyncing();
384 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
385 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
386 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
388 ShowChromeNowNotification();
389 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
391 EXPECT_EQ(message_center()->add_notification_calls(), 1);
392 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
393 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
394 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
395 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
396 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
399 // Simulate a delayed preference sync when the welcome notification was
400 // previously dismissed.
401 TEST_F(ExtensionWelcomeNotificationTest
,
402 DelayedPreferenceSyncPreviouslyDismissed
) {
403 // Show a notification while the preference system is not syncing.
404 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
405 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
406 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
408 ShowChromeNowNotification();
410 EXPECT_EQ(message_center()->add_notification_calls(), 0);
411 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
412 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
413 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
414 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
415 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
417 // Now start the preference syncing with a previously dismissed welcome.
418 SetBooleanPref(prefs::kWelcomeNotificationDismissed
, true);
419 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
420 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
421 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
423 StartPreferenceSyncing();
425 EXPECT_EQ(message_center()->add_notification_calls(), 0);
426 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
427 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
428 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
429 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
430 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
433 // Simulate a delayed preference sync when the welcome notification was
435 TEST_F(ExtensionWelcomeNotificationTest
, DelayedPreferenceSyncNeverShown
) {
436 // Show a notification while the preference system is not syncing.
437 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
438 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
439 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
441 ShowChromeNowNotification();
443 EXPECT_EQ(message_center()->add_notification_calls(), 0);
444 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
445 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
446 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
447 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
448 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
450 // Now start the preference syncing with the default preference values.
451 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
452 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
453 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
455 StartPreferenceSyncing();
457 EXPECT_EQ(message_center()->add_notification_calls(), 1);
458 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
459 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
460 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
461 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
462 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
465 // Simulate the passage of time when the welcome notification
466 // automatically dismisses.
467 TEST_F(ExtensionWelcomeNotificationTest
, TimeExpiredNotification
) {
468 StartPreferenceSyncing();
469 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
470 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
471 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
472 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
), 0);
473 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
475 ShowChromeNowNotification();
477 base::TimeDelta requested_show_time
=
478 base::TimeDelta::FromDays(
479 ExtensionWelcomeNotification::kRequestedShowTimeDays
);
481 EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U);
482 EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time
);
484 EXPECT_EQ(message_center()->add_notification_calls(), 1);
485 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
486 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
487 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
488 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
489 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
491 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
),
492 (GetStartTime() + requested_show_time
).ToInternalValue());
494 SetElapsedTime(requested_show_time
);
495 task_runner()->RunPendingTasks();
497 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
498 EXPECT_EQ(message_center()->add_notification_calls(), 1);
499 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
500 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
501 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
502 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
503 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
505 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
),
506 (GetStartTime() + requested_show_time
).ToInternalValue());
509 // Simulate the passage of time after Chrome is closed and the welcome
510 // notification expiration elapses.
511 TEST_F(ExtensionWelcomeNotificationTest
, NotificationPreviouslyExpired
) {
512 StartPreferenceSyncing();
513 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
, true);
514 SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
, 1);
515 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
516 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
517 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
518 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
), 1);
519 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
521 const base::TimeDelta requested_show_time
=
522 base::TimeDelta::FromDays(
523 ExtensionWelcomeNotification::kRequestedShowTimeDays
);
524 SetElapsedTime(requested_show_time
);
525 ShowChromeNowNotification();
527 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
528 EXPECT_EQ(message_center()->add_notification_calls(), 0);
529 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
530 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
531 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed
));
532 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal
));
533 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp
));
534 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp
), 1);