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> |
| 6 #include <string> |
| 7 #include <vector> |
| 8 |
5 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "components/arc/instance_holder.h" |
7 #include "components/arc/test/fake_arc_bridge_instance.h" | 12 #include "components/arc/test/fake_arc_bridge_instance.h" |
8 #include "components/arc/test/fake_arc_bridge_service.h" | 13 #include "components/arc/test/fake_arc_bridge_service.h" |
9 #include "components/arc/test/fake_notifications_instance.h" | 14 #include "components/arc/test/fake_notifications_instance.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/arc/notification/arc_notification_manager.h" | 16 #include "ui/arc/notification/arc_notification_manager.h" |
12 #include "ui/message_center/fake_message_center.h" | 17 #include "ui/message_center/fake_message_center.h" |
13 | 18 |
14 namespace arc { | 19 namespace arc { |
15 | 20 |
16 namespace { | 21 namespace { |
(...skipping 28 matching lines...) Expand all Loading... |
45 GetVisibleNotifications() override { | 50 GetVisibleNotifications() override { |
46 return visible_notifications_; | 51 return visible_notifications_; |
47 } | 52 } |
48 | 53 |
49 private: | 54 private: |
50 message_center::NotificationList::Notifications visible_notifications_; | 55 message_center::NotificationList::Notifications visible_notifications_; |
51 | 56 |
52 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 57 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
53 }; | 58 }; |
54 | 59 |
55 class ArcBridgeServiceObserver : public ArcBridgeService::Observer { | 60 class NotificationsObserver |
| 61 : public InstanceHolder<mojom::NotificationsInstance>::Observer { |
56 public: | 62 public: |
57 ArcBridgeServiceObserver() = default; | 63 NotificationsObserver() = default; |
58 void OnNotificationsInstanceReady() override { ready_ = true; } | 64 void OnInstanceReady(mojom::NotificationsInstance*, |
| 65 uint32_t version) override { |
| 66 ready_ = true; |
| 67 } |
59 | 68 |
60 bool IsReady() { return ready_; } | 69 bool IsReady() { return ready_; } |
61 | 70 |
62 private: | 71 private: |
63 bool ready_ = false; | 72 bool ready_ = false; |
64 | 73 |
65 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceObserver); | 74 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); |
66 }; | 75 }; |
67 | 76 |
68 } // anonymous namespace | 77 } // anonymous namespace |
69 | 78 |
70 class ArcNotificationManagerTest : public testing::Test { | 79 class ArcNotificationManagerTest : public testing::Test { |
71 public: | 80 public: |
72 ArcNotificationManagerTest() {} | 81 ArcNotificationManagerTest() {} |
73 ~ArcNotificationManagerTest() override { loop_.RunUntilIdle(); } | 82 ~ArcNotificationManagerTest() override { loop_.RunUntilIdle(); } |
74 | 83 |
75 protected: | 84 protected: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void SetUp() override { | 119 void SetUp() override { |
111 mojom::NotificationsInstancePtr arc_notifications_instance; | 120 mojom::NotificationsInstancePtr arc_notifications_instance; |
112 arc_notifications_instance_.reset( | 121 arc_notifications_instance_.reset( |
113 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); | 122 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); |
114 service_.reset(new FakeArcBridgeService()); | 123 service_.reset(new FakeArcBridgeService()); |
115 message_center_.reset(new MockMessageCenter()); | 124 message_center_.reset(new MockMessageCenter()); |
116 | 125 |
117 arc_notification_manager_.reset(new ArcNotificationManager( | 126 arc_notification_manager_.reset(new ArcNotificationManager( |
118 service(), EmptyAccountId(), message_center_.get())); | 127 service(), EmptyAccountId(), message_center_.get())); |
119 | 128 |
120 ArcBridgeServiceObserver observer; | 129 NotificationsObserver observer; |
121 service_->AddObserver(&observer); | 130 service_->notifications()->AddObserver(&observer); |
122 service_->OnNotificationsInstanceReady( | 131 service_->OnNotificationsInstanceReady( |
123 std::move(arc_notifications_instance)); | 132 std::move(arc_notifications_instance)); |
124 | 133 |
125 while (!observer.IsReady()) | 134 while (!observer.IsReady()) |
126 loop_.RunUntilIdle(); | 135 loop_.RunUntilIdle(); |
127 | 136 |
128 service_->RemoveObserver(&observer); | 137 service_->notifications()->RemoveObserver(&observer); |
129 } | 138 } |
130 | 139 |
131 void TearDown() override { | 140 void TearDown() override { |
132 arc_notification_manager_.reset(); | 141 arc_notification_manager_.reset(); |
133 message_center_.reset(); | 142 message_center_.reset(); |
134 service_.reset(); | 143 service_.reset(); |
135 arc_notifications_instance_.reset(); | 144 arc_notifications_instance_.reset(); |
136 } | 145 } |
137 | 146 |
138 DISALLOW_COPY_AND_ASSIGN(ArcNotificationManagerTest); | 147 DISALLOW_COPY_AND_ASSIGN(ArcNotificationManagerTest); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 179 } |
171 | 180 |
172 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { | 181 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { |
173 service()->SetReady(); | 182 service()->SetReady(); |
174 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 183 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
175 CreateNotificationWithKey("notification1"); | 184 CreateNotificationWithKey("notification1"); |
176 CreateNotificationWithKey("notification2"); | 185 CreateNotificationWithKey("notification2"); |
177 CreateNotificationWithKey("notification3"); | 186 CreateNotificationWithKey("notification3"); |
178 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); | 187 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); |
179 | 188 |
180 arc_notification_manager()->OnNotificationsInstanceClosed(); | 189 arc_notification_manager()->OnInstanceClosed(nullptr); |
181 | 190 |
182 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 191 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
183 } | 192 } |
184 | 193 |
185 } // namespace arc | 194 } // namespace arc |
OLD | NEW |