| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "content/renderer/presentation/presentation_connection_proxy.h" | 10 #include "content/renderer/presentation/presentation_connection_proxy.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 std::unique_ptr<TestPresentationConnection> receiver_connection_; | 64 std::unique_ptr<TestPresentationConnection> receiver_connection_; |
| 65 ControllerConnectionProxy* controller_connection_proxy_; | 65 ControllerConnectionProxy* controller_connection_proxy_; |
| 66 ReceiverConnectionProxy* receiver_connection_proxy_; | 66 ReceiverConnectionProxy* receiver_connection_proxy_; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 content::TestBrowserThreadBundle thread_bundle_; | 69 content::TestBrowserThreadBundle thread_bundle_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST_F(PresentationConnectionProxyTest, TestSendString) { | 72 TEST_F(PresentationConnectionProxyTest, TestSendString) { |
| 73 blink::WebString message = blink::WebString::fromUTF8("test message"); | 73 blink::WebString message = blink::WebString::fromUTF8("test message"); |
| 74 blink::mojom::ConnectionMessagePtr session_message = | |
| 75 blink::mojom::ConnectionMessage::New(); | |
| 76 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
| 77 session_message->message = message.utf8(); | |
| 78 | |
| 79 base::RunLoop run_loop; | 74 base::RunLoop run_loop; |
| 80 EXPECT_CALL(*receiver_connection_, didReceiveTextMessage(message)); | 75 EXPECT_CALL(*receiver_connection_, didReceiveTextMessage(message)); |
| 81 controller_connection_proxy_->SendConnectionMessage( | 76 controller_connection_proxy_->SendConnectionMessage( |
| 82 std::move(session_message), | 77 PresentationConnectionMessage(message.utf8()), |
| 83 base::Bind( | 78 base::Bind( |
| 84 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, | 79 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, |
| 85 base::Unretained(this))); | 80 base::Unretained(this))); |
| 86 run_loop.RunUntilIdle(); | 81 run_loop.RunUntilIdle(); |
| 87 } | 82 } |
| 88 | 83 |
| 89 TEST_F(PresentationConnectionProxyTest, TestSendArrayBuffer) { | 84 TEST_F(PresentationConnectionProxyTest, TestSendArrayBuffer) { |
| 90 std::vector<uint8_t> expected_data; | 85 std::vector<uint8_t> expected_data; |
| 91 expected_data.push_back(42); | 86 expected_data.push_back(42); |
| 92 expected_data.push_back(36); | 87 expected_data.push_back(36); |
| 93 | 88 |
| 94 blink::mojom::ConnectionMessagePtr session_message = | |
| 95 blink::mojom::ConnectionMessage::New(); | |
| 96 session_message->type = blink::mojom::PresentationMessageType::BINARY; | |
| 97 session_message->data = expected_data; | |
| 98 | |
| 99 base::RunLoop run_loop; | 89 base::RunLoop run_loop; |
| 100 EXPECT_CALL(*receiver_connection_, didReceiveBinaryMessage(_, _)) | 90 EXPECT_CALL(*receiver_connection_, didReceiveBinaryMessage(_, _)) |
| 101 .WillOnce(::testing::Invoke( | 91 .WillOnce(::testing::Invoke( |
| 102 [&expected_data](const uint8_t* data, size_t length) { | 92 [&expected_data](const uint8_t* data, size_t length) { |
| 103 std::vector<uint8_t> message_data(data, data + length); | 93 std::vector<uint8_t> message_data(data, data + length); |
| 104 EXPECT_EQ(expected_data, message_data); | 94 EXPECT_EQ(expected_data, message_data); |
| 105 })); | 95 })); |
| 106 | 96 |
| 107 controller_connection_proxy_->SendConnectionMessage( | 97 controller_connection_proxy_->SendConnectionMessage( |
| 108 std::move(session_message), | 98 PresentationConnectionMessage(expected_data), |
| 109 base::Bind( | 99 base::Bind( |
| 110 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, | 100 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, |
| 111 base::Unretained(this))); | 101 base::Unretained(this))); |
| 112 run_loop.RunUntilIdle(); | 102 run_loop.RunUntilIdle(); |
| 113 } | 103 } |
| 114 | 104 |
| 115 TEST_F(PresentationConnectionProxyTest, TestControllerConnectionCallsClose) { | 105 TEST_F(PresentationConnectionProxyTest, TestControllerConnectionCallsClose) { |
| 116 base::RunLoop run_loop; | 106 base::RunLoop run_loop; |
| 117 EXPECT_CALL(*controller_connection_, | 107 EXPECT_CALL(*controller_connection_, |
| 118 didChangeState(blink::WebPresentationConnectionState::Closed)); | 108 didChangeState(blink::WebPresentationConnectionState::Closed)); |
| 119 EXPECT_CALL(*receiver_connection_, | 109 EXPECT_CALL(*receiver_connection_, |
| 120 didChangeState(blink::WebPresentationConnectionState::Closed)); | 110 didChangeState(blink::WebPresentationConnectionState::Closed)); |
| 121 controller_connection_proxy_->close(); | 111 controller_connection_proxy_->close(); |
| 122 run_loop.RunUntilIdle(); | 112 run_loop.RunUntilIdle(); |
| 123 } | 113 } |
| 124 | 114 |
| 125 TEST_F(PresentationConnectionProxyTest, TestReceiverConnectionCallsClose) { | 115 TEST_F(PresentationConnectionProxyTest, TestReceiverConnectionCallsClose) { |
| 126 base::RunLoop run_loop; | 116 base::RunLoop run_loop; |
| 127 EXPECT_CALL(*controller_connection_, | 117 EXPECT_CALL(*controller_connection_, |
| 128 didChangeState(blink::WebPresentationConnectionState::Closed)); | 118 didChangeState(blink::WebPresentationConnectionState::Closed)); |
| 129 EXPECT_CALL(*receiver_connection_, | 119 EXPECT_CALL(*receiver_connection_, |
| 130 didChangeState(blink::WebPresentationConnectionState::Closed)); | 120 didChangeState(blink::WebPresentationConnectionState::Closed)); |
| 131 receiver_connection_proxy_->close(); | 121 receiver_connection_proxy_->close(); |
| 132 run_loop.RunUntilIdle(); | 122 run_loop.RunUntilIdle(); |
| 133 } | 123 } |
| 134 | 124 |
| 135 } // namespace content | 125 } // namespace content |
| OLD | NEW |