Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / notifications / extension_welcome_notification_unittest.cc
bloba396f5fc4e894703b4f6db8267cc5c39ac2f66c8
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"
7 #include <string>
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_browser_process.h"
18 #include "chrome/test/base/testing_pref_service_syncable.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "sync/api/fake_sync_change_processor.h"
22 #include "sync/api/sync_error_factory_mock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/message_center/fake_message_center.h"
25 #include "ui/message_center/notification.h"
27 class MockMessageCenter : public message_center::FakeMessageCenter {
28 public:
29 MockMessageCenter()
30 : add_notification_calls_(0),
31 remove_notification_calls_(0),
32 notifications_with_shown_as_popup_(0) {
35 int add_notification_calls() { return add_notification_calls_; }
36 int remove_notification_calls() { return remove_notification_calls_; }
37 int notifications_with_shown_as_popup() {
38 return notifications_with_shown_as_popup_;
41 // message_center::FakeMessageCenter Overrides
42 message_center::Notification* FindVisibleNotificationById(
43 const std::string& id) override {
44 if (last_notification.get() && last_notification->id() == id)
45 return last_notification.get();
46 return NULL;
49 void AddNotification(
50 scoped_ptr<message_center::Notification> notification) override {
51 EXPECT_FALSE(last_notification.get());
52 last_notification.swap(notification);
53 add_notification_calls_++;
54 if (last_notification->shown_as_popup())
55 notifications_with_shown_as_popup_++;
58 void RemoveNotification(const std::string& id, 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);
70 private:
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 {
81 public:
82 WelcomeNotificationDelegate()
83 : start_time_(base::Time::Now()),
84 message_center_(new MockMessageCenter()) {
87 // ExtensionWelcomeNotification::Delegate
88 message_center::MessageCenter* GetMessageCenter() override {
89 return message_center_.get();
92 base::Time GetCurrentTime() override { return start_time_ + elapsed_time_; }
94 void PostTask(const tracked_objects::Location& from_here,
95 const base::Closure& task) override {
96 EXPECT_TRUE(pending_task_.is_null());
97 pending_task_ = task;
100 // WelcomeNotificationDelegate
101 MockMessageCenter* message_center() const { return message_center_.get(); }
103 base::Time GetStartTime() const { return start_time_; }
105 void SetElapsedTime(base::TimeDelta elapsed_time) {
106 elapsed_time_ = elapsed_time;
109 void RunPendingTask() {
110 base::Closure task_to_run = pending_task_;
111 pending_task_.Reset();
112 task_to_run.Run();
115 private:
116 const base::Time start_time_;
117 base::TimeDelta elapsed_time_;
118 scoped_ptr<MockMessageCenter> message_center_;
119 base::Closure pending_task_;
121 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate);
124 class ExtensionWelcomeNotificationTest : public testing::Test {
125 protected:
126 ExtensionWelcomeNotificationTest() {
127 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
128 new user_prefs::PrefRegistrySyncable());
129 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
132 void SetUp() override {
133 task_runner_ = new base::TestSimpleTaskRunner();
134 thread_task_runner_handle_.reset(
135 new base::ThreadTaskRunnerHandle(task_runner_));
136 profile_.reset(new TestingProfile());
137 delegate_ = new WelcomeNotificationDelegate();
138 welcome_notification_.reset(
139 ExtensionWelcomeNotification::Create(profile_.get(), delegate_));
142 void TearDown() override {
143 delegate_ = NULL;
144 welcome_notification_.reset();
145 profile_.reset();
146 TestingBrowserProcess::DeleteInstance();
147 thread_task_runner_handle_.reset();
148 task_runner_ = NULL;
151 void StartPreferenceSyncing() const {
152 PrefServiceSyncable::FromProfile(profile_.get())
153 ->GetSyncableService(syncer::PREFERENCES)
154 ->MergeDataAndStartSyncing(syncer::PREFERENCES,
155 syncer::SyncDataList(),
156 scoped_ptr<syncer::SyncChangeProcessor>(
157 new syncer::FakeSyncChangeProcessor),
158 scoped_ptr<syncer::SyncErrorFactory>(
159 new syncer::SyncErrorFactoryMock()));
162 void ShowChromeNowNotification() const {
163 ShowNotification(
164 "ChromeNowNotification",
165 message_center::NotifierId(
166 message_center::NotifierId::APPLICATION,
167 ExtensionWelcomeNotification::kChromeNowExtensionID));
170 void ShowRegularNotification() const {
171 ShowNotification(
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);
204 private:
205 class TestNotificationDelegate : public NotificationDelegate {
206 public:
207 explicit TestNotificationDelegate(const std::string& id) : id_(id) {}
209 // Overridden from NotificationDelegate:
210 std::string id() const override { return id_; }
212 private:
213 ~TestNotificationDelegate() override {}
215 const std::string id_;
217 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate);
220 void ShowNotification(std::string notification_id,
221 const message_center::NotifierId& notifier_id) const {
222 message_center::RichNotificationData rich_notification_data;
223 rich_notification_data.priority = 0;
224 Notification notification(
225 message_center::NOTIFICATION_TYPE_BASE_FORMAT,
226 base::UTF8ToUTF16("Title"), base::UTF8ToUTF16("Body"), gfx::Image(),
227 notifier_id, base::UTF8ToUTF16("Source"), GURL("http://tests.url"),
228 notification_id, rich_notification_data,
229 new TestNotificationDelegate("TestNotification"));
230 welcome_notification_->ShowWelcomeNotificationIfNecessary(notification);
233 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
234 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
235 scoped_ptr<TestingProfile> profile_;
236 // Weak Ref owned by welcome_notification_
237 WelcomeNotificationDelegate* delegate_;
238 scoped_ptr<ExtensionWelcomeNotification> welcome_notification_;
240 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest);
243 // Show a regular notification. Expect that WelcomeNotification will
244 // not show a welcome notification.
245 TEST_F(ExtensionWelcomeNotificationTest, FirstRunShowRegularNotification) {
246 StartPreferenceSyncing();
247 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
248 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
249 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
251 ShowRegularNotification();
253 EXPECT_EQ(message_center()->add_notification_calls(), 0);
254 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
255 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
256 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
257 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
258 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
261 // Show a Chrome Now notification. Expect that WelcomeNotification will
262 // show a welcome notification.
263 TEST_F(ExtensionWelcomeNotificationTest, FirstRunChromeNowNotification) {
264 StartPreferenceSyncing();
265 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
266 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
267 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
269 ShowChromeNowNotification();
271 EXPECT_EQ(message_center()->add_notification_calls(), 1);
272 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
273 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
274 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
275 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
276 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
279 // Show a Chrome Now notification that was already shown before.
280 TEST_F(ExtensionWelcomeNotificationTest, ShowWelcomeNotificationAgain) {
281 StartPreferenceSyncing();
282 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
283 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
284 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
285 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
287 ShowChromeNowNotification();
289 EXPECT_EQ(message_center()->add_notification_calls(), 1);
290 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
291 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1);
292 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
293 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
294 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
297 // Don't show a welcome notification if it was previously dismissed on another
298 // machine that wrote the synced flag.
299 TEST_F(ExtensionWelcomeNotificationTest,
300 WelcomeNotificationPreviouslyDismissed) {
301 StartPreferenceSyncing();
302 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
303 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
304 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
305 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
307 ShowChromeNowNotification();
309 EXPECT_EQ(message_center()->add_notification_calls(), 0);
310 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
311 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
312 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
313 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
314 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
317 // Don't show a welcome notification if it was previously dismissed on this
318 // machine.
319 TEST_F(ExtensionWelcomeNotificationTest,
320 WelcomeNotificationPreviouslyDismissedLocal) {
321 StartPreferenceSyncing();
322 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
323 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
324 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
325 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
327 ShowChromeNowNotification();
329 EXPECT_EQ(message_center()->add_notification_calls(), 0);
330 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
331 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
332 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
333 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
334 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
337 // Don't show a welcome notification if it was previously dismissed with the
338 // local flag and synced flag. This case is possible but rare.
339 TEST_F(ExtensionWelcomeNotificationTest,
340 WelcomeNotificationPreviouslyDismissedSyncedAndLocal) {
341 StartPreferenceSyncing();
342 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
343 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
344 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
345 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
346 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
348 ShowChromeNowNotification();
350 EXPECT_EQ(message_center()->add_notification_calls(), 0);
351 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
352 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
353 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
354 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
355 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
358 // Show a Chrome Now notification and dismiss it.
359 // Expect welcome toast dismissed to be true.
360 TEST_F(ExtensionWelcomeNotificationTest, DismissWelcomeNotification) {
361 StartPreferenceSyncing();
362 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
363 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
364 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
366 ShowChromeNowNotification();
367 message_center()->CloseCurrentNotification();
368 FlushMessageLoop();
370 EXPECT_EQ(message_center()->add_notification_calls(), 1);
371 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
372 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
373 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
374 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
375 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
378 // Show a Chrome Now notification and dismiss it via a synced preference change.
379 // Expect welcome toast dismissed to be true.
380 TEST_F(ExtensionWelcomeNotificationTest, SyncedDismissalWelcomeNotification) {
381 StartPreferenceSyncing();
382 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
383 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
384 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
386 ShowChromeNowNotification();
387 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
389 EXPECT_EQ(message_center()->add_notification_calls(), 1);
390 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
391 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
392 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
393 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
394 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
397 // Simulate a delayed preference sync when the welcome notification was
398 // previously dismissed.
399 TEST_F(ExtensionWelcomeNotificationTest,
400 DelayedPreferenceSyncPreviouslyDismissed) {
401 // Show a notification while the preference system is not syncing.
402 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
403 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
404 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
406 ShowChromeNowNotification();
408 EXPECT_EQ(message_center()->add_notification_calls(), 0);
409 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
410 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
411 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
412 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
413 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
415 // Now start the preference syncing with a previously dismissed welcome.
416 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
417 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
418 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
419 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
421 StartPreferenceSyncing();
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_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
427 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
428 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
431 // Simulate a delayed preference sync when the welcome notification was
432 // never shown.
433 TEST_F(ExtensionWelcomeNotificationTest, DelayedPreferenceSyncNeverShown) {
434 // Show a notification while the preference system is not syncing.
435 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
436 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
437 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
439 ShowChromeNowNotification();
441 EXPECT_EQ(message_center()->add_notification_calls(), 0);
442 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
443 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
444 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
445 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
446 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
448 // Now start the preference syncing with the default preference values.
449 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
450 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
451 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
453 StartPreferenceSyncing();
455 EXPECT_EQ(message_center()->add_notification_calls(), 1);
456 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
457 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
458 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
459 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
460 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
463 // Simulate the passage of time when the welcome notification
464 // automatically dismisses.
465 TEST_F(ExtensionWelcomeNotificationTest, TimeExpiredNotification) {
466 StartPreferenceSyncing();
467 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
468 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
469 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
470 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 0);
471 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
473 ShowChromeNowNotification();
475 base::TimeDelta requested_show_time =
476 base::TimeDelta::FromDays(
477 ExtensionWelcomeNotification::kRequestedShowTimeDays);
479 EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U);
480 EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time);
482 EXPECT_EQ(message_center()->add_notification_calls(), 1);
483 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
484 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
485 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
486 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
487 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
488 EXPECT_EQ(
489 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
490 (GetStartTime() + requested_show_time).ToInternalValue());
492 SetElapsedTime(requested_show_time);
493 task_runner()->RunPendingTasks();
495 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
496 EXPECT_EQ(message_center()->add_notification_calls(), 1);
497 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
498 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
499 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
500 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
501 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
502 EXPECT_EQ(
503 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
504 (GetStartTime() + requested_show_time).ToInternalValue());
507 // Simulate the passage of time after Chrome is closed and the welcome
508 // notification expiration elapses.
509 TEST_F(ExtensionWelcomeNotificationTest, NotificationPreviouslyExpired) {
510 StartPreferenceSyncing();
511 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
512 SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp, 1);
513 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
514 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
515 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
516 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
517 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
519 const base::TimeDelta requested_show_time =
520 base::TimeDelta::FromDays(
521 ExtensionWelcomeNotification::kRequestedShowTimeDays);
522 SetElapsedTime(requested_show_time);
523 ShowChromeNowNotification();
525 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
526 EXPECT_EQ(message_center()->add_notification_calls(), 0);
527 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
528 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
529 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
530 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
531 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
532 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);