Chromium Code Reviews| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 const PresentationSessionSuccessCallback& success_cb, | 81 const PresentationSessionSuccessCallback& success_cb, |
| 82 const PresentationSessionErrorCallback& error_cb)); | 82 const PresentationSessionErrorCallback& error_cb)); |
| 83 MOCK_METHOD6(JoinSession, | 83 MOCK_METHOD6(JoinSession, |
| 84 void( | 84 void( |
| 85 int render_process_id, | 85 int render_process_id, |
| 86 int render_frame_id, | 86 int render_frame_id, |
| 87 const std::string& presentation_url, | 87 const std::string& presentation_url, |
| 88 const std::string& presentation_id, | 88 const std::string& presentation_id, |
| 89 const PresentationSessionSuccessCallback& success_cb, | 89 const PresentationSessionSuccessCallback& success_cb, |
| 90 const PresentationSessionErrorCallback& error_cb)); | 90 const PresentationSessionErrorCallback& error_cb)); |
| 91 | |
| 91 MOCK_METHOD3(ListenForSessionMessages, | 92 MOCK_METHOD3(ListenForSessionMessages, |
| 92 void( | 93 void( |
| 93 int render_process_id, | 94 int render_process_id, |
| 94 int render_frame_id, | 95 int render_frame_id, |
| 95 const PresentationSessionMessageCallback& message_cb)); | 96 const PresentationSessionMessageCallback& message_cb)); |
| 97 | |
| 98 MOCK_METHOD4(SendMessageRawPtr, | |
| 99 void( | |
| 100 int render_process_id, | |
| 101 int render_frame_id, | |
| 102 PresentationSessionMessage* message_request, | |
| 103 const SendMessageCallback& send_message_cb)); | |
| 104 | |
| 105 void SendMessage( | |
| 106 int render_process_id, | |
| 107 int render_frame_id, | |
| 108 scoped_ptr<PresentationSessionMessage> message_request, | |
| 109 const SendMessageCallback& send_message_cb) { | |
| 110 DCHECK(message_request); | |
| 111 SendMessageRawPtr( | |
| 112 render_process_id, | |
| 113 render_frame_id, | |
| 114 message_request.release(), | |
| 115 send_message_cb); | |
| 116 } | |
| 96 }; | 117 }; |
| 97 | 118 |
| 98 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { | 119 class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| 99 public: | 120 public: |
| 100 PresentationServiceImplTest() | 121 PresentationServiceImplTest() |
| 101 : callback_count_(0), default_session_started_count_(0) {} | 122 : callback_count_(0), default_session_started_count_(0) {} |
| 102 | 123 |
| 103 void SetUp() override { | 124 void SetUp() override { |
| 104 RenderViewHostImplTestHarness::SetUp(); | 125 RenderViewHostImplTestHarness::SetUp(); |
| 105 | 126 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 mojo::Array<presentation::SessionMessagePtr> actual_msgs) { | 257 mojo::Array<presentation::SessionMessagePtr> actual_msgs) { |
| 237 EXPECT_TRUE(actual_msgs.size() == expected_msgs_.size()); | 258 EXPECT_TRUE(actual_msgs.size() == expected_msgs_.size()); |
| 238 for (size_t i = 0; i < actual_msgs.size(); ++i) { | 259 for (size_t i = 0; i < actual_msgs.size(); ++i) { |
| 239 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs_[i].get(), | 260 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_msgs_[i].get(), |
| 240 actual_msgs[i].get())); | 261 actual_msgs[i].get())); |
| 241 } | 262 } |
| 242 if (!run_loop_quit_closure_.is_null()) | 263 if (!run_loop_quit_closure_.is_null()) |
| 243 run_loop_quit_closure_.Run(); | 264 run_loop_quit_closure_.Run(); |
| 244 } | 265 } |
| 245 | 266 |
| 267 void ExpectSendMessageMojoCallback(bool success) { | |
| 268 EXPECT_TRUE(success); | |
| 269 EXPECT_FALSE(service_impl_->send_message_cb_ptr_); | |
| 270 if (!run_loop_quit_closure_.is_null()) | |
| 271 run_loop_quit_closure_.Run(); | |
| 272 } | |
| 273 | |
| 246 void RunListenForSessionMessages(std::string& text_msg, | 274 void RunListenForSessionMessages(std::string& text_msg, |
| 247 std::vector<uint8_t>& binary_data) { | 275 std::vector<uint8_t>& binary_data) { |
| 248 std::string presentation_url("http://fooUrl"); | 276 std::string presentation_url("http://fooUrl"); |
| 249 std::string presentation_id("presentationId"); | 277 std::string presentation_id("presentationId"); |
| 250 | 278 |
| 251 expected_msgs_ = mojo::Array<presentation::SessionMessagePtr>::New(2); | 279 expected_msgs_ = mojo::Array<presentation::SessionMessagePtr>::New(2); |
| 252 expected_msgs_[0] = presentation::SessionMessage::New(); | 280 expected_msgs_[0] = presentation::SessionMessage::New(); |
| 253 expected_msgs_[0]->presentation_url = presentation_url; | 281 expected_msgs_[0]->presentation_url = presentation_url; |
| 254 expected_msgs_[0]->presentation_id = presentation_id; | 282 expected_msgs_[0]->presentation_id = presentation_id; |
| 255 expected_msgs_[0]->type = | 283 expected_msgs_[0]->type = |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 base::Unretained(this))); | 804 base::Unretained(this))); |
| 777 RunLoopFor(TestTimeouts::tiny_timeout()); | 805 RunLoopFor(TestTimeouts::tiny_timeout()); |
| 778 | 806 |
| 779 ExpectReset(); | 807 ExpectReset(); |
| 780 service_impl_->Reset(); | 808 service_impl_->Reset(); |
| 781 ExpectCleanState(); | 809 ExpectCleanState(); |
| 782 SaveQuitClosureAndRunLoop(); | 810 SaveQuitClosureAndRunLoop(); |
| 783 EXPECT_EQ(1, default_session_started_count_); | 811 EXPECT_EQ(1, default_session_started_count_); |
| 784 } | 812 } |
| 785 | 813 |
| 814 TEST_F(PresentationServiceImplTest, SendStringMessage) { | |
| 815 std::string presentation_url("http://fooUrl"); | |
|
mark a. foltz
2015/05/07 01:34:30
Nit: Please use a proper URL with a TLD.
USE s.singapati at gmail.com
2015/05/07 14:08:52
Done.
| |
| 816 std::string presentation_id("presentationId"); | |
| 817 std::string message("Test presentation session message"); | |
| 818 | |
| 819 presentation::SessionMessagePtr message_request( | |
| 820 presentation::SessionMessage::New()); | |
| 821 message_request->presentation_url = presentation_url; | |
| 822 message_request->presentation_id = presentation_id; | |
| 823 message_request->type = presentation::PresentationMessageType:: | |
| 824 PRESENTATION_MESSAGE_TYPE_TEXT; | |
| 825 message_request->message = message; | |
| 826 service_ptr_->SendMessage( | |
| 827 message_request.Pass(), | |
| 828 base::Bind( | |
| 829 &PresentationServiceImplTest::ExpectSendMessageMojoCallback, | |
| 830 base::Unretained(this))); | |
| 831 | |
| 832 base::RunLoop run_loop; | |
| 833 base::Closure send_message_cb; | |
| 834 PresentationSessionMessage* test_message = nullptr; | |
| 835 EXPECT_CALL(mock_delegate_, SendMessageRawPtr( | |
| 836 _, _, _, _)) | |
| 837 .WillOnce(DoAll( | |
| 838 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | |
| 839 SaveArg<2>(&test_message), | |
| 840 SaveArg<3>(&send_message_cb))); | |
| 841 run_loop.Run(); | |
| 842 | |
| 843 EXPECT_TRUE(test_message); | |
| 844 EXPECT_EQ(presentation_url, test_message->presentation_url); | |
| 845 EXPECT_EQ(presentation_id, test_message->presentation_id); | |
| 846 EXPECT_FALSE(test_message->is_binary()); | |
| 847 EXPECT_EQ(message, *(test_message->message.get())); | |
| 848 EXPECT_FALSE(test_message->data); | |
| 849 delete test_message; | |
| 850 send_message_cb.Run(); | |
| 851 SaveQuitClosureAndRunLoop(); | |
| 852 } | |
| 853 | |
| 854 TEST_F(PresentationServiceImplTest, SendArrayBuffer) { | |
| 855 std::string presentation_url("http://fooUrl"); | |
|
mark a. foltz
2015/05/07 01:34:30
Ditto
USE s.singapati at gmail.com
2015/05/07 14:08:52
Done.
| |
| 856 std::string presentation_id("presentationId"); | |
| 857 // Test Array buffer data. | |
| 858 const uint8 buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; | |
| 859 std::vector<uint8> data; | |
| 860 data.assign(buffer, buffer + sizeof(buffer)); | |
| 861 | |
| 862 presentation::SessionMessagePtr message_request( | |
| 863 presentation::SessionMessage::New()); | |
| 864 message_request->presentation_url = presentation_url; | |
| 865 message_request->presentation_id = presentation_id; | |
| 866 message_request->type = presentation::PresentationMessageType:: | |
| 867 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
| 868 message_request->data = mojo::Array<uint8>::From(data); | |
| 869 service_ptr_->SendMessage( | |
| 870 message_request.Pass(), | |
| 871 base::Bind( | |
| 872 &PresentationServiceImplTest::ExpectSendMessageMojoCallback, | |
| 873 base::Unretained(this))); | |
| 874 | |
| 875 base::RunLoop run_loop; | |
| 876 base::Closure send_message_cb; | |
| 877 PresentationSessionMessage* test_message = nullptr; | |
| 878 EXPECT_CALL(mock_delegate_, SendMessageRawPtr( | |
| 879 _, _, _, _)) | |
| 880 .WillOnce(DoAll( | |
| 881 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit), | |
| 882 SaveArg<2>(&test_message), | |
| 883 SaveArg<3>(&send_message_cb))); | |
| 884 run_loop.Run(); | |
| 885 | |
| 886 EXPECT_TRUE(test_message); | |
| 887 EXPECT_EQ(presentation_url, test_message->presentation_url); | |
| 888 EXPECT_EQ(presentation_id, test_message->presentation_id); | |
| 889 EXPECT_TRUE(test_message->is_binary()); | |
| 890 EXPECT_FALSE(test_message->message); | |
| 891 EXPECT_EQ(data.size(), test_message->data.get()->size()); | |
| 892 EXPECT_EQ(0, memcmp(buffer, &(*test_message->data.get())[0], sizeof(buffer))); | |
| 893 delete test_message; | |
| 894 send_message_cb.Run(); | |
| 895 SaveQuitClosureAndRunLoop(); | |
| 896 } | |
| 897 | |
| 786 } // namespace content | 898 } // namespace content |
| OLD | NEW |