Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc

Issue 14767029: Add API function chrome.notifications.getAll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge that caused test error. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 void GetAllIdsByProfileAndSourceOrigin(
143 Profile* profile,
144 const GURL& source,
145 std::set<std::string>* notification_ids) OVERRIDE {
146 DCHECK(notification_ids);
147 if (source == notification_.origin_url() && profile == profile_)
148 notification_ids->insert(notification_.notification_id());
149 }
150
139 // Removes notifications matching the |source_origin| (which could be an 151 // Removes notifications matching the |source_origin| (which could be an
140 // extension ID). Returns true if anything was removed. 152 // extension ID). Returns true if anything was removed.
141 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { 153 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE {
142 return false; 154 return false;
143 } 155 }
144 156
145 // Removes notifications matching |profile|. Returns true if any were removed. 157 // Removes notifications matching |profile|. Returns true if any were removed.
146 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { 158 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE {
147 return false; 159 return false;
148 } 160 }
149 161
150 // Cancels all pending notifications and closes anything currently showing. 162 // Cancels all pending notifications and closes anything currently showing.
151 // Used when the app is terminating. 163 // Used when the app is terminating.
152 virtual void CancelAll() OVERRIDE {} 164 virtual void CancelAll() OVERRIDE {}
153 165
154 // Test hook to get the notification so we can check it 166 // Test hook to get the notification so we can check it
155 const Notification& notification() const { return notification_; } 167 const Notification& notification() const { return notification_; }
156 168
157 private: 169 private:
158 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); 170 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager);
159 Notification notification_; 171 Notification notification_;
172 Profile* profile_;
160 }; 173 };
161 174
162 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed 175 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed
163 // back up to Sync. 176 // back up to Sync.
164 class TestChangeProcessor : public syncer::SyncChangeProcessor { 177 class TestChangeProcessor : public syncer::SyncChangeProcessor {
165 public: 178 public:
166 TestChangeProcessor() { } 179 TestChangeProcessor() { }
167 virtual ~TestChangeProcessor() { } 180 virtual ~TestChangeProcessor() { }
168 181
169 // Store a copy of all the changes passed in so we can examine them later. 182 // 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
754 EXPECT_EQ(kTitle2, notification1->GetTitle()); 767 EXPECT_EQ(kTitle2, notification1->GetTitle());
755 768
756 // Ensure no new data will be sent to the remote store for notification1. 769 // Ensure no new data will be sent to the remote store for notification1.
757 EXPECT_EQ(0U, processor()->change_list_size()); 770 EXPECT_EQ(0U, processor()->change_list_size());
758 EXPECT_FALSE(processor()->ContainsId(kKey1)); 771 EXPECT_FALSE(processor()->ContainsId(kKey1));
759 } 772 }
760 773
761 // TODO(petewil): There are more tests to add, such as when we add an API 774 // 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 775 // 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. 776 // item on the client than the server, or we might have a merge conflict.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698