| 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 "mojo/message_pump/message_pump_mojo.h" | 10 #include "mojo/message_pump/message_pump_mojo.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/arc/notification/arc_notification_manager.h" | 12 #include "ui/arc/notification/arc_notification_manager.h" |
| 13 #include "ui/message_center/fake_message_center.h" | 13 #include "ui/message_center/fake_message_center.h" |
| 14 | 14 |
| 15 namespace arc { | 15 namespace arc { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kDummyNotificationKey[] = "DUMMY_NOTIFICATION_KEY"; | 19 const char kDummyNotificationKey[] = "DUMMY_NOTIFICATION_KEY"; |
| 20 | 20 |
| 21 class MockMessageCenter : public message_center::FakeMessageCenter { | 21 class MockMessageCenter : public message_center::FakeMessageCenter { |
| 22 public: | 22 public: |
| 23 MockMessageCenter() {} | 23 MockMessageCenter() {} |
| 24 ~MockMessageCenter() override { | 24 ~MockMessageCenter() override { |
| 25 STLDeleteContainerPointers( | 25 STLDeleteContainerPointers( |
| 26 visible_notifications_.begin(), visible_notifications_.end()); | 26 visible_notifications_.begin(), visible_notifications_.end()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void AddNotification( | 29 void AddNotification( |
| 30 scoped_ptr<message_center::Notification> notification) override { | 30 std::unique_ptr<message_center::Notification> notification) override { |
| 31 visible_notifications_.insert(notification.release()); | 31 visible_notifications_.insert(notification.release()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void RemoveNotification(const std::string& id, bool by_user) override { | 34 void RemoveNotification(const std::string& id, bool by_user) override { |
| 35 for (auto it = visible_notifications_.begin(); | 35 for (auto it = visible_notifications_.begin(); |
| 36 it != visible_notifications_.end(); it++) { | 36 it != visible_notifications_.end(); it++) { |
| 37 if ((*it)->id() == id) { | 37 if ((*it)->id() == id) { |
| 38 delete *it; | 38 delete *it; |
| 39 visible_notifications_.erase(it); | 39 visible_notifications_.erase(it); |
| 40 return; | 40 return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 std::vector<unsigned char> icon_data; | 97 std::vector<unsigned char> icon_data; |
| 98 data->icon_data.Swap(&icon_data); | 98 data->icon_data.Swap(&icon_data); |
| 99 | 99 |
| 100 arc_notification_manager()->OnNotificationPosted(std::move(data)); | 100 arc_notification_manager()->OnNotificationPosted(std::move(data)); |
| 101 | 101 |
| 102 return key; | 102 return key; |
| 103 } | 103 } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 base::MessageLoop loop_; | 106 base::MessageLoop loop_; |
| 107 scoped_ptr<FakeArcBridgeService> service_; | 107 std::unique_ptr<FakeArcBridgeService> service_; |
| 108 scoped_ptr<FakeNotificationsInstance> arc_notifications_instance_; | 108 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; |
| 109 scoped_ptr<ArcNotificationManager> arc_notification_manager_; | 109 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; |
| 110 scoped_ptr<MockMessageCenter> message_center_; | 110 std::unique_ptr<MockMessageCenter> message_center_; |
| 111 | 111 |
| 112 void SetUp() override { | 112 void SetUp() override { |
| 113 NotificationsInstancePtr arc_notifications_instance; | 113 NotificationsInstancePtr arc_notifications_instance; |
| 114 arc_notifications_instance_.reset( | 114 arc_notifications_instance_.reset( |
| 115 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); | 115 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance))); |
| 116 service_.reset(new FakeArcBridgeService()); | 116 service_.reset(new FakeArcBridgeService()); |
| 117 message_center_.reset(new MockMessageCenter()); | 117 message_center_.reset(new MockMessageCenter()); |
| 118 | 118 |
| 119 arc_notification_manager_.reset(new ArcNotificationManager( | 119 arc_notification_manager_.reset(new ArcNotificationManager( |
| 120 service(), EmptyAccountId(), message_center_.get())); | 120 service(), EmptyAccountId(), message_center_.get())); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 CreateNotificationWithKey("notification2"); | 178 CreateNotificationWithKey("notification2"); |
| 179 CreateNotificationWithKey("notification3"); | 179 CreateNotificationWithKey("notification3"); |
| 180 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); | 180 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); |
| 181 | 181 |
| 182 arc_notification_manager()->OnNotificationsInstanceClosed(); | 182 arc_notification_manager()->OnNotificationsInstanceClosed(); |
| 183 | 183 |
| 184 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); | 184 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace arc | 187 } // namespace arc |
| OLD | NEW |