| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/notifications/extension_welcome_notification.h" | 5 #include "chrome/browser/notifications/extension_welcome_notification.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 notifications_with_shown_as_popup_(0) { | 31 notifications_with_shown_as_popup_(0) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 int add_notification_calls() { return add_notification_calls_; } | 34 int add_notification_calls() { return add_notification_calls_; } |
| 35 int remove_notification_calls() { return remove_notification_calls_; } | 35 int remove_notification_calls() { return remove_notification_calls_; } |
| 36 int notifications_with_shown_as_popup() { | 36 int notifications_with_shown_as_popup() { |
| 37 return notifications_with_shown_as_popup_; | 37 return notifications_with_shown_as_popup_; |
| 38 } | 38 } |
| 39 | 39 |
| 40 // message_center::FakeMessageCenter Overrides | 40 // message_center::FakeMessageCenter Overrides |
| 41 virtual message_center::Notification* FindVisibleNotificationById( | 41 message_center::Notification* FindVisibleNotificationById( |
| 42 const std::string& id) override { | 42 const std::string& id) override { |
| 43 if (last_notification.get() && last_notification->id() == id) | 43 if (last_notification.get() && last_notification->id() == id) |
| 44 return last_notification.get(); | 44 return last_notification.get(); |
| 45 return NULL; | 45 return NULL; |
| 46 } | 46 } |
| 47 | 47 |
| 48 virtual void AddNotification( | 48 void AddNotification( |
| 49 scoped_ptr<message_center::Notification> notification) override { | 49 scoped_ptr<message_center::Notification> notification) override { |
| 50 EXPECT_FALSE(last_notification.get()); | 50 EXPECT_FALSE(last_notification.get()); |
| 51 last_notification.swap(notification); | 51 last_notification.swap(notification); |
| 52 add_notification_calls_++; | 52 add_notification_calls_++; |
| 53 if (last_notification->shown_as_popup()) | 53 if (last_notification->shown_as_popup()) |
| 54 notifications_with_shown_as_popup_++; | 54 notifications_with_shown_as_popup_++; |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual void RemoveNotification(const std::string& id, | 57 void RemoveNotification(const std::string& id, bool by_user) override { |
| 58 bool by_user) override { | |
| 59 EXPECT_TRUE(last_notification.get()); | 58 EXPECT_TRUE(last_notification.get()); |
| 60 last_notification.reset(); | 59 last_notification.reset(); |
| 61 remove_notification_calls_++; | 60 remove_notification_calls_++; |
| 62 } | 61 } |
| 63 | 62 |
| 64 void CloseCurrentNotification() { | 63 void CloseCurrentNotification() { |
| 65 EXPECT_TRUE(last_notification.get()); | 64 EXPECT_TRUE(last_notification.get()); |
| 66 last_notification->delegate()->Close(true); | 65 last_notification->delegate()->Close(true); |
| 67 RemoveNotification(last_notification->id(), true); | 66 RemoveNotification(last_notification->id(), true); |
| 68 } | 67 } |
| 69 | 68 |
| 70 private: | 69 private: |
| 71 scoped_ptr<message_center::Notification> last_notification; | 70 scoped_ptr<message_center::Notification> last_notification; |
| 72 int add_notification_calls_; | 71 int add_notification_calls_; |
| 73 int remove_notification_calls_; | 72 int remove_notification_calls_; |
| 74 int notifications_with_shown_as_popup_; | 73 int notifications_with_shown_as_popup_; |
| 75 | 74 |
| 76 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 75 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
| 77 }; | 76 }; |
| 78 | 77 |
| 79 class WelcomeNotificationDelegate | 78 class WelcomeNotificationDelegate |
| 80 : public ExtensionWelcomeNotification::Delegate { | 79 : public ExtensionWelcomeNotification::Delegate { |
| 81 public: | 80 public: |
| 82 WelcomeNotificationDelegate() | 81 WelcomeNotificationDelegate() |
| 83 : start_time_(base::Time::Now()), | 82 : start_time_(base::Time::Now()), |
| 84 message_center_(new MockMessageCenter()) { | 83 message_center_(new MockMessageCenter()) { |
| 85 } | 84 } |
| 86 | 85 |
| 87 // ExtensionWelcomeNotification::Delegate | 86 // ExtensionWelcomeNotification::Delegate |
| 88 virtual message_center::MessageCenter* GetMessageCenter() override { | 87 message_center::MessageCenter* GetMessageCenter() override { |
| 89 return message_center_.get(); | 88 return message_center_.get(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 virtual base::Time GetCurrentTime() override { | 91 base::Time GetCurrentTime() override { return start_time_ + elapsed_time_; } |
| 93 return start_time_ + elapsed_time_; | |
| 94 } | |
| 95 | 92 |
| 96 virtual void PostTask( | 93 void PostTask(const tracked_objects::Location& from_here, |
| 97 const tracked_objects::Location& from_here, | 94 const base::Closure& task) override { |
| 98 const base::Closure& task) override { | |
| 99 EXPECT_TRUE(pending_task_.is_null()); | 95 EXPECT_TRUE(pending_task_.is_null()); |
| 100 pending_task_ = task; | 96 pending_task_ = task; |
| 101 } | 97 } |
| 102 | 98 |
| 103 // WelcomeNotificationDelegate | 99 // WelcomeNotificationDelegate |
| 104 MockMessageCenter* message_center() const { return message_center_.get(); } | 100 MockMessageCenter* message_center() const { return message_center_.get(); } |
| 105 | 101 |
| 106 base::Time GetStartTime() const { return start_time_; } | 102 base::Time GetStartTime() const { return start_time_; } |
| 107 | 103 |
| 108 void SetElapsedTime(base::TimeDelta elapsed_time) { | 104 void SetElapsedTime(base::TimeDelta elapsed_time) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 void SetInt64Pref(const char* path, int64 value) const { | 198 void SetInt64Pref(const char* path, int64 value) const { |
| 203 profile_->GetPrefs()->SetInt64(path, value); | 199 profile_->GetPrefs()->SetInt64(path, value); |
| 204 } | 200 } |
| 205 | 201 |
| 206 private: | 202 private: |
| 207 class TestNotificationDelegate : public NotificationDelegate { | 203 class TestNotificationDelegate : public NotificationDelegate { |
| 208 public: | 204 public: |
| 209 explicit TestNotificationDelegate(const std::string& id) : id_(id) {} | 205 explicit TestNotificationDelegate(const std::string& id) : id_(id) {} |
| 210 | 206 |
| 211 // Overridden from NotificationDelegate: | 207 // Overridden from NotificationDelegate: |
| 212 virtual void Display() override {} | 208 void Display() override {} |
| 213 virtual void Error() override {} | 209 void Error() override {} |
| 214 virtual void Close(bool by_user) override {} | 210 void Close(bool by_user) override {} |
| 215 virtual void Click() override {} | 211 void Click() override {} |
| 216 virtual void ButtonClick(int index) override {} | 212 void ButtonClick(int index) override {} |
| 217 | 213 |
| 218 virtual std::string id() const override { return id_; } | 214 std::string id() const override { return id_; } |
| 219 | 215 |
| 220 private: | 216 private: |
| 221 virtual ~TestNotificationDelegate() {} | 217 ~TestNotificationDelegate() override {} |
| 222 | 218 |
| 223 const std::string id_; | 219 const std::string id_; |
| 224 | 220 |
| 225 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); | 221 DISALLOW_COPY_AND_ASSIGN(TestNotificationDelegate); |
| 226 }; | 222 }; |
| 227 | 223 |
| 228 void ShowNotification(std::string notification_id, | 224 void ShowNotification(std::string notification_id, |
| 229 const message_center::NotifierId& notifier_id) const { | 225 const message_center::NotifierId& notifier_id) const { |
| 230 message_center::RichNotificationData rich_notification_data; | 226 message_center::RichNotificationData rich_notification_data; |
| 231 rich_notification_data.priority = 0; | 227 rich_notification_data.priority = 0; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 533 |
| 538 EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); | 534 EXPECT_TRUE(task_runner()->GetPendingTasks().empty()); |
| 539 EXPECT_EQ(message_center()->add_notification_calls(), 0); | 535 EXPECT_EQ(message_center()->add_notification_calls(), 0); |
| 540 EXPECT_EQ(message_center()->remove_notification_calls(), 0); | 536 EXPECT_EQ(message_center()->remove_notification_calls(), 0); |
| 541 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); | 537 EXPECT_EQ(message_center()->notifications_with_shown_as_popup(), 0); |
| 542 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); | 538 EXPECT_FALSE(GetBooleanPref(prefs::kWelcomeNotificationDismissed)); |
| 543 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); | 539 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationDismissedLocal)); |
| 544 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); | 540 EXPECT_TRUE(GetBooleanPref(prefs::kWelcomeNotificationPreviouslyPoppedUp)); |
| 545 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); | 541 EXPECT_EQ(GetInt64Pref(prefs::kWelcomeNotificationExpirationTimestamp), 1); |
| 546 } | 542 } |
| OLD | NEW |