Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: ui/arc/notification/arc_notification_manager_unittest.cc

Issue 2138513002: arc: Use the new InstanceHolder for unittests (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@bridge_refactor_first
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/arc/test/fake_notifications_instance.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector>
hidehiko 2016/07/11 06:05:18 nit: <string> and <memory>, too?
Luis Héctor Chávez 2016/07/11 17:15:08 Addressed in previous change.
6
5 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
6 #include "base/run_loop.h" 8 #include "base/run_loop.h"
7 #include "components/arc/test/fake_arc_bridge_instance.h" 9 #include "components/arc/test/fake_arc_bridge_instance.h"
8 #include "components/arc/test/fake_arc_bridge_service.h" 10 #include "components/arc/test/fake_arc_bridge_service.h"
9 #include "components/arc/test/fake_notifications_instance.h" 11 #include "components/arc/test/fake_notifications_instance.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/arc/notification/arc_notification_manager.h" 13 #include "ui/arc/notification/arc_notification_manager.h"
12 #include "ui/message_center/fake_message_center.h" 14 #include "ui/message_center/fake_message_center.h"
13 15
14 namespace arc { 16 namespace arc {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 107 }
106 108
107 private: 109 private:
108 base::MessageLoop loop_; 110 base::MessageLoop loop_;
109 std::unique_ptr<FakeArcBridgeService> service_; 111 std::unique_ptr<FakeArcBridgeService> service_;
110 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; 112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_;
111 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; 113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_;
112 std::unique_ptr<MockMessageCenter> message_center_; 114 std::unique_ptr<MockMessageCenter> message_center_;
113 115
114 void SetUp() override { 116 void SetUp() override {
115 mojom::NotificationsInstancePtr arc_notifications_instance; 117 arc_notifications_instance_.reset(new FakeNotificationsInstance());
116 arc_notifications_instance_.reset(
117 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance)));
118 service_.reset(new FakeArcBridgeService()); 118 service_.reset(new FakeArcBridgeService());
119 message_center_.reset(new MockMessageCenter()); 119 message_center_.reset(new MockMessageCenter());
120 120
121 arc_notification_manager_.reset(new ArcNotificationManager( 121 arc_notification_manager_.reset(new ArcNotificationManager(
122 service(), EmptyAccountId(), message_center_.get())); 122 service(), EmptyAccountId(), message_center_.get()));
123 123
124 NotificationsObserver observer; 124 NotificationsObserver observer;
125 service_->notifications()->AddObserver(&observer); 125 service_->notifications()->AddObserver(&observer);
126 service_->OnNotificationsInstanceReady( 126 service_->notifications()->SetInstance(arc_notifications_instance_.get());
127 std::move(arc_notifications_instance));
128 127
129 while (!observer.IsReady()) 128 while (!observer.IsReady())
130 loop_.RunUntilIdle(); 129 loop_.RunUntilIdle();
131 130
132 service_->notifications()->RemoveObserver(&observer); 131 service_->notifications()->RemoveObserver(&observer);
133 } 132 }
134 133
135 void TearDown() override { 134 void TearDown() override {
136 arc_notification_manager_.reset(); 135 arc_notification_manager_.reset();
137 message_center_.reset(); 136 message_center_.reset();
(...skipping 20 matching lines...) Expand all
158 std::string key = CreateNotification(); 157 std::string key = CreateNotification();
159 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); 158 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size());
160 159
161 { 160 {
162 message_center::Notification* notification = 161 message_center::Notification* notification =
163 *message_center()->GetVisibleNotifications().begin(); 162 *message_center()->GetVisibleNotifications().begin();
164 notification->delegate()->Close(true /* by_user */); 163 notification->delegate()->Close(true /* by_user */);
165 // |notification| gets stale here. 164 // |notification| gets stale here.
166 } 165 }
167 166
168 arc_notifications_instance()->WaitForIncomingMethodCall();
169
170 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); 167 ASSERT_EQ(1u, arc_notifications_instance()->events().size());
171 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); 168 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first);
172 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, 169 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED,
173 arc_notifications_instance()->events().at(0).second); 170 arc_notifications_instance()->events().at(0).second);
174 } 171 }
175 172
176 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { 173 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) {
177 service()->SetReady(); 174 service()->SetReady();
178 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); 175 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size());
179 CreateNotificationWithKey("notification1"); 176 CreateNotificationWithKey("notification1");
180 CreateNotificationWithKey("notification2"); 177 CreateNotificationWithKey("notification2");
181 CreateNotificationWithKey("notification3"); 178 CreateNotificationWithKey("notification3");
182 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); 179 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size());
183 180
184 arc_notification_manager()->OnInstanceClosed(nullptr); 181 arc_notification_manager()->OnInstanceClosed(nullptr);
185 182
186 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); 183 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size());
187 } 184 }
188 185
189 } // namespace arc 186 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/test/fake_notifications_instance.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698