Chromium Code Reviews| Index: content/browser/presentation/presentation_service_impl_unittest.cc |
| diff --git a/content/browser/presentation/presentation_service_impl_unittest.cc b/content/browser/presentation/presentation_service_impl_unittest.cc |
| index 2f2525667ed51ecfe4e920cd595bb8e4f64468f7..98986e7718543fb4afa56fdab2e83180ce76c767 100644 |
| --- a/content/browser/presentation/presentation_service_impl_unittest.cc |
| +++ b/content/browser/presentation/presentation_service_impl_unittest.cc |
| @@ -31,6 +31,17 @@ bool ArePresentationSessionsEqual( |
| const presentation::PresentationSessionInfo& actual) { |
| return expected.url == actual.url && expected.id == actual.id; |
| } |
| + |
| +bool ArePresentationSessionMessagesEqual( |
| + const presentation::SessionMessage* expected, |
| + const presentation::SessionMessage* actual) { |
| + return expected->presentation_url == actual->presentation_url && |
| + expected->presentation_id == actual->presentation_id && |
| + expected->type == actual->type && |
| + expected->message == actual->message && |
| + expected->data.Equals(actual->data); |
| +} |
| + |
| } // namespace |
| class MockPresentationServiceDelegate : public PresentationServiceDelegate { |
| @@ -77,6 +88,10 @@ class MockPresentationServiceDelegate : public PresentationServiceDelegate { |
| const std::string& presentation_id, |
| const PresentationSessionSuccessCallback& success_cb, |
| const PresentationSessionErrorCallback& error_cb)); |
| + MOCK_METHOD3(ListenForSessionMessages, |
| + void(int render_process_id, |
| + int render_frame_id, |
| + const PresentationSessionMessageCallback& message_cb)); |
| }; |
| class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| @@ -215,12 +230,25 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| run_loop_quit_closure_.Run(); |
| } |
| + void ExpectSessionMessages( |
| + mojo::Array<presentation::SessionMessagePtr> actual_msgs) { |
| + EXPECT_TRUE(!actual_msgs.is_null()); |
| + EXPECT_TRUE(actual_msgs.size() == expected_msgs_.size()); |
| + for (size_t i = 0; i < actual_msgs.size(); ++i) { |
| + EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs_[i].get(), |
| + actual_msgs[i].get())); |
| + } |
| + if (!run_loop_quit_closure_.is_null()) |
| + run_loop_quit_closure_.Run(); |
| + } |
| + |
| MockPresentationServiceDelegate mock_delegate_; |
| scoped_ptr<PresentationServiceImpl> service_impl_; |
| mojo::InterfacePtr<presentation::PresentationService> service_ptr_; |
| base::Closure run_loop_quit_closure_; |
| int callback_count_; |
| int default_session_started_count_; |
| + mojo::Array<presentation::SessionMessagePtr> expected_msgs_; |
| }; |
| TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { |
| @@ -578,6 +606,50 @@ TEST_F(PresentationServiceImplTest, JoinSessionError) { |
| SaveQuitClosureAndRunLoop(); |
| } |
| +TEST_F(PresentationServiceImplTest, ListenForSessionMessages) { |
| + std::string presentation_url("http://fooUrl"); |
| + std::string presentation_id("presentationId"); |
| + std::string text_msg("123"); |
| + std::vector<uint8_t> binary_data{'\1', '\2', '\3'}; |
| + |
| + expected_msgs_ = mojo::Array<presentation::SessionMessagePtr>::New(2); |
| + expected_msgs_[0] = presentation::SessionMessage::New(); |
| + expected_msgs_[0]->presentation_url = presentation_url; |
| + expected_msgs_[0]->presentation_id = presentation_id; |
| + expected_msgs_[0]->type = |
| + presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; |
| + expected_msgs_[0]->message = text_msg; |
| + expected_msgs_[1] = presentation::SessionMessage::New(); |
| + expected_msgs_[1]->presentation_url = presentation_url; |
| + expected_msgs_[1]->presentation_id = presentation_id; |
| + expected_msgs_[1]->type = presentation::PresentationMessageType:: |
| + PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
| + expected_msgs_[1]->data = mojo::Array<uint8_t>::From(binary_data); |
| + |
| + service_ptr_->ListenForSessionMessages( |
| + base::Bind(&PresentationServiceImplTest::ExpectSessionMessages, |
| + base::Unretained(this))); |
| + |
| + base::RunLoop run_loop; |
| + base::Callback<void(scoped_ptr<ScopedVector<PresentationSessionMessage>>)> |
| + message_cb; |
| + EXPECT_CALL(mock_delegate_, ListenForSessionMessages(_, _, _)) |
| + .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), |
| + SaveArg<2>(&message_cb))); |
| + run_loop.Run(); |
| + |
| + scoped_ptr<ScopedVector<PresentationSessionMessage>> messages( |
| + new ScopedVector<PresentationSessionMessage>()); |
| + messages->push_back(new content::PresentationSessionMessage( |
| + presentation_url, presentation_id, |
| + scoped_ptr<std::string>(new std::string(text_msg)))); |
| + messages->push_back(new content::PresentationSessionMessage( |
| + presentation_url, presentation_id, |
| + scoped_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>(binary_data)))); |
| + message_cb.Run(messages.Pass()); |
| + SaveQuitClosureAndRunLoop(); |
| +} |
|
mark a. foltz
2015/05/01 19:42:07
Would be a good idea to test:
- Reset() runs the s
haibinlu
2015/05/02 00:32:55
Done. Now DCHECK multiple listen, thus this case i
|
| + |
| TEST_F(PresentationServiceImplTest, StartSessionInProgress) { |
| std::string presentation_url1("http://fooUrl"); |
| std::string presentation_id1("presentationId1"); |