| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const PresentationSessionSuccessCallback& success_cb, | 58 const PresentationSessionSuccessCallback& success_cb, |
| 59 const PresentationSessionErrorCallback& error_cb)); | 59 const PresentationSessionErrorCallback& error_cb)); |
| 60 MOCK_METHOD6(JoinSession, | 60 MOCK_METHOD6(JoinSession, |
| 61 void( | 61 void( |
| 62 int render_process_id, | 62 int render_process_id, |
| 63 int render_frame_id, | 63 int render_frame_id, |
| 64 const std::string& presentation_url, | 64 const std::string& presentation_url, |
| 65 const std::string& presentation_id, | 65 const std::string& presentation_id, |
| 66 const PresentationSessionSuccessCallback& success_cb, | 66 const PresentationSessionSuccessCallback& success_cb, |
| 67 const PresentationSessionErrorCallback& error_cb)); | 67 const PresentationSessionErrorCallback& error_cb)); |
| 68 |
| 69 MOCK_METHOD6(SendStringMessage, |
| 70 void( |
| 71 int render_process_id, |
| 72 int render_frame_id, |
| 73 const std::string& presentation_url, |
| 74 const std::string& presentation_id, |
| 75 const std::string& message, |
| 76 const SendMessageCallback& send_message_cb)); |
| 68 }; | 77 }; |
| 69 | 78 |
| 70 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 79 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| 71 public: | 80 public: |
| 72 PresentationServiceImplTest() : callback_count_(0) {} | 81 PresentationServiceImplTest() : callback_count_(0) {} |
| 73 | 82 |
| 74 void SetUp() override { | 83 void SetUp() override { |
| 75 RenderViewHostImplTestHarness::SetUp(); | 84 RenderViewHostImplTestHarness::SetUp(); |
| 76 | 85 |
| 77 auto request = mojo::GetProxy(&service_ptr_); | 86 auto request = mojo::GetProxy(&service_ptr_); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 186 |
| 178 void ExpectNewSessionMojoCallbackError( | 187 void ExpectNewSessionMojoCallbackError( |
| 179 presentation::PresentationSessionInfoPtr info, | 188 presentation::PresentationSessionInfoPtr info, |
| 180 presentation::PresentationErrorPtr error) { | 189 presentation::PresentationErrorPtr error) { |
| 181 EXPECT_TRUE(info.is_null()); | 190 EXPECT_TRUE(info.is_null()); |
| 182 EXPECT_FALSE(error.is_null()); | 191 EXPECT_FALSE(error.is_null()); |
| 183 if (!run_loop_quit_closure_.is_null()) | 192 if (!run_loop_quit_closure_.is_null()) |
| 184 run_loop_quit_closure_.Run(); | 193 run_loop_quit_closure_.Run(); |
| 185 } | 194 } |
| 186 | 195 |
| 196 void ExpectSendMessageMojoCallback() { |
| 197 if (!run_loop_quit_closure_.is_null()) |
| 198 run_loop_quit_closure_.Run(); |
| 199 } |
| 200 |
| 187 MockPresentationServiceDelegate mock_delegate_; | 201 MockPresentationServiceDelegate mock_delegate_; |
| 188 scoped_ptr<PresentationServiceImpl> service_impl_; | 202 scoped_ptr<PresentationServiceImpl> service_impl_; |
| 189 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; | 203 mojo::InterfacePtr<presentation::PresentationService> service_ptr_; |
| 190 base::Closure run_loop_quit_closure_; | 204 base::Closure run_loop_quit_closure_; |
| 191 int callback_count_; | 205 int callback_count_; |
| 192 }; | 206 }; |
| 193 | 207 |
| 194 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { | 208 TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { |
| 195 std::string presentation_url("http://fooUrl"); | 209 std::string presentation_url("http://fooUrl"); |
| 196 ListenForScreenAvailabilityAndWait( | 210 ListenForScreenAvailabilityAndWait( |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 588 |
| 575 // Running the callback means the first request is done. It should now | 589 // Running the callback means the first request is done. It should now |
| 576 // move on to the queued request. | 590 // move on to the queued request. |
| 577 EXPECT_CALL(mock_delegate_, StartSession( | 591 EXPECT_CALL(mock_delegate_, StartSession( |
| 578 _, _, Eq(presentation_url2), Eq(presentation_id2), _, _)) | 592 _, _, Eq(presentation_url2), Eq(presentation_id2), _, _)) |
| 579 .Times(1); | 593 .Times(1); |
| 580 success_cb.Run(PresentationSessionInfo(presentation_url1, presentation_id1)); | 594 success_cb.Run(PresentationSessionInfo(presentation_url1, presentation_id1)); |
| 581 SaveQuitClosureAndRunLoop(); | 595 SaveQuitClosureAndRunLoop(); |
| 582 } | 596 } |
| 583 | 597 |
| 598 TEST_F(PresentationServiceImplTest, SendStringMessage) { |
| 599 std::string presentation_url("http://fooUrl"); |
| 600 std::string presentation_id("presentationId"); |
| 601 std::string message("testMessage"); |
| 602 service_ptr_->SendStringMessage( |
| 603 presentation_url, |
| 604 presentation_id, |
| 605 message, |
| 606 base::Bind( |
| 607 &PresentationServiceImplTest::ExpectSendMessageMojoCallback, |
| 608 base::Unretained(this))); |
| 609 base::RunLoop run_loop; |
| 610 base::Callback<void()> send_message_cb; |
| 611 EXPECT_CALL(mock_delegate_, SendStringMessage( |
| 612 _, _, Eq(presentation_url), Eq(presentation_id), Eq(message), _)) |
| 613 .WillOnce(DoAll( |
| 614 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| 615 SaveArg<5>(&send_message_cb))); |
| 616 run_loop.Run(); |
| 617 send_message_cb.Run(); |
| 618 SaveQuitClosureAndRunLoop(); |
| 619 } |
| 620 |
| 584 } // namespace content | 621 } // namespace content |
| OLD | NEW |