| 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" |
| 11 #include "content/renderer/presentation/presentation_dispatcher.h" | 11 #include "content/renderer/presentation/presentation_dispatcher.h" |
| 12 #include "content/renderer/presentation/test_presentation_connection.h" | 12 #include "content/renderer/presentation/test_presentation_connection.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" | 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" |
| 15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" | 15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" |
| 16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnectionCallbacks.h" | 16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnectionCallbacks.h" |
| 17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" | 17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
| 18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nError.h" | 18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nError.h" |
| 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nReceiver.h" |
| 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" | 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" |
| 20 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | 21 #include "third_party/WebKit/public/web/WebArrayBuffer.h" |
| 21 | 22 |
| 22 using ::testing::_; | 23 using ::testing::_; |
| 23 using ::testing::Invoke; | 24 using ::testing::Invoke; |
| 24 using blink::WebArrayBuffer; | 25 using blink::WebArrayBuffer; |
| 25 using blink::WebPresentationAvailabilityCallbacks; | 26 using blink::WebPresentationAvailabilityCallbacks; |
| 26 using blink::WebPresentationAvailabilityObserver; | 27 using blink::WebPresentationAvailabilityObserver; |
| 27 using blink::WebPresentationConnectionCallbacks; | 28 using blink::WebPresentationConnectionCallbacks; |
| 28 using blink::WebPresentationError; | 29 using blink::WebPresentationError; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 blink::mojom::PresentationConnectionPtr controller_conn_ptr, | 105 blink::mojom::PresentationConnectionPtr controller_conn_ptr, |
| 105 blink::mojom::PresentationConnectionRequest receiver_conn_request) | 106 blink::mojom::PresentationConnectionRequest receiver_conn_request) |
| 106 override { | 107 override { |
| 107 SetPresentationConnection(session_info, controller_conn_ptr.get()); | 108 SetPresentationConnection(session_info, controller_conn_ptr.get()); |
| 108 } | 109 } |
| 109 MOCK_METHOD2(SetPresentationConnection, | 110 MOCK_METHOD2(SetPresentationConnection, |
| 110 void(const PresentationSessionInfo& session_info, | 111 void(const PresentationSessionInfo& session_info, |
| 111 PresentationConnection* connection)); | 112 PresentationConnection* connection)); |
| 112 }; | 113 }; |
| 113 | 114 |
| 115 class TestPresentationConnectionProxy : public PresentationConnectionProxy { |
| 116 public: |
| 117 TestPresentationConnectionProxy(blink::WebPresentationConnection* connection) |
| 118 : PresentationConnectionProxy(connection) {} |
| 119 |
| 120 void SendConnectionMessage(blink::mojom::ConnectionMessagePtr session_message, |
| 121 const OnMessageCallback& callback) const override { |
| 122 SendConnectionMessageInternal(session_message.get(), callback); |
| 123 } |
| 124 MOCK_CONST_METHOD2(SendConnectionMessageInternal, |
| 125 void(blink::mojom::ConnectionMessage*, |
| 126 const OnMessageCallback&)); |
| 127 }; |
| 128 |
| 129 class TestPresentationReceiver : public blink::WebPresentationReceiver { |
| 130 public: |
| 131 blink::WebPresentationConnection* onReceiverConnectionAvailable( |
| 132 const blink::WebPresentationSessionInfo&) override { |
| 133 return &connection_; |
| 134 } |
| 135 |
| 136 TestPresentationConnection connection_; |
| 137 }; |
| 138 |
| 114 class MockPresentationAvailabilityCallbacks | 139 class MockPresentationAvailabilityCallbacks |
| 115 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { | 140 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { |
| 116 public: | 141 public: |
| 117 MOCK_METHOD1(onSuccess, void(bool value)); | 142 MOCK_METHOD1(onSuccess, void(bool value)); |
| 118 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); | 143 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); |
| 119 }; | 144 }; |
| 120 | 145 |
| 121 class TestWebPresentationConnectionCallback | 146 class TestWebPresentationConnectionCallback |
| 122 : public WebPresentationConnectionCallbacks { | 147 : public WebPresentationConnectionCallbacks { |
| 123 public: | 148 public: |
| 124 TestWebPresentationConnectionCallback(WebURL url, WebString id) | 149 // Does not take ownership of |connection|. |
| 125 : url_(url), id_(id), callback_called_(false) {} | 150 TestWebPresentationConnectionCallback(WebURL url, |
| 151 WebString id, |
| 152 TestPresentationConnection* connection) |
| 153 : url_(url), id_(id), callback_called_(false), connection_(connection) {} |
| 126 ~TestWebPresentationConnectionCallback() override { | 154 ~TestWebPresentationConnectionCallback() override { |
| 127 EXPECT_TRUE(callback_called_); | 155 EXPECT_TRUE(callback_called_); |
| 128 } | 156 } |
| 129 | 157 |
| 130 void onSuccess(const WebPresentationSessionInfo& info) override { | 158 void onSuccess(const WebPresentationSessionInfo& info) override { |
| 131 callback_called_ = true; | 159 callback_called_ = true; |
| 132 EXPECT_EQ(info.url, url_); | 160 EXPECT_EQ(info.url, url_); |
| 133 EXPECT_EQ(info.id, id_); | 161 EXPECT_EQ(info.id, id_); |
| 134 } | 162 } |
| 135 | 163 |
| 136 blink::WebPresentationConnection* getConnection() override { | 164 blink::WebPresentationConnection* getConnection() override { |
| 137 return &connection_; | 165 return connection_; |
| 138 } | 166 } |
| 139 | 167 |
| 140 private: | 168 private: |
| 141 const WebURL url_; | 169 const WebURL url_; |
| 142 const WebString id_; | 170 const WebString id_; |
| 143 bool callback_called_; | 171 bool callback_called_; |
| 144 TestPresentationConnection connection_; | 172 TestPresentationConnection* connection_; |
| 145 }; | 173 }; |
| 146 | 174 |
| 147 class TestWebPresentationConnectionErrorCallback | 175 class TestWebPresentationConnectionErrorCallback |
| 148 : public WebPresentationConnectionCallbacks { | 176 : public WebPresentationConnectionCallbacks { |
| 149 public: | 177 public: |
| 150 TestWebPresentationConnectionErrorCallback( | 178 TestWebPresentationConnectionErrorCallback( |
| 151 WebPresentationError::ErrorType error_type, | 179 WebPresentationError::ErrorType error_type, |
| 152 WebString message) | 180 WebString message) |
| 153 : error_type_(error_type), message_(message), callback_called_(false) {} | 181 : error_type_(error_type), message_(message), callback_called_(false) {} |
| 154 ~TestWebPresentationConnectionErrorCallback() override { | 182 ~TestWebPresentationConnectionErrorCallback() override { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 185 mojo::MakeRequest(&presentation_service_)); | 213 mojo::MakeRequest(&presentation_service_)); |
| 186 } | 214 } |
| 187 } | 215 } |
| 188 | 216 |
| 189 MockPresentationService* mock_presentation_service_; | 217 MockPresentationService* mock_presentation_service_; |
| 190 std::unique_ptr<mojo::Binding<PresentationService>> mock_binding_; | 218 std::unique_ptr<mojo::Binding<PresentationService>> mock_binding_; |
| 191 }; | 219 }; |
| 192 | 220 |
| 193 class PresentationDispatcherTest : public ::testing::Test { | 221 class PresentationDispatcherTest : public ::testing::Test { |
| 194 public: | 222 public: |
| 223 using OnMessageCallback = PresentationConnectionProxy::OnMessageCallback; |
| 224 |
| 195 enum class URLState { Available, Unavailable, Unsupported, Unknown }; | 225 enum class URLState { Available, Unavailable, Unsupported, Unknown }; |
| 196 | 226 |
| 197 PresentationDispatcherTest() | 227 PresentationDispatcherTest() |
| 198 : gurl1_(GURL("https://www.example.com/1.html")), | 228 : gurl1_(GURL("https://www.example.com/1.html")), |
| 199 gurl2_(GURL("https://www.example.com/2.html")), | 229 gurl2_(GURL("https://www.example.com/2.html")), |
| 200 gurl3_(GURL("https://www.example.com/3.html")), | 230 gurl3_(GURL("https://www.example.com/3.html")), |
| 201 gurl4_(GURL("https://www.example.com/4.html")), | 231 gurl4_(GURL("https://www.example.com/4.html")), |
| 202 gurls_({gurl1_, gurl2_, gurl3_, gurl4_}), | 232 gurls_({gurl1_, gurl2_, gurl3_, gurl4_}), |
| 203 url1_(WebURL(gurl1_)), | 233 url1_(WebURL(gurl1_)), |
| 204 url2_(WebURL(gurl2_)), | 234 url2_(WebURL(gurl2_)), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 std::vector<MockPresentationAvailabilityObserver*> mock_observers_; | 318 std::vector<MockPresentationAvailabilityObserver*> mock_observers_; |
| 289 | 319 |
| 290 MockPresentationService presentation_service_; | 320 MockPresentationService presentation_service_; |
| 291 TestPresentationDispatcher dispatcher_; | 321 TestPresentationDispatcher dispatcher_; |
| 292 | 322 |
| 293 private: | 323 private: |
| 294 content::TestBrowserThreadBundle thread_bundle_; | 324 content::TestBrowserThreadBundle thread_bundle_; |
| 295 }; | 325 }; |
| 296 | 326 |
| 297 TEST_F(PresentationDispatcherTest, TestStartSession) { | 327 TEST_F(PresentationDispatcherTest, TestStartSession) { |
| 298 base::RunLoop run_loop; | 328 TestPresentationConnection connection; |
| 329 EXPECT_FALSE(connection.proxy()); |
| 330 { |
| 331 base::RunLoop run_loop; |
| 332 EXPECT_CALL(presentation_service_, ListenForConnectionMessages(_)); |
| 333 EXPECT_CALL(presentation_service_, SetPresentationConnection(_, _)); |
| 334 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) |
| 335 .WillOnce(Invoke([this]( |
| 336 const std::vector<GURL>& presentation_urls, |
| 337 const PresentationService::StartSessionCallback& callback) { |
| 338 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8()); |
| 339 callback.Run(session_info, base::nullopt); |
| 340 })); |
| 299 | 341 |
| 300 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) | 342 dispatcher_.startSession( |
| 301 .WillOnce(Invoke([this]( | 343 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>( |
| 302 const std::vector<GURL>& presentation_urls, | 344 url1_, presentation_id_, &connection)); |
| 303 const PresentationService::StartSessionCallback& callback) { | 345 run_loop.RunUntilIdle(); |
| 304 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8()); | 346 } |
| 305 callback.Run(session_info, base::nullopt); | 347 EXPECT_TRUE(connection.proxy()); |
| 306 })); | |
| 307 client()->startSession( | |
| 308 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>( | |
| 309 url1_, presentation_id_)); | |
| 310 run_loop.RunUntilIdle(); | |
| 311 } | 348 } |
| 312 | 349 |
| 313 TEST_F(PresentationDispatcherTest, TestStartSessionError) { | 350 TEST_F(PresentationDispatcherTest, TestStartSessionError) { |
| 314 WebString error_message = WebString::fromUTF8("Test error message"); | 351 WebString error_message = WebString::fromUTF8("Test error message"); |
| 315 base::RunLoop run_loop; | 352 base::RunLoop run_loop; |
| 316 | 353 |
| 317 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) | 354 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) |
| 318 .WillOnce(Invoke([&error_message]( | 355 .WillOnce(Invoke([&error_message]( |
| 319 const std::vector<GURL>& presentation_urls, | 356 const std::vector<GURL>& presentation_urls, |
| 320 const PresentationService::StartSessionCallback& callback) { | 357 const PresentationService::StartSessionCallback& callback) { |
| 321 callback.Run( | 358 callback.Run( |
| 322 base::nullopt, | 359 base::nullopt, |
| 323 PresentationError(content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, | 360 PresentationError(content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |
| 324 error_message.utf8())); | 361 error_message.utf8())); |
| 325 })); | 362 })); |
| 326 client()->startSession( | 363 dispatcher_.startSession( |
| 327 urls_, | 364 urls_, |
| 328 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( | 365 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( |
| 329 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); | 366 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); |
| 330 run_loop.RunUntilIdle(); | 367 run_loop.RunUntilIdle(); |
| 331 } | 368 } |
| 332 | 369 |
| 333 TEST_F(PresentationDispatcherTest, TestJoinSessionError) { | 370 TEST_F(PresentationDispatcherTest, TestJoinSessionError) { |
| 334 WebString error_message = WebString::fromUTF8("Test error message"); | 371 WebString error_message = WebString::fromUTF8("Test error message"); |
| 335 base::RunLoop run_loop; | 372 base::RunLoop run_loop; |
| 336 | 373 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 347 error_message.utf8())); | 384 error_message.utf8())); |
| 348 })); | 385 })); |
| 349 dispatcher_.joinSession( | 386 dispatcher_.joinSession( |
| 350 urls_, presentation_id_, | 387 urls_, presentation_id_, |
| 351 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( | 388 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( |
| 352 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); | 389 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); |
| 353 run_loop.RunUntilIdle(); | 390 run_loop.RunUntilIdle(); |
| 354 } | 391 } |
| 355 | 392 |
| 356 TEST_F(PresentationDispatcherTest, TestJoinSession) { | 393 TEST_F(PresentationDispatcherTest, TestJoinSession) { |
| 357 base::RunLoop run_loop; | 394 TestPresentationConnection connection; |
| 395 EXPECT_FALSE(connection.proxy()); |
| 396 { |
| 397 base::RunLoop run_loop; |
| 398 EXPECT_CALL(presentation_service_, ListenForConnectionMessages(_)); |
| 399 EXPECT_CALL(presentation_service_, SetPresentationConnection(_, _)); |
| 400 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) |
| 401 .WillOnce(Invoke([this]( |
| 402 const std::vector<GURL>& presentation_urls, |
| 403 const base::Optional<std::string>& presentation_id, |
| 404 const PresentationService::JoinSessionCallback& callback) { |
| 405 EXPECT_TRUE(presentation_id.has_value()); |
| 406 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); |
| 407 callback.Run(PresentationSessionInfo(gurl1_, presentation_id_.utf8()), |
| 408 base::nullopt); |
| 409 })); |
| 358 | 410 |
| 359 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) | 411 dispatcher_.joinSession( |
| 360 .WillOnce(Invoke([this]( | 412 urls_, presentation_id_, |
| 361 const std::vector<GURL>& presentation_urls, | 413 base::MakeUnique<TestWebPresentationConnectionCallback>( |
| 362 const base::Optional<std::string>& presentation_id, | 414 url1_, presentation_id_, &connection)); |
| 363 const PresentationService::JoinSessionCallback& callback) { | 415 run_loop.RunUntilIdle(); |
| 364 EXPECT_TRUE(presentation_id.has_value()); | 416 } |
| 365 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); | 417 EXPECT_TRUE(connection.proxy()); |
| 366 callback.Run(PresentationSessionInfo(gurl1_, presentation_id_.utf8()), | |
| 367 base::nullopt); | |
| 368 })); | |
| 369 dispatcher_.joinSession( | |
| 370 urls_, presentation_id_, | |
| 371 base::MakeUnique<TestWebPresentationConnectionCallback>( | |
| 372 url1_, presentation_id_)); | |
| 373 run_loop.RunUntilIdle(); | |
| 374 } | 418 } |
| 375 | 419 |
| 376 TEST_F(PresentationDispatcherTest, TestSendString) { | 420 TEST_F(PresentationDispatcherTest, TestSendString) { |
| 377 WebString message = WebString::fromUTF8("test message"); | 421 WebString message = WebString::fromUTF8("test message"); |
| 422 TestPresentationConnection connection; |
| 423 TestPresentationConnectionProxy connection_proxy(&connection); |
| 424 |
| 378 base::RunLoop run_loop; | 425 base::RunLoop run_loop; |
| 379 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 426 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) |
| 380 .WillOnce(Invoke([this, &message]( | 427 .WillOnce(Invoke([this, &message](ConnectionMessage* session_message, |
| 381 const PresentationSessionInfo& session_info, | 428 const OnMessageCallback& callback) { |
| 382 ConnectionMessage* message_request, | 429 EXPECT_EQ(blink::mojom::PresentationMessageType::TEXT, |
| 383 const PresentationService::SendConnectionMessageCallback& callback) { | 430 session_message->type); |
| 384 EXPECT_EQ(gurl1_, session_info.presentation_url); | 431 EXPECT_EQ(message.utf8(), session_message->message.value()); |
| 385 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id); | |
| 386 EXPECT_TRUE(message_request->message.has_value()); | |
| 387 EXPECT_EQ(message.utf8(), message_request->message.value()); | |
| 388 callback.Run(true); | |
| 389 })); | 432 })); |
| 390 dispatcher_.sendString(url1_, presentation_id_, message, nullptr); | 433 dispatcher_.sendString(url1_, presentation_id_, message, &connection_proxy); |
| 391 run_loop.RunUntilIdle(); | 434 run_loop.RunUntilIdle(); |
| 392 } | 435 } |
| 393 | 436 |
| 394 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { | 437 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { |
| 438 TestPresentationConnection connection; |
| 439 TestPresentationConnectionProxy connection_proxy(&connection); |
| 440 |
| 395 base::RunLoop run_loop; | 441 base::RunLoop run_loop; |
| 396 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 442 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) |
| 397 .WillOnce(Invoke([this]( | 443 .WillOnce(Invoke([this](ConnectionMessage* message_request, |
| 398 const PresentationSessionInfo& session_info, | 444 const OnMessageCallback& callback) { |
| 399 ConnectionMessage* message_request, | |
| 400 const PresentationService::SendConnectionMessageCallback& callback) { | |
| 401 EXPECT_EQ(gurl1_, session_info.presentation_url); | |
| 402 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id); | |
| 403 std::vector<uint8_t> data( | 445 std::vector<uint8_t> data( |
| 404 array_buffer_data(), | 446 array_buffer_data(), |
| 405 array_buffer_data() + array_buffer_.byteLength()); | 447 array_buffer_data() + array_buffer_.byteLength()); |
| 406 EXPECT_TRUE(message_request->data.has_value()); | 448 EXPECT_TRUE(message_request->data.has_value()); |
| 407 EXPECT_EQ(data, message_request->data.value()); | 449 EXPECT_EQ(data, message_request->data.value()); |
| 408 callback.Run(true); | |
| 409 })); | 450 })); |
| 410 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), | 451 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), |
| 411 array_buffer_.byteLength(), nullptr); | 452 array_buffer_.byteLength(), &connection_proxy); |
| 412 run_loop.RunUntilIdle(); | 453 run_loop.RunUntilIdle(); |
| 413 } | 454 } |
| 414 | 455 |
| 415 TEST_F(PresentationDispatcherTest, TestSendBlobData) { | 456 TEST_F(PresentationDispatcherTest, TestSendBlobData) { |
| 457 TestPresentationConnection connection; |
| 458 TestPresentationConnectionProxy connection_proxy(&connection); |
| 459 |
| 416 base::RunLoop run_loop; | 460 base::RunLoop run_loop; |
| 417 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 461 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) |
| 418 .WillOnce(Invoke([this]( | 462 .WillOnce(Invoke([this](ConnectionMessage* message_request, |
| 419 const PresentationSessionInfo& session_info, | 463 const OnMessageCallback& callback) { |
| 420 ConnectionMessage* message_request, | |
| 421 const PresentationService::SendConnectionMessageCallback& callback) { | |
| 422 EXPECT_EQ(gurl1_, session_info.presentation_url); | |
| 423 EXPECT_EQ(presentation_id_.utf8(), session_info.presentation_id); | |
| 424 std::vector<uint8_t> data( | 464 std::vector<uint8_t> data( |
| 425 array_buffer_data(), | 465 array_buffer_data(), |
| 426 array_buffer_data() + array_buffer_.byteLength()); | 466 array_buffer_data() + array_buffer_.byteLength()); |
| 427 EXPECT_TRUE(message_request->data.has_value()); | 467 EXPECT_TRUE(message_request->data.has_value()); |
| 428 EXPECT_EQ(data, message_request->data.value()); | 468 EXPECT_EQ(data, message_request->data.value()); |
| 429 callback.Run(true); | 469 callback.Run(true); |
| 430 })); | 470 })); |
| 431 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), | 471 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), |
| 432 array_buffer_.byteLength(), nullptr); | 472 array_buffer_.byteLength(), &connection_proxy); |
| 433 run_loop.RunUntilIdle(); | 473 run_loop.RunUntilIdle(); |
| 434 } | 474 } |
| 435 | 475 |
| 476 TEST_F(PresentationDispatcherTest, TestOnReceiverConnectionAvailable) { |
| 477 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8()); |
| 478 |
| 479 blink::mojom::PresentationConnectionPtr controller_connection_ptr; |
| 480 TestPresentationConnection controller_connection; |
| 481 TestPresentationConnectionProxy controller_connection_proxy( |
| 482 &controller_connection); |
| 483 mojo::Binding<blink::mojom::PresentationConnection> binding( |
| 484 &controller_connection_proxy, |
| 485 mojo::MakeRequest(&controller_connection_ptr)); |
| 486 |
| 487 blink::mojom::PresentationConnectionPtr receiver_connection_ptr; |
| 488 |
| 489 TestPresentationReceiver receiver; |
| 490 dispatcher_.setReceiver(&receiver); |
| 491 |
| 492 base::RunLoop run_loop; |
| 493 EXPECT_CALL(controller_connection, |
| 494 didChangeState(blink::WebPresentationConnectionState::Connected)); |
| 495 EXPECT_CALL(receiver.connection_, |
| 496 didChangeState(blink::WebPresentationConnectionState::Connected)); |
| 497 |
| 498 dispatcher_.OnReceiverConnectionAvailable( |
| 499 std::move(session_info), std::move(controller_connection_ptr), |
| 500 mojo::MakeRequest(&receiver_connection_ptr)); |
| 501 |
| 502 EXPECT_TRUE(receiver_connection_ptr); |
| 503 EXPECT_TRUE(receiver.connection_.proxy()); |
| 504 run_loop.RunUntilIdle(); |
| 505 } |
| 506 |
| 436 TEST_F(PresentationDispatcherTest, TestCloseSession) { | 507 TEST_F(PresentationDispatcherTest, TestCloseSession) { |
| 437 base::RunLoop run_loop; | 508 base::RunLoop run_loop; |
| 438 EXPECT_CALL(presentation_service_, | 509 EXPECT_CALL(presentation_service_, |
| 439 CloseConnection(gurl1_, presentation_id_.utf8())); | 510 CloseConnection(gurl1_, presentation_id_.utf8())); |
| 440 dispatcher_.closeSession(url1_, presentation_id_); | 511 dispatcher_.closeSession(url1_, presentation_id_); |
| 441 run_loop.RunUntilIdle(); | 512 run_loop.RunUntilIdle(); |
| 442 } | 513 } |
| 443 | 514 |
| 444 TEST_F(PresentationDispatcherTest, TestTerminateSession) { | 515 TEST_F(PresentationDispatcherTest, TestTerminateSession) { |
| 445 base::RunLoop run_loop; | 516 base::RunLoop run_loop; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 783 |
| 713 for (auto* mock_observer : mock_observers_) | 784 for (auto* mock_observer : mock_observers_) |
| 714 EXPECT_CALL(*mock_observer, availabilityChanged(false)); | 785 EXPECT_CALL(*mock_observer, availabilityChanged(false)); |
| 715 | 786 |
| 716 base::RunLoop run_loop_2; | 787 base::RunLoop run_loop_2; |
| 717 ChangeURLState(gurl2_, URLState::Unavailable); | 788 ChangeURLState(gurl2_, URLState::Unavailable); |
| 718 run_loop_2.RunUntilIdle(); | 789 run_loop_2.RunUntilIdle(); |
| 719 } | 790 } |
| 720 | 791 |
| 721 } // namespace content | 792 } // namespace content |
| OLD | NEW |