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