OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/presentation/presentation_service_impl.h" | 8 #include "content/browser/presentation/presentation_service_impl.h" |
9 #include "content/public/browser/presentation_service_delegate.h" | 9 #include "content/public/browser/presentation_service_delegate.h" |
10 #include "content/public/browser/presentation_session.h" | 10 #include "content/public/browser/presentation_session.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // has not been deleted. | 311 // has not been deleted. |
312 SimulateScreenAvailabilityChange(presentation_url, true); | 312 SimulateScreenAvailabilityChange(presentation_url, true); |
313 SaveQuitClosureAndRunLoop(); | 313 SaveQuitClosureAndRunLoop(); |
314 EXPECT_EQ(1, callback_count_); | 314 EXPECT_EQ(1, callback_count_); |
315 } | 315 } |
316 | 316 |
317 TEST_F(PresentationServiceImplTest, GetScreenAvailabilityTwice) { | 317 TEST_F(PresentationServiceImplTest, GetScreenAvailabilityTwice) { |
318 std::string presentation_url("http://fooUrl"); | 318 std::string presentation_url("http://fooUrl"); |
319 GetScreenAvailabilityAndWait( | 319 GetScreenAvailabilityAndWait( |
320 presentation_url, | 320 presentation_url, |
321 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | 321 base::Bind( |
322 base::Unretained(this)), | 322 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, |
| 323 base::Unretained(this), |
| 324 false), |
323 true); | 325 true); |
324 | 326 |
325 // Second call should overwrite the callback from first call. | 327 // Second call should overwrite the callback from first call. |
326 // It shouldn't result in an extra call to delegate. | 328 // It shouldn't result in an extra call to delegate. |
327 service_ptr_->GetScreenAvailability( | 329 service_ptr_->GetScreenAvailability( |
328 presentation_url, | 330 presentation_url, |
329 base::Bind( | 331 base::Bind( |
330 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | 332 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, |
331 base::Unretained(this), | 333 base::Unretained(this), |
332 false)); | 334 false)); |
333 | 335 |
334 // Cannot use GetScreenAvailabilityAndWait here since the mock delegate | 336 // Cannot use GetScreenAvailabilityAndWait here since the mock delegate |
335 // won't be triggered again to quit the RunLoop. | 337 // won't be triggered again to quit the RunLoop. |
336 RunLoopFor(base::TimeDelta::FromMilliseconds(50)); | 338 RunLoopFor(base::TimeDelta::FromMilliseconds(50)); |
337 | 339 |
338 // Result now available; callback will be invoked with availability result. | 340 // Result now available; callback will be invoked with availability result. |
339 SimulateScreenAvailabilityChange(presentation_url, false); | 341 SimulateScreenAvailabilityChange(presentation_url, false); |
340 SaveQuitClosureAndRunLoop(); | 342 SaveQuitClosureAndRunLoop(); |
341 | 343 |
342 EXPECT_EQ(1, callback_count_); | 344 EXPECT_EQ(2, callback_count_); |
343 } | 345 } |
344 | 346 |
345 TEST_F(PresentationServiceImplTest, DelegateFails) { | 347 TEST_F(PresentationServiceImplTest, DelegateFails) { |
346 std::string presentation_url("http://fooUrl"); | 348 std::string presentation_url("http://fooUrl"); |
347 GetScreenAvailabilityAndWait( | 349 GetScreenAvailabilityAndWait( |
348 presentation_url, | 350 presentation_url, |
349 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | 351 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, |
350 base::Unretained(this)), | 352 base::Unretained(this)), |
351 false); | 353 false); |
352 | 354 |
(...skipping 12 matching lines...) Expand all Loading... |
365 // Now there should be a callback registered with the DPU. | 367 // Now there should be a callback registered with the DPU. |
366 GetScreenAvailabilityAndWait( | 368 GetScreenAvailabilityAndWait( |
367 url1, | 369 url1, |
368 base::Bind( | 370 base::Bind( |
369 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | 371 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, |
370 base::Unretained(this), true), | 372 base::Unretained(this), true), |
371 true); | 373 true); |
372 const auto& contexts = service_impl_->availability_contexts_; | 374 const auto& contexts = service_impl_->availability_contexts_; |
373 auto it = contexts.find(url1); | 375 auto it = contexts.find(url1); |
374 ASSERT_TRUE(it != contexts.end()); | 376 ASSERT_TRUE(it != contexts.end()); |
375 EXPECT_NE(nullptr, it->second->GetCallback()); | 377 EXPECT_TRUE(it->second->HasPendingCallbacks()); |
376 | 378 |
377 std::string url2("http://barUrl"); | 379 std::string url2("http://barUrl"); |
378 // Sets different DPU. | 380 // Sets different DPU. |
379 // Adds listener for url2 and removes listener for url1. | 381 // Adds listener for url2 and removes listener for url1. |
380 // Also, the callback from url1 is transferred to url2. | 382 // Also, the callback from url1 is transferred to url2. |
381 EXPECT_CALL( | 383 EXPECT_CALL( |
382 mock_delegate_, | 384 mock_delegate_, |
383 AddScreenAvailabilityListener(_, _, _)) | 385 AddScreenAvailabilityListener(_, _, _)) |
384 .WillOnce(Return(true)); | 386 .WillOnce(Return(true)); |
385 EXPECT_CALL( | 387 EXPECT_CALL( |
386 mock_delegate_, | 388 mock_delegate_, |
387 RemoveScreenAvailabilityListener(_, _, _)) | 389 RemoveScreenAvailabilityListener(_, _, _)) |
388 .Times(1); | 390 .Times(1); |
389 EXPECT_CALL(mock_delegate_, | 391 EXPECT_CALL(mock_delegate_, |
390 SetDefaultPresentationUrl(_, _, Eq(url2), Eq(dpu_id))) | 392 SetDefaultPresentationUrl(_, _, Eq(url2), Eq(dpu_id))) |
391 .Times(1); | 393 .Times(1); |
392 service_impl_->SetDefaultPresentationURL(url2, dpu_id); | 394 service_impl_->SetDefaultPresentationURL(url2, dpu_id); |
393 EXPECT_EQ(url2, service_impl_->default_presentation_url_); | 395 EXPECT_EQ(url2, service_impl_->default_presentation_url_); |
394 | 396 |
395 it = contexts.find(url2); | 397 it = contexts.find(url2); |
396 ASSERT_TRUE(it != contexts.end()); | 398 ASSERT_TRUE(it != contexts.end()); |
397 EXPECT_NE(nullptr, it->second->GetCallback()); | 399 EXPECT_TRUE(it->second->HasPendingCallbacks()); |
398 } | 400 } |
399 | 401 |
400 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { | 402 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { |
401 std::string url("http://fooUrl"); | 403 std::string url("http://fooUrl"); |
402 std::string dpu_id("dpuId"); | 404 std::string dpu_id("dpuId"); |
403 EXPECT_CALL(mock_delegate_, | 405 EXPECT_CALL(mock_delegate_, |
404 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id))) | 406 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id))) |
405 .Times(1); | 407 .Times(1); |
406 service_impl_->SetDefaultPresentationURL(url, dpu_id); | 408 service_impl_->SetDefaultPresentationURL(url, dpu_id); |
407 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 409 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
(...skipping 18 matching lines...) Expand all Loading... |
426 GetScreenAvailabilityAndWait( | 428 GetScreenAvailabilityAndWait( |
427 url, | 429 url, |
428 base::Bind( | 430 base::Bind( |
429 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | 431 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, |
430 base::Unretained(this), true), | 432 base::Unretained(this), true), |
431 true); | 433 true); |
432 | 434 |
433 const auto& contexts = service_impl_->availability_contexts_; | 435 const auto& contexts = service_impl_->availability_contexts_; |
434 auto it = contexts.find(url); | 436 auto it = contexts.find(url); |
435 ASSERT_TRUE(it != contexts.end()); | 437 ASSERT_TRUE(it != contexts.end()); |
436 EXPECT_NE(nullptr, it->second->GetCallback()); | 438 EXPECT_TRUE(it->second->HasPendingCallbacks()); |
437 | 439 |
438 // Clears the default presentation URL. Transfers the listener from url to | 440 // Clears the default presentation URL. Transfers the listener from url to |
439 // "1-UA" mode. | 441 // "1-UA" mode. |
440 EXPECT_CALL( | 442 EXPECT_CALL( |
441 mock_delegate_, | 443 mock_delegate_, |
442 AddScreenAvailabilityListener(_, _, _)) | 444 AddScreenAvailabilityListener(_, _, _)) |
443 .WillOnce(Return(true)); | 445 .WillOnce(Return(true)); |
444 EXPECT_CALL( | 446 EXPECT_CALL( |
445 mock_delegate_, | 447 mock_delegate_, |
446 RemoveScreenAvailabilityListener(_, _, _)) | 448 RemoveScreenAvailabilityListener(_, _, _)) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 // Running the callback means the first request is done. It should now | 571 // Running the callback means the first request is done. It should now |
570 // move on to the queued request. | 572 // move on to the queued request. |
571 EXPECT_CALL(mock_delegate_, StartSession( | 573 EXPECT_CALL(mock_delegate_, StartSession( |
572 _, _, Eq(presentation_url2), Eq(presentation_id2), _, _)) | 574 _, _, Eq(presentation_url2), Eq(presentation_id2), _, _)) |
573 .Times(1); | 575 .Times(1); |
574 success_cb.Run(PresentationSessionInfo(presentation_url1, presentation_id1)); | 576 success_cb.Run(PresentationSessionInfo(presentation_url1, presentation_id1)); |
575 SaveQuitClosureAndRunLoop(); | 577 SaveQuitClosureAndRunLoop(); |
576 } | 578 } |
577 | 579 |
578 } // namespace content | 580 } // namespace content |
OLD | NEW |