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