Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / notifications / extension_welcome_notification_unittest.cc
blob43d9d88386db24f1e4895d50b744e35d8cfcb882
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(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
225 GURL("http://tests.url"),
226 base::UTF8ToUTF16("Title"),
227 base::UTF8ToUTF16("Body"),
228 gfx::Image(),
229 notifier_id,
230 base::UTF8ToUTF16("Source"),
231 notification_id,
232 rich_notification_data,
233 new TestNotificationDelegate("TestNotification"));
234 welcome_notification_->ShowWelcomeNotificationIfNecessary(notification);
237 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
238 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
239 scoped_ptr<TestingProfile> profile_;
240 // Weak Ref owned by welcome_notification_
241 WelcomeNotificationDelegate* delegate_;
242 scoped_ptr<ExtensionWelcomeNotification> welcome_notification_;
244 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest);
247 // Show a regular notification. Expect that WelcomeNotification will
248 // not show a welcome notification.
249 TEST_F(ExtensionWelcomeNotificationTest, FirstRunShowRegularNotification) {
250 StartPreferenceSyncing();
251 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
252 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
253 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
255 ShowRegularNotification();
257 EXPECT_EQ(message_center()->add_notification_calls(), 0);
258 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
259 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
260 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
261 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
262 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
265 // Show a Chrome Now notification. Expect that WelcomeNotification will
266 // show a welcome notification.
267 TEST_F(ExtensionWelcomeNotificationTest, FirstRunChromeNowNotification) {
268 StartPreferenceSyncing();
269 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
270 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
271 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
273 ShowChromeNowNotification();
275 EXPECT_EQ(message_center()->add_notification_calls(), 1);
276 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
277 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
278 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
279 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
280 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
283 // Show a Chrome Now notification that was already shown before.
284 TEST_F(ExtensionWelcomeNotificationTest, ShowWelcomeNotificationAgain) {
285 StartPreferenceSyncing();
286 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
287 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
288 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
289 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
291 ShowChromeNowNotification();
293 EXPECT_EQ(message_center()->add_notification_calls(), 1);
294 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
295 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1);
296 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
297 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
298 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
301 // Don't show a welcome notification if it was previously dismissed on another
302 // machine that wrote the synced flag.
303 TEST_F(ExtensionWelcomeNotificationTest,
304 WelcomeNotificationPreviouslyDismissed) {
305 StartPreferenceSyncing();
306 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
307 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
308 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
309 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
311 ShowChromeNowNotification();
313 EXPECT_EQ(message_center()->add_notification_calls(), 0);
314 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
315 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
316 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
317 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
318 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
321 // Don't show a welcome notification if it was previously dismissed on this
322 // machine.
323 TEST_F(ExtensionWelcomeNotificationTest,
324 WelcomeNotificationPreviouslyDismissedLocal) {
325 StartPreferenceSyncing();
326 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
327 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
328 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
329 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
331 ShowChromeNowNotification();
333 EXPECT_EQ(message_center()->add_notification_calls(), 0);
334 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
335 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
336 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
337 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
338 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
341 // Don't show a welcome notification if it was previously dismissed with the
342 // local flag and synced flag. This case is possible but rare.
343 TEST_F(ExtensionWelcomeNotificationTest,
344 WelcomeNotificationPreviouslyDismissedSyncedAndLocal) {
345 StartPreferenceSyncing();
346 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
347 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
348 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
349 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
350 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
352 ShowChromeNowNotification();
354 EXPECT_EQ(message_center()->add_notification_calls(), 0);
355 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
356 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
357 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
358 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
359 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
362 // Show a Chrome Now notification and dismiss it.
363 // Expect welcome toast dismissed to be true.
364 TEST_F(ExtensionWelcomeNotificationTest, DismissWelcomeNotification) {
365 StartPreferenceSyncing();
366 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
367 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
368 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
370 ShowChromeNowNotification();
371 message_center()->CloseCurrentNotification();
372 FlushMessageLoop();
374 EXPECT_EQ(message_center()->add_notification_calls(), 1);
375 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
376 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
377 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
378 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
379 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
382 // Show a Chrome Now notification and dismiss it via a synced preference change.
383 // Expect welcome toast dismissed to be true.
384 TEST_F(ExtensionWelcomeNotificationTest, SyncedDismissalWelcomeNotification) {
385 StartPreferenceSyncing();
386 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
387 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
388 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
390 ShowChromeNowNotification();
391 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
393 EXPECT_EQ(message_center()->add_notification_calls(), 1);
394 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
395 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
396 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
397 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
398 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
401 // Simulate a delayed preference sync when the welcome notification was
402 // previously dismissed.
403 TEST_F(ExtensionWelcomeNotificationTest,
404 DelayedPreferenceSyncPreviouslyDismissed) {
405 // Show a notification while the preference system is not syncing.
406 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
407 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
408 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
410 ShowChromeNowNotification();
412 EXPECT_EQ(message_center()->add_notification_calls(), 0);
413 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
414 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
415 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
416 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
417 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
419 // Now start the preference syncing with a previously dismissed welcome.
420 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
421 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
422 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
423 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
425 StartPreferenceSyncing();
427 EXPECT_EQ(message_center()->add_notification_calls(), 0);
428 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
429 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
430 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
431 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
432 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
435 // Simulate a delayed preference sync when the welcome notification was
436 // never shown.
437 TEST_F(ExtensionWelcomeNotificationTest, DelayedPreferenceSyncNeverShown) {
438 // Show a notification while the preference system is not syncing.
439 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
440 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
441 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
443 ShowChromeNowNotification();
445 EXPECT_EQ(message_center()->add_notification_calls(), 0);
446 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
447 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
448 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
449 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
450 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
452 // Now start the preference syncing with the default preference values.
453 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
454 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
455 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
457 StartPreferenceSyncing();
459 EXPECT_EQ(message_center()->add_notification_calls(), 1);
460 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
461 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
462 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
463 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
464 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
467 // Simulate the passage of time when the welcome notification
468 // automatically dismisses.
469 TEST_F(ExtensionWelcomeNotificationTest, TimeExpiredNotification) {
470 StartPreferenceSyncing();
471 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
472 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
473 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
474 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 0);
475 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
477 ShowChromeNowNotification();
479 base::TimeDelta requested_show_time =
480 base::TimeDelta::FromDays(
481 ExtensionWelcomeNotification::kRequestedShowTimeDays);
483 EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U);
484 EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time);
486 EXPECT_EQ(message_center()->add_notification_calls(), 1);
487 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
488 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
489 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
490 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
491 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
492 EXPECT_EQ(
493 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
494 (GetStartTime() + requested_show_time).ToInternalValue());
496 SetElapsedTime(requested_show_time);
497 task_runner()->RunPendingTasks();
499 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
500 EXPECT_EQ(message_center()->add_notification_calls(), 1);
501 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
502 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
503 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
504 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
505 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
506 EXPECT_EQ(
507 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
508 (GetStartTime() + requested_show_time).ToInternalValue());
511 // Simulate the passage of time after Chrome is closed and the welcome
512 // notification expiration elapses.
513 TEST_F(ExtensionWelcomeNotificationTest, NotificationPreviouslyExpired) {
514 StartPreferenceSyncing();
515 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
516 SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp, 1);
517 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
518 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
519 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
520 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
521 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
523 const base::TimeDelta requested_show_time =
524 base::TimeDelta::FromDays(
525 ExtensionWelcomeNotification::kRequestedShowTimeDays);
526 SetElapsedTime(requested_show_time);
527 ShowChromeNowNotification();
529 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
530 EXPECT_EQ(message_center()->add_notification_calls(), 0);
531 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
532 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
533 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
534 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
535 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
536 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);