OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 private: | 109 private: |
110 base::MessageLoop loop_; | 110 base::MessageLoop loop_; |
111 std::unique_ptr<FakeArcBridgeService> service_; | 111 std::unique_ptr<FakeArcBridgeService> service_; |
112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; | 112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; |
113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; | 113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; |
114 std::unique_ptr<MockMessageCenter> message_center_; | 114 std::unique_ptr<MockMessageCenter> message_center_; |
115 | 115 |
116 void SetUp() override { | 116 void SetUp() override { |
117 arc_notifications_instance_.reset(new FakeNotificationsInstance()); | 117 mojom::NotificationsInstancePtr arc_notifications_instance; |
| 118 arc_notifications_instance_.reset( |
| 119 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); |
118 service_.reset(new FakeArcBridgeService()); | 120 service_.reset(new FakeArcBridgeService()); |
119 message_center_.reset(new MockMessageCenter()); | 121 message_center_.reset(new MockMessageCenter()); |
120 | 122 |
121 arc_notification_manager_.reset(new ArcNotificationManager( | 123 arc_notification_manager_.reset(new ArcNotificationManager( |
122 service(), EmptyAccountId(), message_center_.get())); | 124 service(), EmptyAccountId(), message_center_.get())); |
123 | 125 |
124 NotificationsObserver observer; | 126 NotificationsObserver observer; |
125 service_->notifications()->AddObserver(&observer); | 127 service_->notifications()->AddObserver(&observer); |
126 service_->notifications()->SetInstance(arc_notifications_instance_.get()); | 128 service_->OnNotificationsInstanceReady( |
| 129 std::move(arc_notifications_instance)); |
127 | 130 |
128 while (!observer.IsReady()) | 131 while (!observer.IsReady()) |
129 loop_.RunUntilIdle(); | 132 loop_.RunUntilIdle(); |
130 | 133 |
131 service_->notifications()->RemoveObserver(&observer); | 134 service_->notifications()->RemoveObserver(&observer); |
132 } | 135 } |
133 | 136 |
134 void TearDown() override { | 137 void TearDown() override { |
135 arc_notification_manager_.reset(); | 138 arc_notification_manager_.reset(); |
136 message_center_.reset(); | 139 message_center_.reset(); |
(...skipping 20 matching lines...) Expand all Loading... |
157 std::string key = CreateNotification(); | 160 std::string key = CreateNotification(); |
158 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); | 161 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); |
159 | 162 |
160 { | 163 { |
161 message_center::Notification* notification = | 164 message_center::Notification* notification = |
162 *message_center()->GetVisibleNotifications().begin(); | 165 *message_center()->GetVisibleNotifications().begin(); |
163 notification->delegate()->Close(true /* by_user */); | 166 notification->delegate()->Close(true /* by_user */); |
164 // |notification| gets stale here. | 167 // |notification| gets stale here. |
165 } | 168 } |
166 | 169 |
| 170 arc_notifications_instance()->WaitForIncomingMethodCall(); |
| 171 |
167 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); | 172 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); |
168 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); | 173 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); |
169 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, | 174 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, |
170 arc_notifications_instance()->events().at(0).second); | 175 arc_notifications_instance()->events().at(0).second); |
171 } | 176 } |
172 | 177 |
173 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { | 178 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { |
174 service()->SetReady(); | 179 service()->SetReady(); |
175 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 180 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
176 CreateNotificationWithKey("notification1"); | 181 CreateNotificationWithKey("notification1"); |
177 CreateNotificationWithKey("notification2"); | 182 CreateNotificationWithKey("notification2"); |
178 CreateNotificationWithKey("notification3"); | 183 CreateNotificationWithKey("notification3"); |
179 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); | 184 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); |
180 | 185 |
181 arc_notification_manager()->OnInstanceClosed(); | 186 arc_notification_manager()->OnInstanceClosed(); |
182 | 187 |
183 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 188 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
184 } | 189 } |
185 | 190 |
186 } // namespace arc | 191 } // namespace arc |
OLD | NEW |