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 "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "content/browser/presentation/presentation_service_impl.h" | 9 #include "content/browser/presentation/presentation_service_impl.h" |
10 #include "content/public/browser/presentation_service_delegate.h" | 10 #include "content/public/browser/presentation_service_delegate.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 scoped_ptr<PresentationSessionMessage> message_request, | 109 scoped_ptr<PresentationSessionMessage> message_request, |
110 const SendMessageCallback& send_message_cb) { | 110 const SendMessageCallback& send_message_cb) { |
111 SendMessageRawPtr( | 111 SendMessageRawPtr( |
112 render_process_id, | 112 render_process_id, |
113 render_frame_id, | 113 render_frame_id, |
114 message_request.release(), | 114 message_request.release(), |
115 send_message_cb); | 115 send_message_cb); |
116 } | 116 } |
117 }; | 117 }; |
118 | 118 |
| 119 class MockPresentationServiceClient : |
| 120 public presentation::PresentationServiceClient { |
| 121 public: |
| 122 MOCK_METHOD1(OnScreenAvailabilityUpdated, void(bool available)); |
| 123 }; |
| 124 |
119 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 125 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
120 public: | 126 public: |
121 PresentationServiceImplTest() | 127 PresentationServiceImplTest() |
122 : callback_count_(0), default_session_started_count_(0) {} | 128 : default_session_started_count_(0) {} |
123 | 129 |
124 void SetUp() override { | 130 void SetUp() override { |
125 RenderViewHostImplTestHarness::SetUp(); | 131 RenderViewHostImplTestHarness::SetUp(); |
126 | 132 |
127 auto request = mojo::GetProxy(&service_ptr_); | 133 auto request = mojo::GetProxy(&service_ptr_); |
128 | |
129 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); | 134 EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); |
130 service_impl_.reset(new PresentationServiceImpl( | 135 service_impl_.reset(new PresentationServiceImpl( |
131 contents()->GetMainFrame(), contents(), &mock_delegate_)); | 136 contents()->GetMainFrame(), contents(), &mock_delegate_)); |
132 service_impl_->Bind(request.Pass()); | 137 service_impl_->Bind(request.Pass()); |
| 138 |
| 139 presentation::PresentationServiceClientPtr client_ptr; |
| 140 client_binding_.reset( |
| 141 new mojo::Binding<presentation::PresentationServiceClient>( |
| 142 &mock_client_, mojo::GetProxy(&client_ptr))); |
| 143 service_impl_->SetClient(client_ptr.Pass()); |
133 } | 144 } |
134 | 145 |
135 void TearDown() override { | 146 void TearDown() override { |
136 service_ptr_.reset(); | 147 service_ptr_.reset(); |
137 if (service_impl_.get()) { | 148 if (service_impl_.get()) { |
138 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); | 149 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
139 service_impl_.reset(); | 150 service_impl_.reset(); |
140 } | 151 } |
141 RenderViewHostImplTestHarness::TearDown(); | 152 RenderViewHostImplTestHarness::TearDown(); |
142 } | 153 } |
143 | 154 |
144 void ListenForScreenAvailabilityAndWait( | 155 void ListenForScreenAvailabilityAndWait(bool delegate_success) { |
145 const std::string& presentation_url, | |
146 const base::Callback<void(const std::string&, bool)>& callback, | |
147 bool delegate_success) { | |
148 base::RunLoop run_loop; | 156 base::RunLoop run_loop; |
149 // This will call to |service_impl_| via mojo. Process the message | 157 // This will call to |service_impl_| via mojo. Process the message |
150 // using RunLoop. | 158 // using RunLoop. |
151 // The callback shouldn't be invoked since there is no availability | 159 // The callback shouldn't be invoked since there is no availability |
152 // result yet. | 160 // result yet. |
153 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener(_, _, _)) | 161 EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener(_, _, _)) |
154 .WillOnce(DoAll( | 162 .WillOnce(DoAll( |
155 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | 163 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
156 Return(delegate_success))); | 164 Return(delegate_success))); |
157 service_ptr_->ListenForScreenAvailability(presentation_url, callback); | 165 service_ptr_->ListenForScreenAvailability(); |
158 run_loop.Run(); | 166 run_loop.Run(); |
159 | 167 |
160 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 168 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
161 } | 169 } |
162 | 170 |
163 void ExpectListenerDoesNotExist(const std::string& presentation_url) { | |
164 const auto& contexts = service_impl_->availability_contexts_; | |
165 auto it = contexts.find(presentation_url); | |
166 EXPECT_TRUE(it == contexts.end()); | |
167 } | |
168 | |
169 void RunLoopFor(base::TimeDelta duration) { | 171 void RunLoopFor(base::TimeDelta duration) { |
170 base::RunLoop run_loop; | 172 base::RunLoop run_loop; |
171 base::MessageLoop::current()->PostDelayedTask( | 173 base::MessageLoop::current()->PostDelayedTask( |
172 FROM_HERE, run_loop.QuitClosure(), duration); | 174 FROM_HERE, run_loop.QuitClosure(), duration); |
173 run_loop.Run(); | 175 run_loop.Run(); |
174 } | 176 } |
175 | 177 |
176 void SaveQuitClosureAndRunLoop() { | 178 void SaveQuitClosureAndRunLoop() { |
177 base::RunLoop run_loop; | 179 base::RunLoop run_loop; |
178 run_loop_quit_closure_ = run_loop.QuitClosure(); | 180 run_loop_quit_closure_ = run_loop.QuitClosure(); |
179 run_loop.Run(); | 181 run_loop.Run(); |
180 run_loop_quit_closure_.Reset(); | 182 run_loop_quit_closure_.Reset(); |
181 } | 183 } |
182 | 184 |
183 void ShouldNotBeCalled(const std::string& presentation_url, bool available) { | 185 void SimulateScreenAvailabilityChangeAndWait(bool available) { |
184 FAIL() << "Callback unexpectedly invoked with " | 186 auto* listener = service_impl_->screen_availability_listener_.get(); |
185 << "url = " << presentation_url << ", available = " << available; | 187 ASSERT_TRUE(listener); |
186 } | |
187 | 188 |
188 void SimulateScreenAvailabilityChange( | 189 base::RunLoop run_loop; |
189 const std::string& presentation_url, bool available) { | 190 EXPECT_CALL(mock_client_, OnScreenAvailabilityUpdated(available)) |
190 const auto& contexts = service_impl_->availability_contexts_; | 191 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
191 auto it = contexts.find(presentation_url); | 192 listener->OnScreenAvailabilityChanged(available); |
192 ASSERT_TRUE(it != contexts.end()); | 193 run_loop.Run(); |
193 it->second->OnScreenAvailabilityChanged(available); | |
194 } | |
195 | |
196 void ScreenAvailabilityChangedCallback( | |
197 bool expected, | |
198 const std::string& presentation_url, | |
199 bool available) { | |
200 ++callback_count_; | |
201 EXPECT_EQ(expected, available); | |
202 if (!run_loop_quit_closure_.is_null()) | |
203 run_loop_quit_closure_.Run(); | |
204 } | 194 } |
205 | 195 |
206 void ExpectReset() { | 196 void ExpectReset() { |
207 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); | 197 EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); |
208 } | 198 } |
209 | 199 |
210 void ExpectCleanState() { | 200 void ExpectCleanState() { |
211 EXPECT_TRUE(service_impl_->availability_contexts_.empty()); | |
212 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); | 201 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); |
213 EXPECT_TRUE(service_impl_->default_presentation_id_.empty()); | 202 EXPECT_TRUE(service_impl_->default_presentation_id_.empty()); |
214 EXPECT_TRUE(service_impl_->queued_start_session_requests_.empty()); | 203 EXPECT_TRUE(service_impl_->queued_start_session_requests_.empty()); |
| 204 EXPECT_FALSE(service_impl_->screen_availability_listener_.get()); |
215 EXPECT_FALSE(service_impl_->default_session_start_context_.get()); | 205 EXPECT_FALSE(service_impl_->default_session_start_context_.get()); |
216 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); | 206 EXPECT_FALSE(service_impl_->on_session_messages_callback_.get()); |
217 } | 207 } |
218 | 208 |
219 void ExpectNewSessionMojoCallbackSuccess( | 209 void ExpectNewSessionMojoCallbackSuccess( |
220 presentation::PresentationSessionInfoPtr info, | 210 presentation::PresentationSessionInfoPtr info, |
221 presentation::PresentationErrorPtr error) { | 211 presentation::PresentationErrorPtr error) { |
222 EXPECT_FALSE(info.is_null()); | 212 EXPECT_FALSE(info.is_null()); |
223 EXPECT_TRUE(error.is_null()); | 213 EXPECT_TRUE(error.is_null()); |
224 if (!run_loop_quit_closure_.is_null()) | 214 if (!run_loop_quit_closure_.is_null()) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 messages->push_back( | 301 messages->push_back( |
312 content::PresentationSessionMessage::CreateBinaryMessage( | 302 content::PresentationSessionMessage::CreateBinaryMessage( |
313 presentation_url, presentation_id, | 303 presentation_url, presentation_id, |
314 scoped_ptr<std::vector<uint8_t>>( | 304 scoped_ptr<std::vector<uint8_t>>( |
315 new std::vector<uint8_t>(binary_data)))); | 305 new std::vector<uint8_t>(binary_data)))); |
316 message_cb.Run(messages.Pass()); | 306 message_cb.Run(messages.Pass()); |
317 SaveQuitClosureAndRunLoop(); | 307 SaveQuitClosureAndRunLoop(); |
318 } | 308 } |
319 | 309 |
320 MockPresentationServiceDelegate mock_delegate_; | 310 MockPresentationServiceDelegate mock_delegate_; |
| 311 |
321 scoped_ptr<PresentationServiceImpl> service_impl_; | 312 scoped_ptr<PresentationServiceImpl> service_impl_; |
322 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; | 313 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; |
| 314 |
| 315 MockPresentationServiceClient mock_client_; |
| 316 scoped_ptr<mojo::Binding<presentation::PresentationServiceClient>> |
| 317 client_binding_; |
| 318 |
323 base::Closure run_loop_quit_closure_; | 319 base::Closure run_loop_quit_closure_; |
324 int callback_count_; | |
325 int default_session_started_count_; | 320 int default_session_started_count_; |
326 mojo::Array<presentation::SessionMessagePtr> expected_msgs_; | 321 mojo::Array<presentation::SessionMessagePtr> expected_msgs_; |
327 }; | 322 }; |
328 | 323 |
329 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { | 324 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { |
330 std::string presentation_url("http://fooUrl"); | 325 ListenForScreenAvailabilityAndWait(true); |
331 ListenForScreenAvailabilityAndWait( | |
332 presentation_url, | |
333 base::Bind( | |
334 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
335 base::Unretained(this), true), | |
336 true); | |
337 | 326 |
338 // Different presentation URL. | 327 SimulateScreenAvailabilityChangeAndWait(true); |
339 ListenForScreenAvailabilityAndWait( | 328 SimulateScreenAvailabilityChangeAndWait(false); |
340 "http://barUrl", | 329 SimulateScreenAvailabilityChangeAndWait(true); |
341 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | |
342 base::Unretained(this)), | |
343 true); | |
344 | |
345 // Result now available; callback will be invoked with availability result. | |
346 SimulateScreenAvailabilityChange(presentation_url, true); | |
347 SaveQuitClosureAndRunLoop(); | |
348 | |
349 EXPECT_EQ(1, callback_count_); | |
350 | |
351 // Result updated but callback not invoked since it's been erased. | |
352 SimulateScreenAvailabilityChange(presentation_url, false); | |
353 | |
354 // Register another callback which should immediately invoke callback | |
355 // since updated result is available. | |
356 service_ptr_->ListenForScreenAvailability( | |
357 presentation_url, | |
358 base::Bind( | |
359 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
360 base::Unretained(this), | |
361 false)); | |
362 SaveQuitClosureAndRunLoop(); | |
363 EXPECT_EQ(2, callback_count_); | |
364 } | 330 } |
365 | 331 |
366 TEST_F(PresentationServiceImplTest, Reset) { | 332 TEST_F(PresentationServiceImplTest, Reset) { |
367 std::string presentation_url("http://fooUrl"); | 333 ListenForScreenAvailabilityAndWait(true); |
368 ListenForScreenAvailabilityAndWait( | |
369 presentation_url, | |
370 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | |
371 base::Unretained(this)), | |
372 true); | |
373 | 334 |
374 ExpectReset(); | 335 ExpectReset(); |
375 service_impl_->Reset(); | 336 service_impl_->Reset(); |
376 ExpectCleanState(); | 337 ExpectCleanState(); |
377 | |
378 EXPECT_EQ(0, callback_count_); | |
379 } | 338 } |
380 | 339 |
381 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { | 340 TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { |
382 std::string presentation_url("http://fooUrl"); | 341 ListenForScreenAvailabilityAndWait(true); |
383 ListenForScreenAvailabilityAndWait( | |
384 presentation_url, | |
385 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | |
386 base::Unretained(this)), | |
387 true); | |
388 | 342 |
389 ExpectReset(); | 343 ExpectReset(); |
390 service_impl_->DidNavigateAnyFrame( | 344 service_impl_->DidNavigateAnyFrame( |
391 contents()->GetMainFrame(), | 345 contents()->GetMainFrame(), |
392 content::LoadCommittedDetails(), | 346 content::LoadCommittedDetails(), |
393 content::FrameNavigateParams()); | 347 content::FrameNavigateParams()); |
394 ExpectCleanState(); | 348 ExpectCleanState(); |
395 } | 349 } |
396 | 350 |
397 TEST_F(PresentationServiceImplTest, DidNavigateNotThisFrame) { | 351 TEST_F(PresentationServiceImplTest, DidNavigateOtherFrame) { |
398 std::string presentation_url("http://fooUrl"); | 352 ListenForScreenAvailabilityAndWait(true); |
399 ListenForScreenAvailabilityAndWait( | |
400 presentation_url, | |
401 base::Bind( | |
402 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
403 base::Unretained(this), | |
404 true), | |
405 true); | |
406 | 353 |
407 // TODO(imcheng): How to get a different RenderFrameHost? | 354 // TODO(imcheng): How to get a different RenderFrameHost? |
408 service_impl_->DidNavigateAnyFrame( | 355 service_impl_->DidNavigateAnyFrame( |
409 nullptr, | 356 nullptr, |
410 content::LoadCommittedDetails(), | 357 content::LoadCommittedDetails(), |
411 content::FrameNavigateParams()); | 358 content::FrameNavigateParams()); |
412 | 359 |
413 // Availability is reported and callback is invoked since it was not | 360 // Availability is reported and callback is invoked since it was not |
414 // removed. | 361 // removed. |
415 SimulateScreenAvailabilityChange(presentation_url, true); | 362 SimulateScreenAvailabilityChangeAndWait(true); |
416 SaveQuitClosureAndRunLoop(); | |
417 EXPECT_EQ(1, callback_count_); | |
418 } | 363 } |
419 | 364 |
420 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) { | 365 TEST_F(PresentationServiceImplTest, ThisRenderFrameDeleted) { |
421 std::string presentation_url("http://fooUrl"); | 366 ListenForScreenAvailabilityAndWait(true); |
422 ListenForScreenAvailabilityAndWait( | |
423 presentation_url, | |
424 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | |
425 base::Unretained(this)), | |
426 true); | |
427 | 367 |
428 ExpectReset(); | 368 ExpectReset(); |
429 | 369 |
430 // Since the frame matched the service, |service_impl_| will be deleted. | 370 // Since the frame matched the service, |service_impl_| will be deleted. |
431 PresentationServiceImpl* service = service_impl_.release(); | 371 PresentationServiceImpl* service = service_impl_.release(); |
432 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); | 372 EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
433 service->RenderFrameDeleted(contents()->GetMainFrame()); | 373 service->RenderFrameDeleted(contents()->GetMainFrame()); |
434 } | 374 } |
435 | 375 |
436 TEST_F(PresentationServiceImplTest, NotThisRenderFrameDeleted) { | 376 TEST_F(PresentationServiceImplTest, OtherRenderFrameDeleted) { |
437 std::string presentation_url("http://fooUrl"); | 377 ListenForScreenAvailabilityAndWait(true); |
438 ListenForScreenAvailabilityAndWait( | |
439 presentation_url, | |
440 base::Bind( | |
441 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
442 base::Unretained(this), | |
443 true), | |
444 true); | |
445 | 378 |
446 // TODO(imcheng): How to get a different RenderFrameHost? | 379 // TODO(imcheng): How to get a different RenderFrameHost? |
447 service_impl_->RenderFrameDeleted(nullptr); | 380 service_impl_->RenderFrameDeleted(nullptr); |
448 | 381 |
449 // Availability is reported and callback should be invoked since listener | 382 // Availability is reported and callback should be invoked since listener |
450 // has not been deleted. | 383 // has not been deleted. |
451 SimulateScreenAvailabilityChange(presentation_url, true); | 384 SimulateScreenAvailabilityChangeAndWait(true); |
452 SaveQuitClosureAndRunLoop(); | |
453 EXPECT_EQ(1, callback_count_); | |
454 } | |
455 | |
456 TEST_F(PresentationServiceImplTest, ListenForScreenAvailabilityTwice) { | |
457 std::string presentation_url("http://fooUrl"); | |
458 ListenForScreenAvailabilityAndWait( | |
459 presentation_url, | |
460 base::Bind( | |
461 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
462 base::Unretained(this), | |
463 false), | |
464 true); | |
465 | |
466 // Second call should overwrite the callback from first call. | |
467 // It shouldn't result in an extra call to delegate. | |
468 service_ptr_->ListenForScreenAvailability( | |
469 presentation_url, | |
470 base::Bind( | |
471 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
472 base::Unretained(this), | |
473 false)); | |
474 | |
475 // Cannot use ListenForScreenAvailabilityAndWait here since the mock delegate | |
476 // won't be triggered again to quit the RunLoop. | |
477 RunLoopFor(base::TimeDelta::FromMilliseconds(50)); | |
478 | |
479 // Result now available; callback will be invoked with availability result. | |
480 SimulateScreenAvailabilityChange(presentation_url, false); | |
481 SaveQuitClosureAndRunLoop(); | |
482 | |
483 EXPECT_EQ(2, callback_count_); | |
484 } | 385 } |
485 | 386 |
486 TEST_F(PresentationServiceImplTest, DelegateFails) { | 387 TEST_F(PresentationServiceImplTest, DelegateFails) { |
487 std::string presentation_url("http://fooUrl"); | 388 ListenForScreenAvailabilityAndWait(false); |
488 ListenForScreenAvailabilityAndWait( | 389 ASSERT_FALSE(service_impl_->screen_availability_listener_.get()); |
489 presentation_url, | |
490 base::Bind(&PresentationServiceImplTest::ShouldNotBeCalled, | |
491 base::Unretained(this)), | |
492 false); | |
493 | |
494 ExpectListenerDoesNotExist(presentation_url); | |
495 } | 390 } |
496 | 391 |
497 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) { | 392 TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrl) { |
498 std::string url1("http://fooUrl"); | 393 std::string url1("http://fooUrl"); |
499 std::string dpu_id("dpuId"); | 394 std::string dpu_id("dpuId"); |
500 EXPECT_CALL(mock_delegate_, | 395 EXPECT_CALL(mock_delegate_, |
501 SetDefaultPresentationUrl(_, _, Eq(url1), Eq(dpu_id))) | 396 SetDefaultPresentationUrl(_, _, Eq(url1), Eq(dpu_id))) |
502 .Times(1); | 397 .Times(1); |
503 service_impl_->SetDefaultPresentationURL(url1, dpu_id); | 398 service_impl_->SetDefaultPresentationURL(url1, dpu_id); |
504 EXPECT_EQ(url1, service_impl_->default_presentation_url_); | 399 EXPECT_EQ(url1, service_impl_->default_presentation_url_); |
505 | 400 |
506 // Now there should be a callback registered with the DPU. | 401 // Now there should be a listener for DPU = |url1|. |
507 ListenForScreenAvailabilityAndWait( | 402 ListenForScreenAvailabilityAndWait(true); |
508 url1, | 403 auto* listener = service_impl_->screen_availability_listener_.get(); |
509 base::Bind( | 404 ASSERT_TRUE(listener); |
510 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | 405 EXPECT_EQ(url1, listener->GetPresentationUrl()); |
511 base::Unretained(this), true), | |
512 true); | |
513 const auto& contexts = service_impl_->availability_contexts_; | |
514 auto it = contexts.find(url1); | |
515 ASSERT_TRUE(it != contexts.end()); | |
516 EXPECT_TRUE(it->second->HasPendingCallbacks()); | |
517 | 406 |
518 std::string url2("http://barUrl"); | 407 std::string url2("http://barUrl"); |
519 // Sets different DPU. | 408 // Sets different DPU. |
520 // Adds listener for url2 and removes listener for url1. | 409 // Adds listener for url2 and removes listener for url1. |
521 // Also, the callback from url1 is transferred to url2. | |
522 EXPECT_CALL( | 410 EXPECT_CALL( |
523 mock_delegate_, | 411 mock_delegate_, |
524 AddScreenAvailabilityListener(_, _, _)) | 412 AddScreenAvailabilityListener(_, _, _)) |
525 .WillOnce(Return(true)); | 413 .WillOnce(Return(true)); |
526 EXPECT_CALL( | 414 EXPECT_CALL( |
527 mock_delegate_, | 415 mock_delegate_, |
528 RemoveScreenAvailabilityListener(_, _, _)) | 416 RemoveScreenAvailabilityListener(_, _, _)) |
529 .Times(1); | 417 .Times(1); |
530 EXPECT_CALL(mock_delegate_, | 418 EXPECT_CALL(mock_delegate_, |
531 SetDefaultPresentationUrl(_, _, Eq(url2), Eq(dpu_id))) | 419 SetDefaultPresentationUrl(_, _, Eq(url2), Eq(dpu_id))) |
532 .Times(1); | 420 .Times(1); |
533 service_impl_->SetDefaultPresentationURL(url2, dpu_id); | 421 service_impl_->SetDefaultPresentationURL(url2, dpu_id); |
534 EXPECT_EQ(url2, service_impl_->default_presentation_url_); | 422 EXPECT_EQ(url2, service_impl_->default_presentation_url_); |
535 | 423 |
536 it = contexts.find(url2); | 424 listener = service_impl_->screen_availability_listener_.get(); |
537 ASSERT_TRUE(it != contexts.end()); | 425 ASSERT_TRUE(listener); |
538 EXPECT_TRUE(it->second->HasPendingCallbacks()); | 426 EXPECT_EQ(url2, listener->GetPresentationUrl()); |
539 } | 427 } |
540 | 428 |
541 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { | 429 TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrl) { |
542 std::string url("http://fooUrl"); | 430 std::string url("http://fooUrl"); |
543 std::string dpu_id("dpuId"); | 431 std::string dpu_id("dpuId"); |
544 EXPECT_CALL(mock_delegate_, | 432 EXPECT_CALL(mock_delegate_, |
545 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id))) | 433 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id))) |
546 .Times(1); | 434 .Times(1); |
547 service_impl_->SetDefaultPresentationURL(url, dpu_id); | 435 service_impl_->SetDefaultPresentationURL(url, dpu_id); |
548 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 436 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
549 EXPECT_EQ(url, service_impl_->default_presentation_url_); | 437 EXPECT_EQ(url, service_impl_->default_presentation_url_); |
550 | 438 |
551 // Same URL as before; no-ops. | 439 // Same URL as before; no-ops. |
552 service_impl_->SetDefaultPresentationURL(url, dpu_id); | 440 service_impl_->SetDefaultPresentationURL(url, dpu_id); |
553 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); | 441 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
554 EXPECT_EQ(url, service_impl_->default_presentation_url_); | 442 EXPECT_EQ(url, service_impl_->default_presentation_url_); |
555 } | 443 } |
556 | 444 |
557 TEST_F(PresentationServiceImplTest, ClearDefaultPresentationUrl) { | |
558 std::string url("http://fooUrl"); | |
559 std::string dpu_id("dpuId"); | |
560 EXPECT_CALL(mock_delegate_, | |
561 SetDefaultPresentationUrl(_, _, Eq(url), Eq(dpu_id))) | |
562 .Times(1); | |
563 service_impl_->SetDefaultPresentationURL(url, dpu_id); | |
564 EXPECT_EQ(url, service_impl_->default_presentation_url_); | |
565 | |
566 // Now there should be a callback registered with the DPU. | |
567 ListenForScreenAvailabilityAndWait( | |
568 url, | |
569 base::Bind( | |
570 &PresentationServiceImplTest::ScreenAvailabilityChangedCallback, | |
571 base::Unretained(this), true), | |
572 true); | |
573 | |
574 const auto& contexts = service_impl_->availability_contexts_; | |
575 auto it = contexts.find(url); | |
576 ASSERT_TRUE(it != contexts.end()); | |
577 EXPECT_TRUE(it->second->HasPendingCallbacks()); | |
578 | |
579 // Clears the default presentation URL. Transfers the listener from url to | |
580 // "1-UA" mode. | |
581 EXPECT_CALL( | |
582 mock_delegate_, | |
583 AddScreenAvailabilityListener(_, _, _)) | |
584 .WillOnce(Return(true)); | |
585 EXPECT_CALL( | |
586 mock_delegate_, | |
587 RemoveScreenAvailabilityListener(_, _, _)) | |
588 .Times(1); | |
589 EXPECT_CALL( | |
590 mock_delegate_, | |
591 SetDefaultPresentationUrl(_, _, Eq(std::string()), Eq(std::string()))) | |
592 .Times(1); | |
593 service_impl_->SetDefaultPresentationURL(std::string(), std::string()); | |
594 EXPECT_TRUE(service_impl_->default_presentation_url_.empty()); | |
595 | |
596 it = contexts.find(url); | |
597 ASSERT_TRUE(it == contexts.end()); | |
598 } | |
599 | |
600 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { | 445 TEST_F(PresentationServiceImplTest, StartSessionSuccess) { |
601 std::string presentation_url("http://fooUrl"); | 446 std::string presentation_url("http://fooUrl"); |
602 std::string presentation_id("presentationId"); | 447 std::string presentation_id("presentationId"); |
603 service_ptr_->StartSession( | 448 service_ptr_->StartSession( |
604 presentation_url, | 449 presentation_url, |
605 presentation_id, | 450 presentation_id, |
606 base::Bind( | 451 base::Bind( |
607 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, | 452 &PresentationServiceImplTest::ExpectNewSessionMojoCallbackSuccess, |
608 base::Unretained(this))); | 453 base::Unretained(this))); |
609 base::RunLoop run_loop; | 454 base::RunLoop run_loop; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 SaveArg<2>(&test_message), | 778 SaveArg<2>(&test_message), |
934 SaveArg<3>(&send_message_cb))); | 779 SaveArg<3>(&send_message_cb))); |
935 run_loop.Run(); | 780 run_loop.Run(); |
936 | 781 |
937 EXPECT_FALSE(test_message); | 782 EXPECT_FALSE(test_message); |
938 send_message_cb.Run(); | 783 send_message_cb.Run(); |
939 SaveQuitClosureAndRunLoop(); | 784 SaveQuitClosureAndRunLoop(); |
940 } | 785 } |
941 | 786 |
942 } // namespace content | 787 } // namespace content |
OLD | NEW |