| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/notifications/notification.h" | 9 #include "chrome/browser/notifications/notification.h" |
| 10 #include "chrome/browser/notifications/notification_ui_manager.h" | 10 #include "chrome/browser/notifications/notification_ui_manager.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 public: | 80 public: |
| 81 StubNotificationUIManager() | 81 StubNotificationUIManager() |
| 82 : notification_(GURL(), GURL(), string16(), string16(), NULL) {} | 82 : notification_(GURL(), GURL(), string16(), string16(), NULL) {} |
| 83 virtual ~StubNotificationUIManager() {} | 83 virtual ~StubNotificationUIManager() {} |
| 84 | 84 |
| 85 // Adds a notification to be displayed. Virtual for unit test override. | 85 // Adds a notification to be displayed. Virtual for unit test override. |
| 86 virtual void Add(const Notification& notification, Profile* profile) | 86 virtual void Add(const Notification& notification, Profile* profile) |
| 87 OVERRIDE { | 87 OVERRIDE { |
| 88 // Make a deep copy of the notification that we can inspect. | 88 // Make a deep copy of the notification that we can inspect. |
| 89 notification_ = notification; | 89 notification_ = notification; |
| 90 profile_ = profile; |
| 90 } | 91 } |
| 91 | 92 |
| 92 // Returns true if any notifications match the supplied ID, either currently | 93 // Returns true if any notifications match the supplied ID, either currently |
| 93 // displayed or in the queue. | 94 // displayed or in the queue. |
| 94 virtual bool DoesIdExist(const std::string& id) OVERRIDE { | 95 virtual bool DoesIdExist(const std::string& id) OVERRIDE { |
| 95 return true; | 96 return true; |
| 96 } | 97 } |
| 97 | 98 |
| 98 // Removes any notifications matching the supplied ID, either currently | 99 // Removes any notifications matching the supplied ID, either currently |
| 99 // displayed or in the queue. Returns true if anything was removed. | 100 // displayed or in the queue. Returns true if anything was removed. |
| 100 virtual bool CancelById(const std::string& notification_id) OVERRIDE { | 101 virtual bool CancelById(const std::string& notification_id) OVERRIDE { |
| 101 return false; | 102 return false; |
| 102 } | 103 } |
| 103 | 104 |
| 105 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( |
| 106 Profile* profile, |
| 107 const GURL& source) OVERRIDE { |
| 108 std::set<std::string> notification_ids; |
| 109 if (source == notification_.origin_url() && |
| 110 profile->IsSameProfile(profile_)) |
| 111 notification_ids.insert(notification_.notification_id()); |
| 112 return notification_ids; |
| 113 } |
| 114 |
| 104 // Removes notifications matching the |source_origin| (which could be an | 115 // Removes notifications matching the |source_origin| (which could be an |
| 105 // extension ID). Returns true if anything was removed. | 116 // extension ID). Returns true if anything was removed. |
| 106 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { | 117 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { |
| 107 return false; | 118 return false; |
| 108 } | 119 } |
| 109 | 120 |
| 110 // Removes notifications matching |profile|. Returns true if any were removed. | 121 // Removes notifications matching |profile|. Returns true if any were removed. |
| 111 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { | 122 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { |
| 112 return false; | 123 return false; |
| 113 } | 124 } |
| 114 | 125 |
| 115 // Cancels all pending notifications and closes anything currently showing. | 126 // Cancels all pending notifications and closes anything currently showing. |
| 116 // Used when the app is terminating. | 127 // Used when the app is terminating. |
| 117 virtual void CancelAll() OVERRIDE {} | 128 virtual void CancelAll() OVERRIDE {} |
| 118 | 129 |
| 119 // Test hook to get the notification so we can check it | 130 // Test hook to get the notification so we can check it |
| 120 const Notification& notification() const { return notification_; } | 131 const Notification& notification() const { return notification_; } |
| 121 | 132 |
| 122 private: | 133 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); | 134 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); |
| 124 Notification notification_; | 135 Notification notification_; |
| 136 Profile* profile_; |
| 125 }; | 137 }; |
| 126 | 138 |
| 127 class SyncedNotificationTest : public testing::Test { | 139 class SyncedNotificationTest : public testing::Test { |
| 128 public: | 140 public: |
| 129 SyncedNotificationTest() {} | 141 SyncedNotificationTest() {} |
| 130 virtual ~SyncedNotificationTest() {} | 142 virtual ~SyncedNotificationTest() {} |
| 131 | 143 |
| 132 // Methods from testing::Test. | 144 // Methods from testing::Test. |
| 133 | 145 |
| 134 virtual void SetUp() OVERRIDE { | 146 virtual void SetUp() OVERRIDE { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 items->Append(item3); | 631 items->Append(item3); |
| 620 expected_fields.Set(message_center::kItemsKey, items); | 632 expected_fields.Set(message_center::kItemsKey, items); |
| 621 | 633 |
| 622 EXPECT_TRUE(expected_fields.Equals(actual_fields)) | 634 EXPECT_TRUE(expected_fields.Equals(actual_fields)) |
| 623 << "Expected: " << expected_fields | 635 << "Expected: " << expected_fields |
| 624 << ", but actual: " << *actual_fields; | 636 << ", but actual: " << *actual_fields; |
| 625 | 637 |
| 626 } | 638 } |
| 627 | 639 |
| 628 // TODO(petewil): Add a test for a notification being read and or deleted. | 640 // TODO(petewil): Add a test for a notification being read and or deleted. |
| OLD | NEW |