OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/chromeos/net/tether_notification_presenter.h" | 5 #include "chrome/browser/chromeos/net/tether_notification_presenter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
11 #include "components/cryptauth/remote_device_test_util.h" | 12 #include "components/cryptauth/remote_device_test_util.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/message_center/fake_message_center.h" | 16 #include "ui/message_center/fake_message_center.h" |
15 #include "ui/message_center/message_center_observer.h" | 17 #include "ui/message_center/message_center_observer.h" |
16 | 18 |
17 namespace chromeos { | 19 namespace chromeos { |
18 | 20 |
19 namespace tether { | 21 namespace tether { |
20 | 22 |
21 namespace { | 23 namespace { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 bool shared) override {} | 131 bool shared) override {} |
130 | 132 |
131 void ConnectToNetworkId(const std::string& network_id) override { | 133 void ConnectToNetworkId(const std::string& network_id) override { |
132 network_id_to_connect_ = network_id; | 134 network_id_to_connect_ = network_id; |
133 } | 135 } |
134 | 136 |
135 private: | 137 private: |
136 std::string network_id_to_connect_; | 138 std::string network_id_to_connect_; |
137 }; | 139 }; |
138 | 140 |
| 141 class TestSettingsUiDelegate |
| 142 : public TetherNotificationPresenter::SettingsUiDelegate { |
| 143 public: |
| 144 TestSettingsUiDelegate() {} |
| 145 ~TestSettingsUiDelegate() override {} |
| 146 |
| 147 Profile* last_profile() { return last_profile_; } |
| 148 std::string last_settings_subpage() { return last_settings_subpage_; } |
| 149 |
| 150 // TetherNotificationPresenter::SettingsUiDelegate: |
| 151 void ShowSettingsSubPageForProfile(Profile* profile, |
| 152 const std::string& sub_page) override { |
| 153 last_profile_ = profile; |
| 154 last_settings_subpage_ = sub_page; |
| 155 } |
| 156 |
| 157 private: |
| 158 Profile* last_profile_ = nullptr; |
| 159 std::string last_settings_subpage_; |
| 160 }; |
| 161 |
139 protected: | 162 protected: |
140 TetherNotificationPresenterTest() : test_device_(CreateTestRemoteDevice()) {} | 163 TetherNotificationPresenterTest() : test_device_(CreateTestRemoteDevice()) {} |
141 | 164 |
142 void SetUp() override { | 165 void SetUp() override { |
| 166 TestingProfile::Builder builder; |
| 167 profile_ = builder.Build(); |
143 test_message_center_ = base::WrapUnique(new TestMessageCenter()); | 168 test_message_center_ = base::WrapUnique(new TestMessageCenter()); |
144 test_network_connect_ = base::WrapUnique(new TestNetworkConnect()); | 169 test_network_connect_ = base::WrapUnique(new TestNetworkConnect()); |
145 notification_presenter_ = base::WrapUnique(new TetherNotificationPresenter( | 170 notification_presenter_ = base::WrapUnique(new TetherNotificationPresenter( |
146 test_message_center_.get(), test_network_connect_.get())); | 171 profile_.get(), test_message_center_.get(), |
| 172 test_network_connect_.get())); |
| 173 |
| 174 test_settings_ui_delegate_ = new TestSettingsUiDelegate(); |
| 175 notification_presenter_->SetSettingsUiDelegateForTesting( |
| 176 base::WrapUnique(test_settings_ui_delegate_)); |
147 } | 177 } |
148 | 178 |
| 179 void TearDown() override { profile_.reset(); } |
| 180 |
149 std::string GetActiveHostNotificationId() { | 181 std::string GetActiveHostNotificationId() { |
150 return std::string(TetherNotificationPresenter::kActiveHostNotificationId); | 182 return std::string(TetherNotificationPresenter::kActiveHostNotificationId); |
151 } | 183 } |
152 | 184 |
153 std::string GetPotentialHotspotNotificationId() { | 185 std::string GetPotentialHotspotNotificationId() { |
154 return std::string( | 186 return std::string( |
155 TetherNotificationPresenter::kPotentialHotspotNotificationId); | 187 TetherNotificationPresenter::kPotentialHotspotNotificationId); |
156 } | 188 } |
157 | 189 |
| 190 void VerifySettingsOpened() { |
| 191 EXPECT_EQ(profile_.get(), test_settings_ui_delegate_->last_profile()); |
| 192 EXPECT_EQ("networks?type=Tether", |
| 193 test_settings_ui_delegate_->last_settings_subpage()); |
| 194 } |
| 195 |
| 196 void VerifySettingsNotOpened() { |
| 197 EXPECT_FALSE(test_settings_ui_delegate_->last_profile()); |
| 198 EXPECT_TRUE(test_settings_ui_delegate_->last_settings_subpage().empty()); |
| 199 } |
| 200 |
| 201 const content::TestBrowserThreadBundle thread_bundle_; |
158 const cryptauth::RemoteDevice test_device_; | 202 const cryptauth::RemoteDevice test_device_; |
159 | 203 |
| 204 std::unique_ptr<TestingProfile> profile_; |
160 std::unique_ptr<TestMessageCenter> test_message_center_; | 205 std::unique_ptr<TestMessageCenter> test_message_center_; |
161 std::unique_ptr<TestNetworkConnect> test_network_connect_; | 206 std::unique_ptr<TestNetworkConnect> test_network_connect_; |
| 207 TestSettingsUiDelegate* test_settings_ui_delegate_; |
162 | 208 |
163 std::unique_ptr<TetherNotificationPresenter> notification_presenter_; | 209 std::unique_ptr<TetherNotificationPresenter> notification_presenter_; |
164 | 210 |
165 private: | 211 private: |
166 DISALLOW_COPY_AND_ASSIGN(TetherNotificationPresenterTest); | 212 DISALLOW_COPY_AND_ASSIGN(TetherNotificationPresenterTest); |
167 }; | 213 }; |
168 | 214 |
169 TEST_F(TetherNotificationPresenterTest, | 215 TEST_F(TetherNotificationPresenterTest, |
170 TestHostConnectionFailedNotification_RemoveProgrammatically) { | 216 TestHostConnectionFailedNotification_RemoveProgrammatically) { |
171 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 217 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
172 GetActiveHostNotificationId())); | 218 GetActiveHostNotificationId())); |
173 notification_presenter_->NotifyConnectionToHostFailed(); | 219 notification_presenter_->NotifyConnectionToHostFailed(); |
174 | 220 |
175 message_center::Notification* notification = | 221 message_center::Notification* notification = |
176 test_message_center_->FindVisibleNotificationById( | 222 test_message_center_->FindVisibleNotificationById( |
177 GetActiveHostNotificationId()); | 223 GetActiveHostNotificationId()); |
178 EXPECT_TRUE(notification); | 224 EXPECT_TRUE(notification); |
179 EXPECT_EQ(GetActiveHostNotificationId(), notification->id()); | 225 EXPECT_EQ(GetActiveHostNotificationId(), notification->id()); |
180 | 226 |
181 EXPECT_EQ(1u, test_message_center_->GetNumNotifications()); | 227 EXPECT_EQ(1u, test_message_center_->GetNumNotifications()); |
182 notification_presenter_->RemoveConnectionToHostFailedNotification(); | 228 notification_presenter_->RemoveConnectionToHostFailedNotification(); |
183 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 229 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
184 GetActiveHostNotificationId())); | 230 GetActiveHostNotificationId())); |
185 EXPECT_EQ(0u, test_message_center_->GetNumNotifications()); | 231 EXPECT_EQ(0u, test_message_center_->GetNumNotifications()); |
| 232 |
| 233 VerifySettingsNotOpened(); |
186 } | 234 } |
187 | 235 |
188 TEST_F(TetherNotificationPresenterTest, | 236 TEST_F(TetherNotificationPresenterTest, |
189 TestHostConnectionFailedNotification_TapNotification) { | 237 TestHostConnectionFailedNotification_TapNotification) { |
190 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 238 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
191 GetActiveHostNotificationId())); | 239 GetActiveHostNotificationId())); |
192 notification_presenter_->NotifyConnectionToHostFailed(); | 240 notification_presenter_->NotifyConnectionToHostFailed(); |
193 | 241 |
194 message_center::Notification* notification = | 242 message_center::Notification* notification = |
195 test_message_center_->FindVisibleNotificationById( | 243 test_message_center_->FindVisibleNotificationById( |
196 GetActiveHostNotificationId()); | 244 GetActiveHostNotificationId()); |
197 EXPECT_TRUE(notification); | 245 EXPECT_TRUE(notification); |
198 EXPECT_EQ(GetActiveHostNotificationId(), notification->id()); | 246 EXPECT_EQ(GetActiveHostNotificationId(), notification->id()); |
199 | 247 |
200 // Tap the notification. | 248 // Tap the notification. |
201 test_message_center_->NotifyNotificationTapped(GetActiveHostNotificationId()); | 249 test_message_center_->NotifyNotificationTapped(GetActiveHostNotificationId()); |
202 // TODO(khorimoto): Test that the tethering settings page is opened. | 250 VerifySettingsOpened(); |
203 } | 251 } |
204 | 252 |
205 TEST_F(TetherNotificationPresenterTest, | 253 TEST_F(TetherNotificationPresenterTest, |
206 TestSinglePotentialHotspotNotification_RemoveProgrammatically) { | 254 TestSinglePotentialHotspotNotification_RemoveProgrammatically) { |
207 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 255 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
208 GetPotentialHotspotNotificationId())); | 256 GetPotentialHotspotNotificationId())); |
209 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); | 257 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); |
210 | 258 |
211 message_center::Notification* notification = | 259 message_center::Notification* notification = |
212 test_message_center_->FindVisibleNotificationById( | 260 test_message_center_->FindVisibleNotificationById( |
213 GetPotentialHotspotNotificationId()); | 261 GetPotentialHotspotNotificationId()); |
214 EXPECT_TRUE(notification); | 262 EXPECT_TRUE(notification); |
215 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 263 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
216 | 264 |
217 notification_presenter_->RemovePotentialHotspotNotification(); | 265 notification_presenter_->RemovePotentialHotspotNotification(); |
218 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 266 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
219 GetPotentialHotspotNotificationId())); | 267 GetPotentialHotspotNotificationId())); |
| 268 |
| 269 VerifySettingsNotOpened(); |
220 } | 270 } |
221 | 271 |
222 TEST_F(TetherNotificationPresenterTest, | 272 TEST_F(TetherNotificationPresenterTest, |
223 TestSinglePotentialHotspotNotification_TapNotification) { | 273 TestSinglePotentialHotspotNotification_TapNotification) { |
224 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 274 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
225 GetPotentialHotspotNotificationId())); | 275 GetPotentialHotspotNotificationId())); |
226 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); | 276 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); |
227 | 277 |
228 message_center::Notification* notification = | 278 message_center::Notification* notification = |
229 test_message_center_->FindVisibleNotificationById( | 279 test_message_center_->FindVisibleNotificationById( |
230 GetPotentialHotspotNotificationId()); | 280 GetPotentialHotspotNotificationId()); |
231 EXPECT_TRUE(notification); | 281 EXPECT_TRUE(notification); |
232 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 282 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
233 | 283 |
234 // Tap the notification. | 284 // Tap the notification. |
235 test_message_center_->NotifyNotificationTapped( | 285 test_message_center_->NotifyNotificationTapped( |
236 GetPotentialHotspotNotificationId()); | 286 GetPotentialHotspotNotificationId()); |
237 // TODO(khorimoto): Test that the tethering settings page is opened. | 287 VerifySettingsOpened(); |
238 } | 288 } |
239 | 289 |
240 TEST_F(TetherNotificationPresenterTest, | 290 TEST_F(TetherNotificationPresenterTest, |
241 TestSinglePotentialHotspotNotification_TapNotificationButton) { | 291 TestSinglePotentialHotspotNotification_TapNotificationButton) { |
242 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 292 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
243 GetPotentialHotspotNotificationId())); | 293 GetPotentialHotspotNotificationId())); |
244 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); | 294 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); |
245 | 295 |
246 message_center::Notification* notification = | 296 message_center::Notification* notification = |
247 test_message_center_->FindVisibleNotificationById( | 297 test_message_center_->FindVisibleNotificationById( |
248 GetPotentialHotspotNotificationId()); | 298 GetPotentialHotspotNotificationId()); |
249 EXPECT_TRUE(notification); | 299 EXPECT_TRUE(notification); |
250 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 300 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
251 | 301 |
252 // Tap the notification's button. | 302 // Tap the notification's button. |
253 test_message_center_->NotifyNotificationButtonTapped( | 303 test_message_center_->NotifyNotificationButtonTapped( |
254 GetPotentialHotspotNotificationId(), 0 /* button_index */); | 304 GetPotentialHotspotNotificationId(), 0 /* button_index */); |
255 | 305 |
256 EXPECT_EQ(test_device_.GetDeviceId(), | 306 EXPECT_EQ(test_device_.GetDeviceId(), |
257 test_network_connect_->network_id_to_connect()); | 307 test_network_connect_->network_id_to_connect()); |
258 | |
259 // TODO(hansberry): Test for the case of the user not yet going through | |
260 // the connection dialog. | |
261 } | 308 } |
262 | 309 |
263 TEST_F(TetherNotificationPresenterTest, | 310 TEST_F(TetherNotificationPresenterTest, |
264 TestMultiplePotentialHotspotNotification_RemoveProgrammatically) { | 311 TestMultiplePotentialHotspotNotification_RemoveProgrammatically) { |
265 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 312 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
266 GetPotentialHotspotNotificationId())); | 313 GetPotentialHotspotNotificationId())); |
267 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); | 314 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); |
268 | 315 |
269 message_center::Notification* notification = | 316 message_center::Notification* notification = |
270 test_message_center_->FindVisibleNotificationById( | 317 test_message_center_->FindVisibleNotificationById( |
271 GetPotentialHotspotNotificationId()); | 318 GetPotentialHotspotNotificationId()); |
272 EXPECT_TRUE(notification); | 319 EXPECT_TRUE(notification); |
273 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 320 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
274 | 321 |
275 notification_presenter_->RemovePotentialHotspotNotification(); | 322 notification_presenter_->RemovePotentialHotspotNotification(); |
276 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 323 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
277 GetPotentialHotspotNotificationId())); | 324 GetPotentialHotspotNotificationId())); |
| 325 |
| 326 VerifySettingsNotOpened(); |
278 } | 327 } |
279 | 328 |
280 TEST_F(TetherNotificationPresenterTest, | 329 TEST_F(TetherNotificationPresenterTest, |
281 TestMultiplePotentialHotspotNotification_TapNotification) { | 330 TestMultiplePotentialHotspotNotification_TapNotification) { |
282 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 331 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
283 GetPotentialHotspotNotificationId())); | 332 GetPotentialHotspotNotificationId())); |
284 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); | 333 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); |
285 | 334 |
286 message_center::Notification* notification = | 335 message_center::Notification* notification = |
287 test_message_center_->FindVisibleNotificationById( | 336 test_message_center_->FindVisibleNotificationById( |
288 GetPotentialHotspotNotificationId()); | 337 GetPotentialHotspotNotificationId()); |
289 EXPECT_TRUE(notification); | 338 EXPECT_TRUE(notification); |
290 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 339 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
291 | 340 |
292 // Tap the notification. | 341 // Tap the notification. |
293 test_message_center_->NotifyNotificationTapped( | 342 test_message_center_->NotifyNotificationTapped( |
294 GetPotentialHotspotNotificationId()); | 343 GetPotentialHotspotNotificationId()); |
295 // TODO(khorimoto): Test that the tethering settings page is opened. | 344 VerifySettingsOpened(); |
296 } | 345 } |
297 | 346 |
298 TEST_F(TetherNotificationPresenterTest, | 347 TEST_F(TetherNotificationPresenterTest, |
299 TestPotentialHotspotNotifications_UpdatesOneNotification) { | 348 TestPotentialHotspotNotifications_UpdatesOneNotification) { |
300 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 349 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
301 GetPotentialHotspotNotificationId())); | 350 GetPotentialHotspotNotificationId())); |
302 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); | 351 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); |
303 | 352 |
304 message_center::Notification* notification = | 353 message_center::Notification* notification = |
305 test_message_center_->FindVisibleNotificationById( | 354 test_message_center_->FindVisibleNotificationById( |
(...skipping 10 matching lines...) Expand all Loading... |
316 // new one. | 365 // new one. |
317 notification = test_message_center_->FindVisibleNotificationById( | 366 notification = test_message_center_->FindVisibleNotificationById( |
318 GetPotentialHotspotNotificationId()); | 367 GetPotentialHotspotNotificationId()); |
319 EXPECT_TRUE(notification); | 368 EXPECT_TRUE(notification); |
320 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 369 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
321 EXPECT_EQ(1u, test_message_center_->GetNumNotifications()); | 370 EXPECT_EQ(1u, test_message_center_->GetNumNotifications()); |
322 | 371 |
323 notification_presenter_->RemovePotentialHotspotNotification(); | 372 notification_presenter_->RemovePotentialHotspotNotification(); |
324 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 373 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
325 GetPotentialHotspotNotificationId())); | 374 GetPotentialHotspotNotificationId())); |
| 375 |
| 376 VerifySettingsNotOpened(); |
326 } | 377 } |
327 | 378 |
328 } // namespace tether | 379 } // namespace tether |
329 | 380 |
330 } // namespace chromeos | 381 } // namespace chromeos |
OLD | NEW |