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