| 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 aa2339cef5ff0b2e0db667d50a0ba04bd017f444..09771d5f58b038c6205983e019cfd50cf4b24795 100644
|
| --- a/content/browser/presentation/presentation_service_impl_unittest.cc
|
| +++ b/content/browser/presentation/presentation_service_impl_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include <stddef.h>
|
| #include <stdint.h>
|
|
|
| +#include <iterator>
|
| #include <memory>
|
| #include <string>
|
| #include <utility>
|
| @@ -19,7 +20,7 @@
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "content/public/browser/navigation_handle.h"
|
| #include "content/public/browser/presentation_service_delegate.h"
|
| -#include "content/public/common/presentation_constants.h"
|
| +#include "content/public/common/presentation_connection_message.h"
|
| #include "content/public/common/presentation_session.h"
|
| #include "content/test/test_render_frame_host.h"
|
| #include "content/test/test_render_view_host.h"
|
| @@ -28,21 +29,19 @@
|
| #include "testing/gmock/include/gmock/gmock.h"
|
|
|
| using ::testing::_;
|
| +using ::testing::ByRef;
|
| using ::testing::Eq;
|
| +using ::testing::Invoke;
|
| using ::testing::InvokeWithoutArgs;
|
| using ::testing::Mock;
|
| using ::testing::Return;
|
| using ::testing::SaveArg;
|
| +using ::testing::WithArgs;
|
|
|
| namespace content {
|
|
|
| namespace {
|
|
|
| -// Matches Mojo structs.
|
| -MATCHER_P(Equals, expected, "") {
|
| - return expected.Equals(arg);
|
| -}
|
| -
|
| // Matches content::PresentationSessionInfo.
|
| MATCHER_P(SessionInfoEquals, expected, "") {
|
| return expected.presentation_url == arg.presentation_url &&
|
| @@ -116,34 +115,25 @@ class MockPresentationServiceDelegate
|
| MOCK_METHOD4(ListenForConnectionMessages,
|
| void(int render_process_id,
|
| int render_frame_id,
|
| - const content::PresentationSessionInfo& session,
|
| + const PresentationSessionInfo& session,
|
| const PresentationConnectionMessageCallback& message_cb));
|
| - MOCK_METHOD5(SendMessageRawPtr,
|
| + MOCK_METHOD5(SendMessage,
|
| void(int render_process_id,
|
| int render_frame_id,
|
| - const content::PresentationSessionInfo& session,
|
| - PresentationConnectionMessage* message_request,
|
| + const PresentationSessionInfo& session,
|
| + const PresentationConnectionMessage& message_request,
|
| const SendMessageCallback& send_message_cb));
|
| - void SendMessage(
|
| - int render_process_id,
|
| - int render_frame_id,
|
| - const content::PresentationSessionInfo& session,
|
| - std::unique_ptr<PresentationConnectionMessage> message_request,
|
| - const SendMessageCallback& send_message_cb) override {
|
| - SendMessageRawPtr(render_process_id, render_frame_id, session,
|
| - message_request.release(), send_message_cb);
|
| - }
|
| - MOCK_METHOD4(ListenForConnectionStateChange,
|
| - void(int render_process_id,
|
| - int render_frame_id,
|
| - const content::PresentationSessionInfo& connection,
|
| - const content::PresentationConnectionStateChangedCallback&
|
| - state_changed_cb));
|
| + MOCK_METHOD4(
|
| + ListenForConnectionStateChange,
|
| + void(int render_process_id,
|
| + int render_frame_id,
|
| + const PresentationSessionInfo& connection,
|
| + const PresentationConnectionStateChangedCallback& state_changed_cb));
|
|
|
| void ConnectToPresentation(
|
| int render_process_id,
|
| int render_frame_id,
|
| - const content::PresentationSessionInfo& session,
|
| + const PresentationSessionInfo& session,
|
| PresentationConnectionPtr controller_conn_ptr,
|
| PresentationConnectionRequest receiver_conn_request) override {
|
| RegisterOffscreenPresentationConnectionRaw(
|
| @@ -153,7 +143,7 @@ class MockPresentationServiceDelegate
|
| MOCK_METHOD4(RegisterOffscreenPresentationConnectionRaw,
|
| void(int render_process_id,
|
| int render_frame_id,
|
| - const content::PresentationSessionInfo& session,
|
| + const PresentationSessionInfo& session,
|
| blink::mojom::PresentationConnection* connection));
|
|
|
| void set_screen_availability_listening_supported(bool value) {
|
| @@ -175,17 +165,14 @@ class MockReceiverPresentationServiceDelegate
|
| void(int render_process_id, int render_frame_id));
|
| MOCK_METHOD2(Reset, void(int render_process_id, int routing_id));
|
| MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback,
|
| - void(const content::ReceiverConnectionAvailableCallback&));
|
| + void(const ReceiverConnectionAvailableCallback&));
|
| };
|
|
|
| class MockPresentationConnection : public blink::mojom::PresentationConnection {
|
| public:
|
| - void OnMessage(blink::mojom::ConnectionMessagePtr message,
|
| - const base::Callback<void(bool)>& send_message_cb) override {
|
| - OnConnectionMessageReceived(*message);
|
| - }
|
| - MOCK_METHOD1(OnConnectionMessageReceived,
|
| - void(const blink::mojom::ConnectionMessage& message));
|
| + MOCK_METHOD2(OnMessage,
|
| + void(const PresentationConnectionMessage& message,
|
| + const base::Callback<void(bool)>& send_message_cb));
|
| MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state));
|
| };
|
|
|
| @@ -195,36 +182,29 @@ class MockPresentationServiceClient
|
| MOCK_METHOD2(OnScreenAvailabilityUpdated,
|
| void(const GURL& url, bool available));
|
| MOCK_METHOD2(OnConnectionStateChanged,
|
| - void(const content::PresentationSessionInfo& connection,
|
| + void(const PresentationSessionInfo& connection,
|
| PresentationConnectionState new_state));
|
| MOCK_METHOD3(OnConnectionClosed,
|
| - void(const content::PresentationSessionInfo& connection,
|
| + void(const PresentationSessionInfo& connection,
|
| PresentationConnectionCloseReason reason,
|
| const std::string& message));
|
| MOCK_METHOD1(OnScreenAvailabilityNotSupported, void(const GURL& url));
|
| -
|
| - void OnConnectionMessagesReceived(
|
| - const content::PresentationSessionInfo& session_info,
|
| - std::vector<blink::mojom::ConnectionMessagePtr> messages) override {
|
| - messages_received_ = std::move(messages);
|
| - MessagesReceived();
|
| - }
|
| - MOCK_METHOD0(MessagesReceived, void());
|
| -
|
| + MOCK_METHOD2(
|
| + OnConnectionMessagesReceived,
|
| + void(const PresentationSessionInfo& session_info,
|
| + const std::vector<PresentationConnectionMessage>& messages));
|
| MOCK_METHOD1(OnDefaultSessionStarted,
|
| - void(const content::PresentationSessionInfo& session_info));
|
| + void(const PresentationSessionInfo& session_info));
|
|
|
| void OnReceiverConnectionAvailable(
|
| - const content::PresentationSessionInfo& session_info,
|
| + const PresentationSessionInfo& session_info,
|
| blink::mojom::PresentationConnectionPtr controller_conn_ptr,
|
| blink::mojom::PresentationConnectionRequest receiver_conn_request)
|
| override {
|
| OnReceiverConnectionAvailable(session_info);
|
| }
|
| MOCK_METHOD1(OnReceiverConnectionAvailable,
|
| - void(const content::PresentationSessionInfo& session_info));
|
| -
|
| - std::vector<blink::mojom::ConnectionMessagePtr> messages_received_;
|
| + void(const PresentationSessionInfo& session_info));
|
| };
|
|
|
| class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| @@ -268,9 +248,8 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| }
|
|
|
| void Navigate(bool main_frame) {
|
| - content::RenderFrameHost* rfh = main_rfh();
|
| - content::RenderFrameHostTester* rfh_tester =
|
| - content::RenderFrameHostTester::For(rfh);
|
| + RenderFrameHost* rfh = main_rfh();
|
| + RenderFrameHostTester* rfh_tester = RenderFrameHostTester::For(rfh);
|
| if (!main_frame)
|
| rfh = rfh_tester->AppendChild("subframe");
|
| std::unique_ptr<NavigationHandle> navigation_handle =
|
| @@ -335,8 +314,8 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| }
|
|
|
| void ExpectNewSessionCallbackSuccess(
|
| - const base::Optional<content::PresentationSessionInfo>& info,
|
| - const base::Optional<content::PresentationError>& error) {
|
| + const base::Optional<PresentationSessionInfo>& info,
|
| + const base::Optional<PresentationError>& error) {
|
| EXPECT_TRUE(info);
|
| EXPECT_FALSE(error);
|
| if (!run_loop_quit_closure_.is_null())
|
| @@ -344,22 +323,14 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| }
|
|
|
| void ExpectNewSessionCallbackError(
|
| - const base::Optional<content::PresentationSessionInfo>& info,
|
| - const base::Optional<content::PresentationError>& error) {
|
| + const base::Optional<PresentationSessionInfo>& info,
|
| + const base::Optional<PresentationError>& error) {
|
| EXPECT_FALSE(info);
|
| EXPECT_TRUE(error);
|
| if (!run_loop_quit_closure_.is_null())
|
| run_loop_quit_closure_.Run();
|
| }
|
|
|
| - void ExpectConnectionMessages(
|
| - const std::vector<blink::mojom::ConnectionMessagePtr>& expected_msgs,
|
| - const std::vector<blink::mojom::ConnectionMessagePtr>& actual_msgs) {
|
| - EXPECT_EQ(expected_msgs.size(), actual_msgs.size());
|
| - for (size_t i = 0; i < actual_msgs.size(); ++i)
|
| - EXPECT_TRUE(expected_msgs[i].Equals(actual_msgs[i]));
|
| - }
|
| -
|
| void ExpectSendConnectionMessageCallback(bool success) {
|
| EXPECT_TRUE(success);
|
| EXPECT_FALSE(service_impl_->send_message_callback_);
|
| @@ -367,52 +338,6 @@ class PresentationServiceImplTest : public RenderViewHostImplTestHarness {
|
| run_loop_quit_closure_.Run();
|
| }
|
|
|
| - void RunListenForConnectionMessages(const std::string& text_msg,
|
| - const std::vector<uint8_t>& binary_data,
|
| - bool pass_ownership) {
|
| - std::vector<blink::mojom::ConnectionMessagePtr> expected_msgs(2);
|
| - expected_msgs[0] = blink::mojom::ConnectionMessage::New();
|
| - expected_msgs[0]->type = blink::mojom::PresentationMessageType::TEXT;
|
| - expected_msgs[0]->message = text_msg;
|
| - expected_msgs[1] = blink::mojom::ConnectionMessage::New();
|
| - expected_msgs[1]->type = blink::mojom::PresentationMessageType::BINARY;
|
| - expected_msgs[1]->data = binary_data;
|
| -
|
| - content::PresentationSessionInfo session(presentation_url1_,
|
| - kPresentationId);
|
| -
|
| - PresentationConnectionMessageCallback message_cb;
|
| - {
|
| - base::RunLoop run_loop;
|
| - EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _))
|
| - .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
|
| - SaveArg<3>(&message_cb)));
|
| - service_ptr_->ListenForConnectionMessages(session);
|
| - run_loop.Run();
|
| - }
|
| -
|
| - std::vector<std::unique_ptr<PresentationConnectionMessage>> messages;
|
| - std::unique_ptr<content::PresentationConnectionMessage> message;
|
| - message.reset(new content::PresentationConnectionMessage(
|
| - PresentationMessageType::TEXT));
|
| - message->message = text_msg;
|
| - messages.push_back(std::move(message));
|
| - message.reset(new content::PresentationConnectionMessage(
|
| - PresentationMessageType::BINARY));
|
| - message->data.reset(new std::vector<uint8_t>(binary_data));
|
| - messages.push_back(std::move(message));
|
| -
|
| - std::vector<blink::mojom::ConnectionMessagePtr> actual_msgs;
|
| - {
|
| - base::RunLoop run_loop;
|
| - EXPECT_CALL(mock_client_, MessagesReceived())
|
| - .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
|
| - message_cb.Run(std::move(messages), pass_ownership);
|
| - run_loop.Run();
|
| - }
|
| - ExpectConnectionMessages(expected_msgs, mock_client_.messages_received_);
|
| - }
|
| -
|
| MockPresentationServiceDelegate mock_delegate_;
|
| MockReceiverPresentationServiceDelegate mock_receiver_delegate_;
|
|
|
| @@ -505,31 +430,28 @@ TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrls) {
|
| std::vector<GURL> more_urls = presentation_urls_;
|
| more_urls.push_back(presentation_url3_);
|
|
|
| - content::PresentationSessionStartedCallback callback;
|
| + PresentationSessionStartedCallback callback;
|
| EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _, more_urls, _))
|
| .WillOnce(SaveArg<3>(&callback));
|
| service_impl_->SetDefaultPresentationUrls(more_urls);
|
|
|
| - content::PresentationSessionInfo session_info(presentation_url2_,
|
| - kPresentationId);
|
| + PresentationSessionInfo session_info(presentation_url2_, kPresentationId);
|
|
|
| base::RunLoop run_loop;
|
| EXPECT_CALL(mock_client_,
|
| OnDefaultSessionStarted(SessionInfoEquals(session_info)))
|
| .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
|
| EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _));
|
| - callback.Run(
|
| - content::PresentationSessionInfo(presentation_url2_, kPresentationId));
|
| + callback.Run(PresentationSessionInfo(presentation_url2_, kPresentationId));
|
| run_loop.Run();
|
| }
|
|
|
| TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
|
| - content::PresentationSessionInfo connection(presentation_url1_,
|
| - kPresentationId);
|
| - content::PresentationConnectionStateChangedCallback state_changed_cb;
|
| + PresentationSessionInfo connection(presentation_url1_, kPresentationId);
|
| + PresentationConnectionStateChangedCallback state_changed_cb;
|
| // Trigger state change. It should be propagated back up to |mock_client_|.
|
| - content::PresentationSessionInfo presentation_connection(presentation_url1_,
|
| - kPresentationId);
|
| + PresentationSessionInfo presentation_connection(presentation_url1_,
|
| + kPresentationId);
|
|
|
| EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
|
| .WillOnce(SaveArg<3>(&state_changed_cb));
|
| @@ -537,10 +459,10 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
|
|
|
| {
|
| base::RunLoop run_loop;
|
| - EXPECT_CALL(mock_client_,
|
| - OnConnectionStateChanged(
|
| - SessionInfoEquals(presentation_connection),
|
| - content::PRESENTATION_CONNECTION_STATE_TERMINATED))
|
| + EXPECT_CALL(
|
| + mock_client_,
|
| + OnConnectionStateChanged(SessionInfoEquals(presentation_connection),
|
| + PRESENTATION_CONNECTION_STATE_TERMINATED))
|
| .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
|
| state_changed_cb.Run(PresentationConnectionStateChangeInfo(
|
| PRESENTATION_CONNECTION_STATE_TERMINATED));
|
| @@ -549,17 +471,16 @@ TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) {
|
| }
|
|
|
| TEST_F(PresentationServiceImplTest, ListenForConnectionClose) {
|
| - content::PresentationSessionInfo connection(presentation_url1_,
|
| - kPresentationId);
|
| - content::PresentationConnectionStateChangedCallback state_changed_cb;
|
| + PresentationSessionInfo connection(presentation_url1_, kPresentationId);
|
| + PresentationConnectionStateChangedCallback state_changed_cb;
|
| EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _))
|
| .WillOnce(SaveArg<3>(&state_changed_cb));
|
| service_impl_->ListenForConnectionStateChange(connection);
|
|
|
| // Trigger connection close. It should be propagated back up to
|
| // |mock_client_|.
|
| - content::PresentationSessionInfo presentation_connection(presentation_url1_,
|
| - kPresentationId);
|
| + PresentationSessionInfo presentation_connection(presentation_url1_,
|
| + kPresentationId);
|
| {
|
| base::RunLoop run_loop;
|
| PresentationConnectionStateChangeInfo closed_info(
|
| @@ -674,26 +595,8 @@ TEST_F(PresentationServiceImplTest, Terminate) {
|
| run_loop.Run();
|
| }
|
|
|
| -TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesPassed) {
|
| - std::string text_msg("123");
|
| - std::vector<uint8_t> binary_data(3, '\1');
|
| - RunListenForConnectionMessages(text_msg, binary_data, true);
|
| -}
|
| -
|
| -TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesCopied) {
|
| - std::string text_msg("123");
|
| - std::vector<uint8_t> binary_data(3, '\1');
|
| - RunListenForConnectionMessages(text_msg, binary_data, false);
|
| -}
|
| -
|
| -TEST_F(PresentationServiceImplTest, ListenForConnectionMessagesWithEmptyMsg) {
|
| - std::string text_msg("");
|
| - std::vector<uint8_t> binary_data;
|
| - RunListenForConnectionMessages(text_msg, binary_data, false);
|
| -}
|
| -
|
| TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
|
| - content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| + PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
|
|
| blink::mojom::PresentationConnectionPtr connection;
|
| MockPresentationConnection mock_presentation_connection;
|
| @@ -702,8 +605,7 @@ TEST_F(PresentationServiceImplTest, SetPresentationConnection) {
|
| blink::mojom::PresentationConnectionPtr receiver_connection;
|
| auto request = mojo::MakeRequest(&receiver_connection);
|
|
|
| - content::PresentationSessionInfo expected(presentation_url1_,
|
| - kPresentationId);
|
| + PresentationSessionInfo expected(presentation_url1_, kPresentationId);
|
| EXPECT_CALL(mock_delegate_, RegisterOffscreenPresentationConnectionRaw(
|
| _, _, SessionInfoEquals(expected), _));
|
|
|
| @@ -733,7 +635,7 @@ TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
|
| // NO-OP for ControllerPresentationServiceDelegate API functions
|
| EXPECT_CALL(mock_delegate_, ListenForConnectionMessages(_, _, _, _)).Times(0);
|
|
|
| - content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| + PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| service_impl.ListenForConnectionMessages(session);
|
| }
|
|
|
| @@ -752,37 +654,25 @@ TEST_F(PresentationServiceImplTest, StartSessionInProgress) {
|
| }
|
|
|
| TEST_F(PresentationServiceImplTest, SendStringMessage) {
|
| - std::string message("Test presentation session message");
|
| + PresentationConnectionMessage message("Test presentation session message");
|
|
|
| - content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| - blink::mojom::ConnectionMessagePtr message_request(
|
| - blink::mojom::ConnectionMessage::New());
|
| - message_request->type = blink::mojom::PresentationMessageType::TEXT;
|
| - message_request->message = message;
|
| + PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| service_ptr_->SendConnectionMessage(
|
| - session, std::move(message_request),
|
| + session, message,
|
| base::Bind(
|
| &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
|
| base::Unretained(this)));
|
|
|
| base::RunLoop run_loop;
|
| - base::Callback<void(bool)> send_message_cb;
|
| - PresentationConnectionMessage* test_message = nullptr;
|
| - EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
|
| - .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
|
| - SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
|
| + EXPECT_CALL(mock_delegate_, SendMessage(_, _, _, _, _))
|
| + .WillOnce(DoAll(WithArgs<3, 4>(Invoke([&message](
|
| + const PresentationConnectionMessage& message_request,
|
| + const base::Callback<void(bool)>& send_message_cb) {
|
| + EXPECT_EQ(message, message_request);
|
| + send_message_cb.Run(true);
|
| + })),
|
| + InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)));
|
| run_loop.Run();
|
| -
|
| - // Make sure |test_message| gets deleted.
|
| - std::unique_ptr<PresentationConnectionMessage> scoped_test_message(
|
| - test_message);
|
| - EXPECT_TRUE(test_message);
|
| - EXPECT_FALSE(test_message->is_binary());
|
| - EXPECT_LE(test_message->message.size(),
|
| - kMaxPresentationConnectionMessageSize);
|
| - EXPECT_EQ(message, test_message->message);
|
| - ASSERT_FALSE(test_message->data);
|
| - send_message_cb.Run(true);
|
| SaveQuitClosureAndRunLoop();
|
| }
|
|
|
| @@ -791,71 +681,25 @@ TEST_F(PresentationServiceImplTest, SendArrayBuffer) {
|
| const uint8_t buffer[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
|
| std::vector<uint8_t> data;
|
| data.assign(buffer, buffer + sizeof(buffer));
|
| + PresentationConnectionMessage message(data);
|
|
|
| - content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| - blink::mojom::ConnectionMessagePtr message_request(
|
| - blink::mojom::ConnectionMessage::New());
|
| - message_request->type = blink::mojom::PresentationMessageType::BINARY;
|
| - message_request->data = data;
|
| + PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| service_ptr_->SendConnectionMessage(
|
| - session, std::move(message_request),
|
| + session, message,
|
| base::Bind(
|
| &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
|
| base::Unretained(this)));
|
|
|
| base::RunLoop run_loop;
|
| - base::Callback<void(bool)> send_message_cb;
|
| - PresentationConnectionMessage* test_message = nullptr;
|
| - EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
|
| - .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
|
| - SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
|
| + EXPECT_CALL(mock_delegate_, SendMessage(_, _, _, _, _))
|
| + .WillOnce(DoAll(WithArgs<3, 4>(Invoke([&message](
|
| + const PresentationConnectionMessage& message_request,
|
| + const base::Callback<void(bool)>& send_message_cb) {
|
| + EXPECT_EQ(message, message_request);
|
| + send_message_cb.Run(true);
|
| + })),
|
| + InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)));
|
| run_loop.Run();
|
| -
|
| - // Make sure |test_message| gets deleted.
|
| - std::unique_ptr<PresentationConnectionMessage> scoped_test_message(
|
| - test_message);
|
| - EXPECT_TRUE(test_message);
|
| - EXPECT_TRUE(test_message->is_binary());
|
| - EXPECT_EQ(PresentationMessageType::BINARY, test_message->type);
|
| - EXPECT_TRUE(test_message->message.empty());
|
| - ASSERT_TRUE(test_message->data);
|
| - EXPECT_EQ(data.size(), test_message->data->size());
|
| - EXPECT_LE(test_message->data->size(), kMaxPresentationConnectionMessageSize);
|
| - EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
|
| - send_message_cb.Run(true);
|
| - SaveQuitClosureAndRunLoop();
|
| -}
|
| -
|
| -TEST_F(PresentationServiceImplTest, SendArrayBufferWithExceedingLimit) {
|
| - // Create buffer with size exceeding the limit.
|
| - // Use same size as in content::kMaxPresentationConnectionMessageSize.
|
| - const size_t kMaxBufferSizeInBytes = 64 * 1024; // 64 KB.
|
| - uint8_t buffer[kMaxBufferSizeInBytes + 1];
|
| - memset(buffer, 0, kMaxBufferSizeInBytes+1);
|
| - std::vector<uint8_t> data;
|
| - data.assign(buffer, buffer + sizeof(buffer));
|
| -
|
| - content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| - blink::mojom::ConnectionMessagePtr message_request(
|
| - blink::mojom::ConnectionMessage::New());
|
| - message_request->type = blink::mojom::PresentationMessageType::BINARY;
|
| - message_request->data = data;
|
| - service_ptr_->SendConnectionMessage(
|
| - session, std::move(message_request),
|
| - base::Bind(
|
| - &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
|
| - base::Unretained(this)));
|
| -
|
| - base::RunLoop run_loop;
|
| - base::Callback<void(bool)> send_message_cb;
|
| - PresentationConnectionMessage* test_message = nullptr;
|
| - EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
|
| - .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
|
| - SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
|
| - run_loop.Run();
|
| -
|
| - EXPECT_FALSE(test_message);
|
| - send_message_cb.Run(true);
|
| SaveQuitClosureAndRunLoop();
|
| }
|
|
|
| @@ -864,37 +708,24 @@ TEST_F(PresentationServiceImplTest, SendBlobData) {
|
| std::vector<uint8_t> data;
|
| data.assign(buffer, buffer + sizeof(buffer));
|
|
|
| - content::PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| - blink::mojom::ConnectionMessagePtr message_request(
|
| - blink::mojom::ConnectionMessage::New());
|
| - message_request->type = blink::mojom::PresentationMessageType::BINARY;
|
| - message_request->data = data;
|
| + PresentationSessionInfo session(presentation_url1_, kPresentationId);
|
| + PresentationConnectionMessage message(data);
|
| service_ptr_->SendConnectionMessage(
|
| - session, std::move(message_request),
|
| + session, message,
|
| base::Bind(
|
| &PresentationServiceImplTest::ExpectSendConnectionMessageCallback,
|
| base::Unretained(this)));
|
|
|
| base::RunLoop run_loop;
|
| - base::Callback<void(bool)> send_message_cb;
|
| - PresentationConnectionMessage* test_message = nullptr;
|
| - EXPECT_CALL(mock_delegate_, SendMessageRawPtr(_, _, _, _, _))
|
| - .WillOnce(DoAll(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit),
|
| - SaveArg<3>(&test_message), SaveArg<4>(&send_message_cb)));
|
| + EXPECT_CALL(mock_delegate_, SendMessage(_, _, _, _, _))
|
| + .WillOnce(DoAll(WithArgs<3, 4>(Invoke([&message](
|
| + const PresentationConnectionMessage& message_request,
|
| + const base::Callback<void(bool)>& send_message_cb) {
|
| + EXPECT_EQ(message, message_request);
|
| + send_message_cb.Run(true);
|
| + })),
|
| + InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)));
|
| run_loop.Run();
|
| -
|
| - // Make sure |test_message| gets deleted.
|
| - std::unique_ptr<PresentationConnectionMessage> scoped_test_message(
|
| - test_message);
|
| - EXPECT_TRUE(test_message);
|
| - EXPECT_TRUE(test_message->is_binary());
|
| - EXPECT_EQ(PresentationMessageType::BINARY, test_message->type);
|
| - EXPECT_TRUE(test_message->message.empty());
|
| - ASSERT_TRUE(test_message->data);
|
| - EXPECT_EQ(data.size(), test_message->data->size());
|
| - EXPECT_LE(test_message->data->size(), kMaxPresentationConnectionMessageSize);
|
| - EXPECT_EQ(0, memcmp(buffer, &(*test_message->data)[0], sizeof(buffer)));
|
| - send_message_cb.Run(true);
|
| SaveQuitClosureAndRunLoop();
|
| }
|
|
|
|
|