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