| 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 <map> | 5 #include <map> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // anonymous namespace | 75 } // anonymous namespace |
| 76 | 76 |
| 77 class ArcNotificationManagerTest : public testing::Test { | 77 class ArcNotificationManagerTest : public testing::Test { |
| 78 public: | 78 public: |
| 79 ArcNotificationManagerTest() {} | 79 ArcNotificationManagerTest() {} |
| 80 ~ArcNotificationManagerTest() override { base::RunLoop().RunUntilIdle(); } | 80 ~ArcNotificationManagerTest() override { base::RunLoop().RunUntilIdle(); } |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 FakeArcBridgeService* service() { return service_.get(); } | |
| 84 FakeNotificationsInstance* arc_notifications_instance() { | 83 FakeNotificationsInstance* arc_notifications_instance() { |
| 85 return arc_notifications_instance_.get(); | 84 return arc_notifications_instance_.get(); |
| 86 } | 85 } |
| 87 ArcNotificationManager* arc_notification_manager() { | 86 ArcNotificationManager* arc_notification_manager() { |
| 88 return arc_notification_manager_.get(); | 87 return arc_notification_manager_.get(); |
| 89 } | 88 } |
| 90 MockMessageCenter* message_center() { return message_center_.get(); } | 89 MockMessageCenter* message_center() { return message_center_.get(); } |
| 91 | 90 |
| 92 std::string CreateNotification() { | 91 std::string CreateNotification() { |
| 93 return CreateNotificationWithKey(kDummyNotificationKey); | 92 return CreateNotificationWithKey(kDummyNotificationKey); |
| 94 } | 93 } |
| 95 | 94 |
| 96 std::string CreateNotificationWithKey(const std::string& key) { | 95 std::string CreateNotificationWithKey(const std::string& key) { |
| 97 auto data = mojom::ArcNotificationData::New(); | 96 auto data = mojom::ArcNotificationData::New(); |
| 98 data->key = key; | 97 data->key = key; |
| 99 data->title = "TITLE"; | 98 data->title = "TITLE"; |
| 100 data->message = "MESSAGE"; | 99 data->message = "MESSAGE"; |
| 101 | 100 |
| 102 std::vector<unsigned char> icon_data; | 101 std::vector<unsigned char> icon_data; |
| 103 data->icon_data = icon_data; | 102 data->icon_data = icon_data; |
| 104 | 103 |
| 105 arc_notification_manager()->OnNotificationPosted(std::move(data)); | 104 arc_notification_manager()->OnNotificationPosted(std::move(data)); |
| 106 | 105 |
| 107 return key; | 106 return key; |
| 108 } | 107 } |
| 109 | 108 |
| 110 private: | 109 private: |
| 111 base::MessageLoop loop_; | 110 base::MessageLoop loop_; |
| 112 std::unique_ptr<FakeArcBridgeService> service_; | 111 std::unique_ptr<ArcBridgeService> service_; |
| 113 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; | 112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; |
| 114 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; | 113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; |
| 115 std::unique_ptr<MockMessageCenter> message_center_; | 114 std::unique_ptr<MockMessageCenter> message_center_; |
| 116 | 115 |
| 117 void SetUp() override { | 116 void SetUp() override { |
| 118 arc_notifications_instance_.reset(new FakeNotificationsInstance()); | 117 arc_notifications_instance_ = base::MakeUnique<FakeNotificationsInstance>(); |
| 119 service_.reset(new FakeArcBridgeService()); | 118 service_ = base::MakeUnique<ArcBridgeService>(); |
| 120 message_center_.reset(new MockMessageCenter()); | 119 message_center_ = base::MakeUnique<MockMessageCenter>(); |
| 121 | 120 |
| 122 arc_notification_manager_.reset(new ArcNotificationManager( | 121 arc_notification_manager_ = base::MakeUnique<ArcNotificationManager>( |
| 123 service(), EmptyAccountId(), message_center_.get())); | 122 service_.get(), EmptyAccountId(), message_center_.get()); |
| 124 | 123 |
| 125 NotificationsObserver observer; | 124 NotificationsObserver observer; |
| 126 service_->notifications()->AddObserver(&observer); | 125 service_->notifications()->AddObserver(&observer); |
| 127 service_->notifications()->SetInstance(arc_notifications_instance_.get()); | 126 service_->notifications()->SetInstance(arc_notifications_instance_.get()); |
| 128 | 127 |
| 129 while (!observer.IsReady()) | 128 while (!observer.IsReady()) |
| 130 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 131 | 130 |
| 132 service_->notifications()->RemoveObserver(&observer); | 131 service_->notifications()->RemoveObserver(&observer); |
| 133 } | 132 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 146 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 145 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 147 std::string key = CreateNotification(); | 146 std::string key = CreateNotification(); |
| 148 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); | 147 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); |
| 149 | 148 |
| 150 arc_notification_manager()->OnNotificationRemoved(key); | 149 arc_notification_manager()->OnNotificationRemoved(key); |
| 151 | 150 |
| 152 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 151 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 153 } | 152 } |
| 154 | 153 |
| 155 TEST_F(ArcNotificationManagerTest, NotificationRemovedByChrome) { | 154 TEST_F(ArcNotificationManagerTest, NotificationRemovedByChrome) { |
| 156 service()->SetReady(); | |
| 157 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 155 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 158 std::string key = CreateNotification(); | 156 std::string key = CreateNotification(); |
| 159 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); | 157 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); |
| 160 | 158 |
| 161 { | 159 { |
| 162 message_center::Notification* notification = | 160 message_center::Notification* notification = |
| 163 *message_center()->GetVisibleNotifications().begin(); | 161 *message_center()->GetVisibleNotifications().begin(); |
| 164 notification->delegate()->Close(true /* by_user */); | 162 notification->delegate()->Close(true /* by_user */); |
| 165 // |notification| gets stale here. | 163 // |notification| gets stale here. |
| 166 } | 164 } |
| 167 | 165 |
| 168 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); | 166 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); |
| 169 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); | 167 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); |
| 170 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, | 168 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, |
| 171 arc_notifications_instance()->events().at(0).second); | 169 arc_notifications_instance()->events().at(0).second); |
| 172 } | 170 } |
| 173 | 171 |
| 174 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { | 172 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { |
| 175 service()->SetReady(); | |
| 176 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 173 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 177 CreateNotificationWithKey("notification1"); | 174 CreateNotificationWithKey("notification1"); |
| 178 CreateNotificationWithKey("notification2"); | 175 CreateNotificationWithKey("notification2"); |
| 179 CreateNotificationWithKey("notification3"); | 176 CreateNotificationWithKey("notification3"); |
| 180 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); | 177 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); |
| 181 | 178 |
| 182 arc_notification_manager()->OnInstanceClosed(); | 179 arc_notification_manager()->OnInstanceClosed(); |
| 183 | 180 |
| 184 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 181 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 185 } | 182 } |
| 186 | 183 |
| 187 } // namespace arc | 184 } // namespace arc |
| OLD | NEW |