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

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: Rebase 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 private: 109 private:
110 base::MessageLoop loop_; 110 base::MessageLoop loop_;
111 std::unique_ptr<FakeArcBridgeService> service_; 111 std::unique_ptr<FakeArcBridgeService> service_;
112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; 112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_;
113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; 113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_;
114 std::unique_ptr<MockMessageCenter> message_center_; 114 std::unique_ptr<MockMessageCenter> message_center_;
115 115
116 void SetUp() override { 116 void SetUp() override {
117 mojom::NotificationsInstancePtr arc_notifications_instance; 117 arc_notifications_instance_.reset(new FakeNotificationsInstance());
118 arc_notifications_instance_.reset(
119 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance)));
120 service_.reset(new FakeArcBridgeService()); 118 service_.reset(new FakeArcBridgeService());
121 message_center_.reset(new MockMessageCenter()); 119 message_center_.reset(new MockMessageCenter());
122 120
123 arc_notification_manager_.reset(new ArcNotificationManager( 121 arc_notification_manager_.reset(new ArcNotificationManager(
124 service(), EmptyAccountId(), message_center_.get())); 122 service(), EmptyAccountId(), message_center_.get()));
125 123
126 NotificationsObserver observer; 124 NotificationsObserver observer;
127 service_->notifications()->AddObserver(&observer); 125 service_->notifications()->AddObserver(&observer);
128 service_->OnNotificationsInstanceReady( 126 service_->notifications()->SetInstance(arc_notifications_instance_.get());
129 std::move(arc_notifications_instance));
130 127
131 while (!observer.IsReady()) 128 while (!observer.IsReady())
132 loop_.RunUntilIdle(); 129 loop_.RunUntilIdle();
133 130
134 service_->notifications()->RemoveObserver(&observer); 131 service_->notifications()->RemoveObserver(&observer);
135 } 132 }
136 133
137 void TearDown() override { 134 void TearDown() override {
138 arc_notification_manager_.reset(); 135 arc_notification_manager_.reset();
139 message_center_.reset(); 136 message_center_.reset();
(...skipping 20 matching lines...) Expand all
160 std::string key = CreateNotification(); 157 std::string key = CreateNotification();
161 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); 158 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size());
162 159
163 { 160 {
164 message_center::Notification* notification = 161 message_center::Notification* notification =
165 *message_center()->GetVisibleNotifications().begin(); 162 *message_center()->GetVisibleNotifications().begin();
166 notification->delegate()->Close(true /* by_user */); 163 notification->delegate()->Close(true /* by_user */);
167 // |notification| gets stale here. 164 // |notification| gets stale here.
168 } 165 }
169 166
170 arc_notifications_instance()->WaitForIncomingMethodCall();
171
172 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); 167 ASSERT_EQ(1u, arc_notifications_instance()->events().size());
173 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); 168 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first);
174 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, 169 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED,
175 arc_notifications_instance()->events().at(0).second); 170 arc_notifications_instance()->events().at(0).second);
176 } 171 }
177 172
178 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { 173 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) {
179 service()->SetReady(); 174 service()->SetReady();
180 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); 175 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size());
181 CreateNotificationWithKey("notification1"); 176 CreateNotificationWithKey("notification1");
182 CreateNotificationWithKey("notification2"); 177 CreateNotificationWithKey("notification2");
183 CreateNotificationWithKey("notification3"); 178 CreateNotificationWithKey("notification3");
184 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); 179 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size());
185 180
186 arc_notification_manager()->OnInstanceClosed(); 181 arc_notification_manager()->OnInstanceClosed();
187 182
188 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); 183 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size());
189 } 184 }
190 185
191 } // 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