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