Add a NavigationThrottle to the public content/ interface
[chromium-blink-merge.git] / chrome / browser / notifications / extension_welcome_notification_unittest.cc
blob85826c3e4cf8336e0764d92c7498b00ef95a5ae9
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/browser/prefs/pref_service_syncable_util.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "components/syncable_prefs/testing_pref_service_syncable.h"
22 #include "sync/api/fake_sync_change_processor.h"
23 #include "sync/api/sync_error_factory_mock.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/message_center/fake_message_center.h"
26 #include "ui/message_center/notification.h"
28 class MockMessageCenter : public message_center::FakeMessageCenter {
29 public:
30 MockMessageCenter()
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 message_center::Notification* FindVisibleNotificationById(
44 const std::string& id) override {
45 if (last_notification.get() && last_notification->id() == id)
46 return last_notification.get();
47 return NULL;
50 void AddNotification(
51 scoped_ptr<message_center::Notification> notification) override {
52 EXPECT_FALSE(last_notification.get());
53 last_notification.swap(notification);
54 add_notification_calls_++;
55 if (last_notification->shown_as_popup())
56 notifications_with_shown_as_popup_++;
59 void RemoveNotification(const std::string& id, bool by_user) override {
60 EXPECT_TRUE(last_notification.get());
61 last_notification.reset();
62 remove_notification_calls_++;
65 void CloseCurrentNotification() {
66 EXPECT_TRUE(last_notification.get());
67 last_notification->delegate()->Close(true);
68 RemoveNotification(last_notification->id(), true);
71 private:
72 scoped_ptr<message_center::Notification> last_notification;
73 int add_notification_calls_;
74 int remove_notification_calls_;
75 int notifications_with_shown_as_popup_;
77 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter);
80 class WelcomeNotificationDelegate
81 : public ExtensionWelcomeNotification::Delegate {
82 public:
83 WelcomeNotificationDelegate()
84 : start_time_(base::Time::Now()),
85 message_center_(new MockMessageCenter()) {
88 // ExtensionWelcomeNotification::Delegate
89 message_center::MessageCenter* GetMessageCenter() override {
90 return message_center_.get();
93 base::Time GetCurrentTime() override { return start_time_ + elapsed_time_; }
95 void PostTask(const tracked_objects::Location& from_here,
96 const base::Closure& task) override {
97 EXPECT_TRUE(pending_task_.is_null());
98 pending_task_ = task;
101 // WelcomeNotificationDelegate
102 MockMessageCenter* message_center() const { return message_center_.get(); }
104 base::Time GetStartTime() const { return start_time_; }
106 void SetElapsedTime(base::TimeDelta elapsed_time) {
107 elapsed_time_ = elapsed_time;
110 void RunPendingTask() {
111 base::Closure task_to_run = pending_task_;
112 pending_task_.Reset();
113 task_to_run.Run();
116 private:
117 const base::Time start_time_;
118 base::TimeDelta elapsed_time_;
119 scoped_ptr<MockMessageCenter> message_center_;
120 base::Closure pending_task_;
122 DISALLOW_COPY_AND_ASSIGN(WelcomeNotificationDelegate);
125 class ExtensionWelcomeNotificationTest : public testing::Test {
126 protected:
127 ExtensionWelcomeNotificationTest() {
128 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
129 new user_prefs::PrefRegistrySyncable());
130 ExtensionWelcomeNotification::RegisterProfilePrefs(pref_registry.get());
133 void SetUp() override {
134 task_runner_ = new base::TestSimpleTaskRunner();
135 thread_task_runner_handle_.reset(
136 new base::ThreadTaskRunnerHandle(task_runner_));
137 profile_.reset(new TestingProfile());
138 delegate_ = new WelcomeNotificationDelegate();
139 welcome_notification_.reset(
140 ExtensionWelcomeNotification::Create(profile_.get(), delegate_));
143 void TearDown() override {
144 delegate_ = NULL;
145 welcome_notification_.reset();
146 profile_.reset();
147 TestingBrowserProcess::DeleteInstance();
148 thread_task_runner_handle_.reset();
149 task_runner_ = NULL;
152 void StartPreferenceSyncing() const {
153 PrefServiceSyncableFromProfile(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 {
164 ShowNotification(
165 "ChromeNowNotification",
166 message_center::NotifierId(
167 message_center::NotifierId::APPLICATION,
168 ExtensionWelcomeNotification::kChromeNowExtensionID));
171 void ShowRegularNotification() const {
172 ShowNotification(
173 "RegularNotification",
174 message_center::NotifierId(message_center::NotifierId::APPLICATION,
175 "aaaabbbbccccddddeeeeffffggghhhhi"));
178 void FlushMessageLoop() { delegate_->RunPendingTask(); }
180 MockMessageCenter* message_center() const {
181 return delegate_->message_center();
183 base::TestSimpleTaskRunner* task_runner() const {
184 return task_runner_.get();
186 base::Time GetStartTime() const {
187 return delegate_->GetStartTime();
189 void SetElapsedTime(base::TimeDelta elapsed_time) const {
190 delegate_->SetElapsedTime(elapsed_time);
192 bool GetBooleanPref(const char* path) const {
193 return profile_->GetPrefs()->GetBoolean(path);
195 void SetBooleanPref(const char* path, bool value) const {
196 profile_->GetPrefs()->SetBoolean(path, value);
198 int64 GetInt64Pref(const char* path) const {
199 return profile_->GetPrefs()->GetInt64(path);
201 void SetInt64Pref(const char* path, int64 value) const {
202 profile_->GetPrefs()->SetInt64(path, value);
205 private:
206 class TestNotificationDelegate : public NotificationDelegate {
207 public:
208 explicit TestNotificationDelegate(const std::string& id) : id_(id) {}
210 // Overridden from NotificationDelegate:
211 std::string id() const override { return id_; }
213 private:
214 ~TestNotificationDelegate() override {}
216 const std::string id_;
218 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate);
221 void ShowNotification(std::string notification_id,
222 const message_center::NotifierId& notifier_id) const {
223 message_center::RichNotificationData rich_notification_data;
224 rich_notification_data.priority = 0;
225 Notification notification(
226 message_center::NOTIFICATION_TYPE_BASE_FORMAT,
227 base::UTF8ToUTF16("Title"), base::UTF8ToUTF16("Body"), gfx::Image(),
228 notifier_id, base::UTF8ToUTF16("Source"), GURL("http://tests.url"),
229 notification_id, rich_notification_data,
230 new TestNotificationDelegate("TestNotification"));
231 welcome_notification_->ShowWelcomeNotificationIfNecessary(notification);
234 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
235 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
236 scoped_ptr<TestingProfile> profile_;
237 // Weak Ref owned by welcome_notification_
238 WelcomeNotificationDelegate* delegate_;
239 scoped_ptr<ExtensionWelcomeNotification> welcome_notification_;
241 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotificationTest);
244 // Show a regular notification. Expect that WelcomeNotification will
245 // not show a welcome notification.
246 TEST_F(ExtensionWelcomeNotificationTest, FirstRunShowRegularNotification) {
247 StartPreferenceSyncing();
248 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
249 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
250 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
252 ShowRegularNotification();
254 EXPECT_EQ(message_center()->add_notification_calls(), 0);
255 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
256 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
257 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
258 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
259 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
262 // Show a Chrome Now notification. Expect that WelcomeNotification will
263 // show a welcome notification.
264 TEST_F(ExtensionWelcomeNotificationTest, FirstRunChromeNowNotification) {
265 StartPreferenceSyncing();
266 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
267 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
268 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
270 ShowChromeNowNotification();
272 EXPECT_EQ(message_center()->add_notification_calls(), 1);
273 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
274 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
275 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
276 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
277 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
280 // Show a Chrome Now notification that was already shown before.
281 TEST_F(ExtensionWelcomeNotificationTest, ShowWelcomeNotificationAgain) {
282 StartPreferenceSyncing();
283 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
284 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
285 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
286 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
288 ShowChromeNowNotification();
290 EXPECT_EQ(message_center()->add_notification_calls(), 1);
291 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
292 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 1);
293 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
294 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
295 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
298 // Don't show a welcome notification if it was previously dismissed on another
299 // machine that wrote the synced flag.
300 TEST_F(ExtensionWelcomeNotificationTest,
301 WelcomeNotificationPreviouslyDismissed) {
302 StartPreferenceSyncing();
303 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
304 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
305 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
306 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
308 ShowChromeNowNotification();
310 EXPECT_EQ(message_center()->add_notification_calls(), 0);
311 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
312 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
313 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
314 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
315 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
318 // Don't show a welcome notification if it was previously dismissed on this
319 // machine.
320 TEST_F(ExtensionWelcomeNotificationTest,
321 WelcomeNotificationPreviouslyDismissedLocal) {
322 StartPreferenceSyncing();
323 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
324 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
325 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
326 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
328 ShowChromeNowNotification();
330 EXPECT_EQ(message_center()->add_notification_calls(), 0);
331 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
332 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
333 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
334 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
335 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
338 // Don't show a welcome notification if it was previously dismissed with the
339 // local flag and synced flag. This case is possible but rare.
340 TEST_F(ExtensionWelcomeNotificationTest,
341 WelcomeNotificationPreviouslyDismissedSyncedAndLocal) {
342 StartPreferenceSyncing();
343 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
344 SetBooleanPref(prefs::kWelcomeNotificationDismissedLocal, true);
345 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
346 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
347 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
349 ShowChromeNowNotification();
351 EXPECT_EQ(message_center()->add_notification_calls(), 0);
352 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
353 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
354 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
355 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
356 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
359 // Show a Chrome Now notification and dismiss it.
360 // Expect welcome toast dismissed to be true.
361 TEST_F(ExtensionWelcomeNotificationTest, DismissWelcomeNotification) {
362 StartPreferenceSyncing();
363 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
364 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
365 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
367 ShowChromeNowNotification();
368 message_center()->CloseCurrentNotification();
369 FlushMessageLoop();
371 EXPECT_EQ(message_center()->add_notification_calls(), 1);
372 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
373 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
374 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
375 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
376 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
379 // Show a Chrome Now notification and dismiss it via a synced preference change.
380 // Expect welcome toast dismissed to be true.
381 TEST_F(ExtensionWelcomeNotificationTest, SyncedDismissalWelcomeNotification) {
382 StartPreferenceSyncing();
383 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
384 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
385 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
387 ShowChromeNowNotification();
388 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
390 EXPECT_EQ(message_center()->add_notification_calls(), 1);
391 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
392 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
393 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
394 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
395 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
398 // Simulate a delayed preference sync when the welcome notification was
399 // previously dismissed.
400 TEST_F(ExtensionWelcomeNotificationTest,
401 DelayedPreferenceSyncPreviouslyDismissed) {
402 // Show a notification while the preference system is not syncing.
403 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
404 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
405 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
407 ShowChromeNowNotification();
409 EXPECT_EQ(message_center()->add_notification_calls(), 0);
410 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
411 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
412 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
413 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
414 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
416 // Now start the preference syncing with a previously dismissed welcome.
417 SetBooleanPref(prefs::kWelcomeNotificationDismissed, true);
418 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
419 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
420 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
422 StartPreferenceSyncing();
424 EXPECT_EQ(message_center()->add_notification_calls(), 0);
425 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
426 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
427 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
428 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
429 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
432 // Simulate a delayed preference sync when the welcome notification was
433 // never shown.
434 TEST_F(ExtensionWelcomeNotificationTest, DelayedPreferenceSyncNeverShown) {
435 // Show a notification while the preference system is not syncing.
436 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
437 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
438 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
440 ShowChromeNowNotification();
442 EXPECT_EQ(message_center()->add_notification_calls(), 0);
443 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
444 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
445 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
446 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
447 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
449 // Now start the preference syncing with the default preference values.
450 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
451 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
452 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
454 StartPreferenceSyncing();
456 EXPECT_EQ(message_center()->add_notification_calls(), 1);
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_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
464 // Simulate the passage of time when the welcome notification
465 // automatically dismisses.
466 TEST_F(ExtensionWelcomeNotificationTest, TimeExpiredNotification) {
467 StartPreferenceSyncing();
468 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
469 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
470 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
471 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 0);
472 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
474 ShowChromeNowNotification();
476 base::TimeDelta requested_show_time =
477 base::TimeDelta::FromDays(
478 ExtensionWelcomeNotification::kRequestedShowTimeDays);
480 EXPECT_EQ(task_runner()->GetPendingTasks().size(), 1U);
481 EXPECT_EQ(task_runner()->NextPendingTaskDelay(), requested_show_time);
483 EXPECT_EQ(message_center()->add_notification_calls(), 1);
484 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
485 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
486 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
487 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
488 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
489 EXPECT_EQ(
490 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
491 (GetStartTime() + requested_show_time).ToInternalValue());
493 SetElapsedTime(requested_show_time);
494 task_runner()->RunPendingTasks();
496 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
497 EXPECT_EQ(message_center()->add_notification_calls(), 1);
498 EXPECT_EQ(message_center()->remove_notification_calls(), 1);
499 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
500 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
501 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
502 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
503 EXPECT_EQ(
504 GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp),
505 (GetStartTime() + requested_show_time).ToInternalValue());
508 // Simulate the passage of time after Chrome is closed and the welcome
509 // notification expiration elapses.
510 TEST_F(ExtensionWelcomeNotificationTest, NotificationPreviouslyExpired) {
511 StartPreferenceSyncing();
512 SetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp, true);
513 SetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp, 1);
514 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
515 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
516 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
517 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);
518 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
520 const base::TimeDelta requested_show_time =
521 base::TimeDelta::FromDays(
522 ExtensionWelcomeNotification::kRequestedShowTimeDays);
523 SetElapsedTime(requested_show_time);
524 ShowChromeNowNotification();
526 EXPECT_TRUE(task_runner()->GetPendingTasks().empty());
527 EXPECT_EQ(message_center()->add_notification_calls(), 0);
528 EXPECT_EQ(message_center()->remove_notification_calls(), 0);
529 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0);
530 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed));
531 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal));
532 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp));
533 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1);