| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
| 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 "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 public: | 115 public: |
| 116 StubNotificationUIManager() : notification_(GURL(), GURL(), string16(), | 116 StubNotificationUIManager() : notification_(GURL(), GURL(), string16(), |
| 117 string16(), NULL) {} | 117 string16(), NULL) {} |
| 118 virtual ~StubNotificationUIManager() {} | 118 virtual ~StubNotificationUIManager() {} |
| 119 | 119 |
| 120 // Adds a notification to be displayed. Virtual for unit test override. | 120 // Adds a notification to be displayed. Virtual for unit test override. |
| 121 virtual void Add(const Notification& notification, Profile* profile) | 121 virtual void Add(const Notification& notification, Profile* profile) |
| 122 OVERRIDE { | 122 OVERRIDE { |
| 123 // Make a deep copy of the notification that we can inspect. | 123 // Make a deep copy of the notification that we can inspect. |
| 124 notification_ = notification; | 124 notification_ = notification; |
| 125 profile_ = profile; |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Returns true if any notifications match the supplied ID, either currently | 128 // Returns true if any notifications match the supplied ID, either currently |
| 128 // displayed or in the queue. | 129 // displayed or in the queue. |
| 129 virtual bool DoesIdExist(const std::string& id) OVERRIDE { | 130 virtual bool DoesIdExist(const std::string& id) OVERRIDE { |
| 130 return true; | 131 return true; |
| 131 } | 132 } |
| 132 | 133 |
| 133 // Removes any notifications matching the supplied ID, either currently | 134 // Removes any notifications matching the supplied ID, either currently |
| 134 // displayed or in the queue. Returns true if anything was removed. | 135 // displayed or in the queue. Returns true if anything was removed. |
| 135 virtual bool CancelById(const std::string& notification_id) OVERRIDE { | 136 virtual bool CancelById(const std::string& notification_id) OVERRIDE { |
| 136 return false; | 137 return false; |
| 137 } | 138 } |
| 138 | 139 |
| 140 // Adds the notification_id for each outstanding notification to the set |
| 141 // |notification_ids| (must not be NULL). |
| 142 virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( |
| 143 Profile* profile, |
| 144 const GURL& source) OVERRIDE { |
| 145 std::set<std::string> notification_ids; |
| 146 if (source == notification_.origin_url() && |
| 147 profile->IsSameProfile(profile_)) |
| 148 notification_ids.insert(notification_.notification_id()); |
| 149 return notification_ids; |
| 150 } |
| 151 |
| 139 // Removes notifications matching the |source_origin| (which could be an | 152 // Removes notifications matching the |source_origin| (which could be an |
| 140 // extension ID). Returns true if anything was removed. | 153 // extension ID). Returns true if anything was removed. |
| 141 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { | 154 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { |
| 142 return false; | 155 return false; |
| 143 } | 156 } |
| 144 | 157 |
| 145 // Removes notifications matching |profile|. Returns true if any were removed. | 158 // Removes notifications matching |profile|. Returns true if any were removed. |
| 146 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { | 159 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { |
| 147 return false; | 160 return false; |
| 148 } | 161 } |
| 149 | 162 |
| 150 // Cancels all pending notifications and closes anything currently showing. | 163 // Cancels all pending notifications and closes anything currently showing. |
| 151 // Used when the app is terminating. | 164 // Used when the app is terminating. |
| 152 virtual void CancelAll() OVERRIDE {} | 165 virtual void CancelAll() OVERRIDE {} |
| 153 | 166 |
| 154 // Test hook to get the notification so we can check it | 167 // Test hook to get the notification so we can check it |
| 155 const Notification& notification() const { return notification_; } | 168 const Notification& notification() const { return notification_; } |
| 156 | 169 |
| 157 private: | 170 private: |
| 158 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); | 171 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); |
| 159 Notification notification_; | 172 Notification notification_; |
| 173 Profile* profile_; |
| 160 }; | 174 }; |
| 161 | 175 |
| 162 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed | 176 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed |
| 163 // back up to Sync. | 177 // back up to Sync. |
| 164 class TestChangeProcessor : public syncer::SyncChangeProcessor { | 178 class TestChangeProcessor : public syncer::SyncChangeProcessor { |
| 165 public: | 179 public: |
| 166 TestChangeProcessor() { } | 180 TestChangeProcessor() { } |
| 167 virtual ~TestChangeProcessor() { } | 181 virtual ~TestChangeProcessor() { } |
| 168 | 182 |
| 169 // Store a copy of all the changes passed in so we can examine them later. | 183 // Store a copy of all the changes passed in so we can examine them later. |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 EXPECT_EQ(kTitle2, notification1->GetTitle()); | 768 EXPECT_EQ(kTitle2, notification1->GetTitle()); |
| 755 | 769 |
| 756 // Ensure no new data will be sent to the remote store for notification1. | 770 // Ensure no new data will be sent to the remote store for notification1. |
| 757 EXPECT_EQ(0U, processor()->change_list_size()); | 771 EXPECT_EQ(0U, processor()->change_list_size()); |
| 758 EXPECT_FALSE(processor()->ContainsId(kKey1)); | 772 EXPECT_FALSE(processor()->ContainsId(kKey1)); |
| 759 } | 773 } |
| 760 | 774 |
| 761 // TODO(petewil): There are more tests to add, such as when we add an API | 775 // TODO(petewil): There are more tests to add, such as when we add an API |
| 762 // to allow data entry from the client, we might have a more up to date | 776 // to allow data entry from the client, we might have a more up to date |
| 763 // item on the client than the server, or we might have a merge conflict. | 777 // item on the client than the server, or we might have a merge conflict. |
| OLD | NEW |