| 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() override { ready_ = true; } |
| 59 | 65 |
| 60 bool IsReady() { return ready_; } | 66 bool IsReady() { return ready_; } |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 bool ready_ = false; | 69 bool ready_ = false; |
| 64 | 70 |
| 65 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceObserver); | 71 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); |
| 66 }; | 72 }; |
| 67 | 73 |
| 68 } // anonymous namespace | 74 } // anonymous namespace |
| 69 | 75 |
| 70 class ArcNotificationManagerTest : public testing::Test { | 76 class ArcNotificationManagerTest : public testing::Test { |
| 71 public: | 77 public: |
| 72 ArcNotificationManagerTest() {} | 78 ArcNotificationManagerTest() {} |
| 73 ~ArcNotificationManagerTest() override { loop_.RunUntilIdle(); } | 79 ~ArcNotificationManagerTest() override { loop_.RunUntilIdle(); } |
| 74 | 80 |
| 75 protected: | 81 protected: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void SetUp() override { | 116 void SetUp() override { |
| 111 mojom::NotificationsInstancePtr arc_notifications_instance; | 117 mojom::NotificationsInstancePtr arc_notifications_instance; |
| 112 arc_notifications_instance_.reset( | 118 arc_notifications_instance_.reset( |
| 113 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); | 119 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); |
| 114 service_.reset(new FakeArcBridgeService()); | 120 service_.reset(new FakeArcBridgeService()); |
| 115 message_center_.reset(new MockMessageCenter()); | 121 message_center_.reset(new MockMessageCenter()); |
| 116 | 122 |
| 117 arc_notification_manager_.reset(new ArcNotificationManager( | 123 arc_notification_manager_.reset(new ArcNotificationManager( |
| 118 service(), EmptyAccountId(), message_center_.get())); | 124 service(), EmptyAccountId(), message_center_.get())); |
| 119 | 125 |
| 120 ArcBridgeServiceObserver observer; | 126 NotificationsObserver observer; |
| 121 service_->AddObserver(&observer); | 127 service_->notifications()->AddObserver(&observer); |
| 122 service_->OnNotificationsInstanceReady( | 128 service_->OnNotificationsInstanceReady( |
| 123 std::move(arc_notifications_instance)); | 129 std::move(arc_notifications_instance)); |
| 124 | 130 |
| 125 while (!observer.IsReady()) | 131 while (!observer.IsReady()) |
| 126 loop_.RunUntilIdle(); | 132 loop_.RunUntilIdle(); |
| 127 | 133 |
| 128 service_->RemoveObserver(&observer); | 134 service_->notifications()->RemoveObserver(&observer); |
| 129 } | 135 } |
| 130 | 136 |
| 131 void TearDown() override { | 137 void TearDown() override { |
| 132 arc_notification_manager_.reset(); | 138 arc_notification_manager_.reset(); |
| 133 message_center_.reset(); | 139 message_center_.reset(); |
| 134 service_.reset(); | 140 service_.reset(); |
| 135 arc_notifications_instance_.reset(); | 141 arc_notifications_instance_.reset(); |
| 136 } | 142 } |
| 137 | 143 |
| 138 DISALLOW_COPY_AND_ASSIGN(ArcNotificationManagerTest); | 144 DISALLOW_COPY_AND_ASSIGN(ArcNotificationManagerTest); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 176 } |
| 171 | 177 |
| 172 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { | 178 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { |
| 173 service()->SetReady(); | 179 service()->SetReady(); |
| 174 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 180 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 175 CreateNotificationWithKey("notification1"); | 181 CreateNotificationWithKey("notification1"); |
| 176 CreateNotificationWithKey("notification2"); | 182 CreateNotificationWithKey("notification2"); |
| 177 CreateNotificationWithKey("notification3"); | 183 CreateNotificationWithKey("notification3"); |
| 178 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); | 184 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); |
| 179 | 185 |
| 180 arc_notification_manager()->OnNotificationsInstanceClosed(); | 186 arc_notification_manager()->OnInstanceClosed(); |
| 181 | 187 |
| 182 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 188 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 183 } | 189 } |
| 184 | 190 |
| 185 } // namespace arc | 191 } // namespace arc |
| OLD | NEW |