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

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

Issue 2144013002: Reland of arc: Use the new InstanceHolder for unittests (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@bridge_refactor_first
Patch Set: Fixed bad merge 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 <utility>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "components/arc/instance_holder.h" 12 #include "components/arc/instance_holder.h"
12 #include "components/arc/test/fake_arc_bridge_instance.h" 13 #include "components/arc/test/fake_arc_bridge_instance.h"
13 #include "components/arc/test/fake_arc_bridge_service.h" 14 #include "components/arc/test/fake_arc_bridge_service.h"
14 #include "components/arc/test/fake_notifications_instance.h" 15 #include "components/arc/test/fake_notifications_instance.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/arc/notification/arc_notification_manager.h" 17 #include "ui/arc/notification/arc_notification_manager.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 108 }
108 109
109 private: 110 private:
110 base::MessageLoop loop_; 111 base::MessageLoop loop_;
111 std::unique_ptr<FakeArcBridgeService> service_; 112 std::unique_ptr<FakeArcBridgeService> service_;
112 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_; 113 std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_;
113 std::unique_ptr<ArcNotificationManager> arc_notification_manager_; 114 std::unique_ptr<ArcNotificationManager> arc_notification_manager_;
114 std::unique_ptr<MockMessageCenter> message_center_; 115 std::unique_ptr<MockMessageCenter> message_center_;
115 116
116 void SetUp() override { 117 void SetUp() override {
117 mojom::NotificationsInstancePtr arc_notifications_instance; 118 arc_notifications_instance_.reset(new FakeNotificationsInstance());
118 arc_notifications_instance_.reset(
119 new FakeNotificationsInstance(GetProxy(&arc_notifications_instance)));
120 service_.reset(new FakeArcBridgeService()); 119 service_.reset(new FakeArcBridgeService());
121 message_center_.reset(new MockMessageCenter()); 120 message_center_.reset(new MockMessageCenter());
122 121
123 arc_notification_manager_.reset(new ArcNotificationManager( 122 arc_notification_manager_.reset(new ArcNotificationManager(
124 service(), EmptyAccountId(), message_center_.get())); 123 service(), EmptyAccountId(), message_center_.get()));
125 124
126 NotificationsObserver observer; 125 NotificationsObserver observer;
127 service_->notifications()->AddObserver(&observer); 126 service_->notifications()->AddObserver(&observer);
128 service_->OnNotificationsInstanceReady( 127 service_->notifications()->SetInstance(arc_notifications_instance_.get());
129 std::move(arc_notifications_instance));
130 128
131 while (!observer.IsReady()) 129 while (!observer.IsReady())
132 loop_.RunUntilIdle(); 130 loop_.RunUntilIdle();
133 131
134 service_->notifications()->RemoveObserver(&observer); 132 service_->notifications()->RemoveObserver(&observer);
135 } 133 }
136 134
137 void TearDown() override { 135 void TearDown() override {
138 arc_notification_manager_.reset(); 136 arc_notification_manager_.reset();
139 message_center_.reset(); 137 message_center_.reset();
(...skipping 20 matching lines...) Expand all
160 std::string key = CreateNotification(); 158 std::string key = CreateNotification();
161 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); 159 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size());
162 160
163 { 161 {
164 message_center::Notification* notification = 162 message_center::Notification* notification =
165 *message_center()->GetVisibleNotifications().begin(); 163 *message_center()->GetVisibleNotifications().begin();
166 notification->delegate()->Close(true /* by_user */); 164 notification->delegate()->Close(true /* by_user */);
167 // |notification| gets stale here. 165 // |notification| gets stale here.
168 } 166 }
169 167
170 arc_notifications_instance()->WaitForIncomingMethodCall();
171
172 ASSERT_EQ(1u, arc_notifications_instance()->events().size()); 168 ASSERT_EQ(1u, arc_notifications_instance()->events().size());
173 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); 169 EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first);
174 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, 170 EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED,
175 arc_notifications_instance()->events().at(0).second); 171 arc_notifications_instance()->events().at(0).second);
176 } 172 }
177 173
178 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) { 174 TEST_F(ArcNotificationManagerTest, NotificationRemovedByConnectionClose) {
179 service()->SetReady(); 175 service()->SetReady();
180 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); 176 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size());
181 CreateNotificationWithKey("notification1"); 177 CreateNotificationWithKey("notification1");
182 CreateNotificationWithKey("notification2"); 178 CreateNotificationWithKey("notification2");
183 CreateNotificationWithKey("notification3"); 179 CreateNotificationWithKey("notification3");
184 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size()); 180 EXPECT_EQ(3u, message_center()->GetVisibleNotifications().size());
185 181
186 arc_notification_manager()->OnInstanceClosed(); 182 arc_notification_manager()->OnInstanceClosed();
187 183
188 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size()); 184 EXPECT_EQ(0u, message_center()->GetVisibleNotifications().size());
189 } 185 }
190 186
191 } // namespace arc 187 } // 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