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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 ListenForConnectionMessagesInternal(session_info.get()); | 109 ListenForConnectionMessagesInternal(session_info.get()); |
109 } | 110 } |
110 MOCK_METHOD1(ListenForConnectionMessagesInternal, | 111 MOCK_METHOD1(ListenForConnectionMessagesInternal, |
111 void(PresentationSessionInfo* session_info)); | 112 void(PresentationSessionInfo* session_info)); |
112 | 113 |
113 void SetPresentationConnection( | 114 void SetPresentationConnection( |
114 blink::mojom::PresentationSessionInfoPtr session, | 115 blink::mojom::PresentationSessionInfoPtr session, |
115 blink::mojom::PresentationConnectionPtr controller_conn_ptr, | 116 blink::mojom::PresentationConnectionPtr controller_conn_ptr, |
116 blink::mojom::PresentationConnectionRequest receiver_conn_request) | 117 blink::mojom::PresentationConnectionRequest receiver_conn_request) |
117 override { | 118 override { |
118 SetPresentationConnection(session.get(), controller_conn_ptr.get()); | 119 SetPresentationConnectionInternal(session.get(), controller_conn_ptr.get()); |
119 } | 120 } |
120 MOCK_METHOD2(SetPresentationConnection, | 121 MOCK_METHOD2(SetPresentationConnectionInternal, |
121 void(PresentationSessionInfo* session_info, | 122 void(PresentationSessionInfo* session_info, |
122 PresentationConnection* connection)); | 123 PresentationConnection* connection)); |
123 }; | 124 }; |
124 | 125 |
| 126 class TestPresentationConnectionProxy : public PresentationConnectionProxy { |
| 127 public: |
| 128 TestPresentationConnectionProxy(blink::WebPresentationConnection* connection) |
| 129 : PresentationConnectionProxy(connection) {} |
| 130 |
| 131 void SendConnectionMessage(blink::mojom::ConnectionMessagePtr session_message, |
| 132 const OnMessageCallback& callback) const override { |
| 133 SendConnectionMessageInternal(session_message.get(), callback); |
| 134 } |
| 135 MOCK_CONST_METHOD2(SendConnectionMessageInternal, |
| 136 void(blink::mojom::ConnectionMessage*, |
| 137 const OnMessageCallback&)); |
| 138 }; |
| 139 |
| 140 class TestPresentationReceiver : public blink::WebPresentationReceiver { |
| 141 public: |
| 142 blink::WebPresentationConnection* onReceiverConnectionAvailable( |
| 143 const blink::WebPresentationSessionInfo&) override { |
| 144 return &connection_; |
| 145 } |
| 146 |
| 147 TestPresentationConnection connection_; |
| 148 }; |
| 149 |
125 class MockPresentationAvailabilityCallbacks | 150 class MockPresentationAvailabilityCallbacks |
126 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { | 151 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { |
127 public: | 152 public: |
128 MOCK_METHOD1(onSuccess, void(bool value)); | 153 MOCK_METHOD1(onSuccess, void(bool value)); |
129 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); | 154 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); |
130 }; | 155 }; |
131 | 156 |
132 class TestWebPresentationConnectionCallback | 157 class TestWebPresentationConnectionCallback |
133 : public WebPresentationConnectionCallbacks { | 158 : public WebPresentationConnectionCallbacks { |
134 public: | 159 public: |
135 TestWebPresentationConnectionCallback(WebURL url, WebString id) | 160 TestWebPresentationConnectionCallback(WebURL url, WebString id) |
136 : url_(url), id_(id), callback_called_(false) {} | 161 : url_(url), id_(id), callback_called_(false) {} |
137 ~TestWebPresentationConnectionCallback() override { | 162 ~TestWebPresentationConnectionCallback() override { |
138 EXPECT_TRUE(callback_called_); | 163 EXPECT_TRUE(callback_called_); |
139 } | 164 } |
140 | 165 |
141 void onSuccess(const WebPresentationSessionInfo& info) override { | 166 void onSuccess(const WebPresentationSessionInfo& info) override { |
142 callback_called_ = true; | 167 callback_called_ = true; |
143 EXPECT_EQ(info.url, url_); | 168 EXPECT_EQ(info.url, url_); |
144 EXPECT_EQ(info.id, id_); | 169 EXPECT_EQ(info.id, id_); |
145 } | 170 } |
146 | 171 |
147 blink::WebPresentationConnection* getConnection() override { | 172 blink::WebPresentationConnection* getConnection() override { |
148 return &connection_; | 173 return &connection_; |
149 } | 174 } |
150 | 175 |
| 176 TestPresentationConnection connection_; |
| 177 |
151 private: | 178 private: |
152 const WebURL url_; | 179 const WebURL url_; |
153 const WebString id_; | 180 const WebString id_; |
154 bool callback_called_; | 181 bool callback_called_; |
155 TestPresentationConnection connection_; | |
156 }; | 182 }; |
157 | 183 |
158 class TestWebPresentationConnectionErrorCallback | 184 class TestWebPresentationConnectionErrorCallback |
159 : public WebPresentationConnectionCallbacks { | 185 : public WebPresentationConnectionCallbacks { |
160 public: | 186 public: |
161 TestWebPresentationConnectionErrorCallback( | 187 TestWebPresentationConnectionErrorCallback( |
162 WebPresentationError::ErrorType error_type, | 188 WebPresentationError::ErrorType error_type, |
163 WebString message) | 189 WebString message) |
164 : error_type_(error_type), message_(message), callback_called_(false) {} | 190 : error_type_(error_type), message_(message), callback_called_(false) {} |
165 ~TestWebPresentationConnectionErrorCallback() override { | 191 ~TestWebPresentationConnectionErrorCallback() override { |
(...skipping 30 matching lines...) Expand all Loading... |
196 mojo::MakeRequest(&presentation_service_)); | 222 mojo::MakeRequest(&presentation_service_)); |
197 } | 223 } |
198 } | 224 } |
199 | 225 |
200 MockPresentationService* mock_presentation_service_; | 226 MockPresentationService* mock_presentation_service_; |
201 std::unique_ptr<mojo::Binding<PresentationService>> mock_binding_; | 227 std::unique_ptr<mojo::Binding<PresentationService>> mock_binding_; |
202 }; | 228 }; |
203 | 229 |
204 class PresentationDispatcherTest : public ::testing::Test { | 230 class PresentationDispatcherTest : public ::testing::Test { |
205 public: | 231 public: |
| 232 using OnMessageCallback = PresentationConnectionProxy::OnMessageCallback; |
| 233 |
206 enum class URLState { Available, Unavailable, Unsupported, Unknown }; | 234 enum class URLState { Available, Unavailable, Unsupported, Unknown }; |
207 | 235 |
208 PresentationDispatcherTest() | 236 PresentationDispatcherTest() |
209 : gurl1_(GURL("https://www.example.com/1.html")), | 237 : gurl1_(GURL("https://www.example.com/1.html")), |
210 gurl2_(GURL("https://www.example.com/2.html")), | 238 gurl2_(GURL("https://www.example.com/2.html")), |
211 gurl3_(GURL("https://www.example.com/3.html")), | 239 gurl3_(GURL("https://www.example.com/3.html")), |
212 gurl4_(GURL("https://www.example.com/4.html")), | 240 gurl4_(GURL("https://www.example.com/4.html")), |
213 gurls_({gurl1_, gurl2_, gurl3_, gurl4_}), | 241 gurls_({gurl1_, gurl2_, gurl3_, gurl4_}), |
214 url1_(WebURL(gurl1_)), | 242 url1_(WebURL(gurl1_)), |
215 url2_(WebURL(gurl2_)), | 243 url2_(WebURL(gurl2_)), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 std::vector<MockPresentationAvailabilityObserver*> mock_observers_; | 327 std::vector<MockPresentationAvailabilityObserver*> mock_observers_; |
300 | 328 |
301 MockPresentationService presentation_service_; | 329 MockPresentationService presentation_service_; |
302 TestPresentationDispatcher dispatcher_; | 330 TestPresentationDispatcher dispatcher_; |
303 | 331 |
304 private: | 332 private: |
305 content::TestBrowserThreadBundle thread_bundle_; | 333 content::TestBrowserThreadBundle thread_bundle_; |
306 }; | 334 }; |
307 | 335 |
308 TEST_F(PresentationDispatcherTest, TestStartSession) { | 336 TEST_F(PresentationDispatcherTest, TestStartSession) { |
| 337 auto* test_connection_callback = |
| 338 new TestWebPresentationConnectionCallback(url1_, presentation_id_); |
| 339 EXPECT_FALSE(test_connection_callback->connection_.proxy()); |
| 340 |
309 base::RunLoop run_loop; | 341 base::RunLoop run_loop; |
310 | 342 EXPECT_CALL(presentation_service_, ListenForConnectionMessagesInternal(_)); |
| 343 EXPECT_CALL(presentation_service_, SetPresentationConnectionInternal(_, _)); |
311 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) | 344 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) |
312 .WillOnce(Invoke([this]( | 345 .WillOnce(Invoke([this]( |
313 const std::vector<GURL>& presentation_urls, | 346 const std::vector<GURL>& presentation_urls, |
314 const PresentationService::StartSessionCallback& callback) { | 347 const PresentationService::StartSessionCallback& callback) { |
315 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); | 348 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); |
316 session_info->url = gurl1_; | 349 session_info->url = gurl1_; |
317 session_info->id = presentation_id_.utf8(); | 350 session_info->id = presentation_id_.utf8(); |
318 callback.Run(std::move(session_info), PresentationErrorPtr()); | 351 callback.Run(std::move(session_info), PresentationErrorPtr()); |
319 })); | 352 })); |
320 client()->startSession( | 353 dispatcher_.startSession(urls_, base::WrapUnique(test_connection_callback)); |
321 urls_, base::MakeUnique<TestWebPresentationConnectionCallback>( | |
322 url1_, presentation_id_)); | |
323 run_loop.RunUntilIdle(); | 354 run_loop.RunUntilIdle(); |
| 355 |
| 356 EXPECT_TRUE(test_connection_callback->connection_.proxy()); |
324 } | 357 } |
325 | 358 |
326 TEST_F(PresentationDispatcherTest, TestStartSessionError) { | 359 TEST_F(PresentationDispatcherTest, TestStartSessionError) { |
327 WebString error_message = WebString::fromUTF8("Test error message"); | 360 WebString error_message = WebString::fromUTF8("Test error message"); |
328 base::RunLoop run_loop; | 361 base::RunLoop run_loop; |
329 | 362 |
330 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) | 363 EXPECT_CALL(presentation_service_, StartSession(gurls_, _)) |
331 .WillOnce(Invoke([&error_message]( | 364 .WillOnce(Invoke([&error_message]( |
332 const std::vector<GURL>& presentation_urls, | 365 const std::vector<GURL>& presentation_urls, |
333 const PresentationService::StartSessionCallback& callback) { | 366 const PresentationService::StartSessionCallback& callback) { |
334 PresentationErrorPtr error(PresentationError::New()); | 367 PresentationErrorPtr error(PresentationError::New()); |
335 error->error_type = PresentationErrorType::NO_AVAILABLE_SCREENS; | 368 error->error_type = PresentationErrorType::NO_AVAILABLE_SCREENS; |
336 error->message = error_message.utf8(); | 369 error->message = error_message.utf8(); |
337 callback.Run(PresentationSessionInfoPtr(), std::move(error)); | 370 callback.Run(PresentationSessionInfoPtr(), std::move(error)); |
338 })); | 371 })); |
339 client()->startSession( | 372 dispatcher_.startSession( |
340 urls_, | 373 urls_, |
341 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( | 374 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( |
342 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); | 375 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); |
343 run_loop.RunUntilIdle(); | 376 run_loop.RunUntilIdle(); |
344 } | 377 } |
345 | 378 |
346 TEST_F(PresentationDispatcherTest, TestJoinSessionError) { | 379 TEST_F(PresentationDispatcherTest, TestJoinSessionError) { |
347 WebString error_message = WebString::fromUTF8("Test error message"); | 380 WebString error_message = WebString::fromUTF8("Test error message"); |
348 base::RunLoop run_loop; | 381 base::RunLoop run_loop; |
349 | 382 |
(...skipping 10 matching lines...) Expand all Loading... |
360 callback.Run(PresentationSessionInfoPtr(), std::move(error)); | 393 callback.Run(PresentationSessionInfoPtr(), std::move(error)); |
361 })); | 394 })); |
362 dispatcher_.joinSession( | 395 dispatcher_.joinSession( |
363 urls_, presentation_id_, | 396 urls_, presentation_id_, |
364 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( | 397 base::MakeUnique<TestWebPresentationConnectionErrorCallback>( |
365 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); | 398 WebPresentationError::ErrorTypeNoAvailableScreens, error_message)); |
366 run_loop.RunUntilIdle(); | 399 run_loop.RunUntilIdle(); |
367 } | 400 } |
368 | 401 |
369 TEST_F(PresentationDispatcherTest, TestJoinSession) { | 402 TEST_F(PresentationDispatcherTest, TestJoinSession) { |
| 403 auto* test_connection_callback = |
| 404 new TestWebPresentationConnectionCallback(url1_, presentation_id_); |
| 405 EXPECT_FALSE(test_connection_callback->connection_.proxy()); |
| 406 |
370 base::RunLoop run_loop; | 407 base::RunLoop run_loop; |
371 | 408 |
| 409 EXPECT_CALL(presentation_service_, ListenForConnectionMessagesInternal(_)); |
| 410 EXPECT_CALL(presentation_service_, SetPresentationConnectionInternal(_, _)); |
372 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) | 411 EXPECT_CALL(presentation_service_, JoinSession(gurls_, _, _)) |
373 .WillOnce(Invoke([this]( | 412 .WillOnce(Invoke([this]( |
374 const std::vector<GURL>& presentation_urls, | 413 const std::vector<GURL>& presentation_urls, |
375 const base::Optional<std::string>& presentation_id, | 414 const base::Optional<std::string>& presentation_id, |
376 const PresentationService::JoinSessionCallback& callback) { | 415 const PresentationService::JoinSessionCallback& callback) { |
377 EXPECT_TRUE(presentation_id.has_value()); | 416 EXPECT_TRUE(presentation_id.has_value()); |
378 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); | 417 EXPECT_EQ(presentation_id_.utf8(), presentation_id.value()); |
379 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); | 418 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); |
380 session_info->url = gurl1_; | 419 session_info->url = gurl1_; |
381 session_info->id = presentation_id_.utf8(); | 420 session_info->id = presentation_id_.utf8(); |
382 callback.Run(std::move(session_info), PresentationErrorPtr()); | 421 callback.Run(std::move(session_info), PresentationErrorPtr()); |
383 })); | 422 })); |
384 dispatcher_.joinSession( | 423 dispatcher_.joinSession(urls_, presentation_id_, |
385 urls_, presentation_id_, | 424 base::WrapUnique(test_connection_callback)); |
386 base::MakeUnique<TestWebPresentationConnectionCallback>( | |
387 url1_, presentation_id_)); | |
388 run_loop.RunUntilIdle(); | 425 run_loop.RunUntilIdle(); |
| 426 |
| 427 EXPECT_TRUE(test_connection_callback->connection_.proxy()); |
389 } | 428 } |
390 | 429 |
391 TEST_F(PresentationDispatcherTest, TestSendString) { | 430 TEST_F(PresentationDispatcherTest, TestSendString) { |
392 WebString message = WebString::fromUTF8("test message"); | 431 WebString message = WebString::fromUTF8("test message"); |
| 432 TestPresentationConnection connection; |
| 433 TestPresentationConnectionProxy connection_proxy(&connection); |
| 434 |
393 base::RunLoop run_loop; | 435 base::RunLoop run_loop; |
394 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 436 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) |
395 .WillOnce(Invoke([this, &message]( | 437 .WillOnce(Invoke([this, &message](ConnectionMessage* session_message, |
396 PresentationSessionInfo* session_info, | 438 const OnMessageCallback& callback) { |
397 ConnectionMessage* message_request, | 439 EXPECT_EQ(blink::mojom::PresentationMessageType::TEXT, |
398 const PresentationService::SendConnectionMessageCallback& callback) { | 440 session_message->type); |
399 EXPECT_EQ(gurl1_, session_info->url); | 441 EXPECT_EQ(message.utf8(), session_message->message.value()); |
400 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | |
401 EXPECT_TRUE(message_request->message.has_value()); | |
402 EXPECT_EQ(message.utf8(), message_request->message.value()); | |
403 callback.Run(true); | |
404 })); | 442 })); |
405 dispatcher_.sendString(url1_, presentation_id_, message, nullptr); | 443 dispatcher_.sendString(url1_, presentation_id_, message, &connection_proxy); |
406 run_loop.RunUntilIdle(); | 444 run_loop.RunUntilIdle(); |
407 } | 445 } |
408 | 446 |
409 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { | 447 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { |
| 448 TestPresentationConnection connection; |
| 449 TestPresentationConnectionProxy connection_proxy(&connection); |
| 450 |
410 base::RunLoop run_loop; | 451 base::RunLoop run_loop; |
411 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 452 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) |
412 .WillOnce(Invoke([this]( | 453 .WillOnce(Invoke([this](ConnectionMessage* message_request, |
413 PresentationSessionInfo* session_info, | 454 const OnMessageCallback& callback) { |
414 ConnectionMessage* message_request, | |
415 const PresentationService::SendConnectionMessageCallback& callback) { | |
416 EXPECT_EQ(gurl1_, session_info->url); | |
417 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | |
418 std::vector<uint8_t> data( | 455 std::vector<uint8_t> data( |
419 array_buffer_data(), | 456 array_buffer_data(), |
420 array_buffer_data() + array_buffer_.byteLength()); | 457 array_buffer_data() + array_buffer_.byteLength()); |
421 EXPECT_TRUE(message_request->data.has_value()); | 458 EXPECT_TRUE(message_request->data.has_value()); |
422 EXPECT_EQ(data, message_request->data.value()); | 459 EXPECT_EQ(data, message_request->data.value()); |
423 callback.Run(true); | |
424 })); | 460 })); |
425 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), | 461 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), |
426 array_buffer_.byteLength(), nullptr); | 462 array_buffer_.byteLength(), &connection_proxy); |
427 run_loop.RunUntilIdle(); | 463 run_loop.RunUntilIdle(); |
428 } | 464 } |
429 | 465 |
430 TEST_F(PresentationDispatcherTest, TestSendBlobData) { | 466 TEST_F(PresentationDispatcherTest, TestSendBlobData) { |
| 467 TestPresentationConnection connection; |
| 468 TestPresentationConnectionProxy connection_proxy(&connection); |
| 469 |
431 base::RunLoop run_loop; | 470 base::RunLoop run_loop; |
432 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 471 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) |
433 .WillOnce(Invoke([this]( | 472 .WillOnce(Invoke([this](ConnectionMessage* message_request, |
434 PresentationSessionInfo* session_info, | 473 const OnMessageCallback& callback) { |
435 ConnectionMessage* message_request, | |
436 const PresentationService::SendConnectionMessageCallback& callback) { | |
437 EXPECT_EQ(gurl1_, session_info->url); | |
438 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | |
439 std::vector<uint8_t> data( | 474 std::vector<uint8_t> data( |
440 array_buffer_data(), | 475 array_buffer_data(), |
441 array_buffer_data() + array_buffer_.byteLength()); | 476 array_buffer_data() + array_buffer_.byteLength()); |
442 EXPECT_TRUE(message_request->data.has_value()); | 477 EXPECT_TRUE(message_request->data.has_value()); |
443 EXPECT_EQ(data, message_request->data.value()); | 478 EXPECT_EQ(data, message_request->data.value()); |
444 callback.Run(true); | 479 callback.Run(true); |
445 })); | 480 })); |
446 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), | 481 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), |
447 array_buffer_.byteLength(), nullptr); | 482 array_buffer_.byteLength(), &connection_proxy); |
448 run_loop.RunUntilIdle(); | 483 run_loop.RunUntilIdle(); |
449 } | 484 } |
450 | 485 |
| 486 TEST_F(PresentationDispatcherTest, TestOnReceiverConnectionAvailable) { |
| 487 PresentationSessionInfoPtr session_info(PresentationSessionInfo::New()); |
| 488 session_info->url = gurl1_; |
| 489 session_info->id = presentation_id_.utf8(); |
| 490 |
| 491 blink::mojom::PresentationConnectionPtr controller_connection_ptr; |
| 492 TestPresentationConnection controller_connection; |
| 493 TestPresentationConnectionProxy controller_connection_proxy( |
| 494 &controller_connection); |
| 495 mojo::Binding<blink::mojom::PresentationConnection> binding( |
| 496 &controller_connection_proxy, |
| 497 mojo::MakeRequest(&controller_connection_ptr)); |
| 498 |
| 499 blink::mojom::PresentationConnectionPtr receiver_connection_ptr; |
| 500 |
| 501 TestPresentationReceiver receiver; |
| 502 dispatcher_.setReceiver(&receiver); |
| 503 |
| 504 base::RunLoop run_loop; |
| 505 EXPECT_CALL(controller_connection, |
| 506 didChangeState(blink::WebPresentationConnectionState::Connected)); |
| 507 EXPECT_CALL(receiver.connection_, |
| 508 didChangeState(blink::WebPresentationConnectionState::Connected)); |
| 509 |
| 510 dispatcher_.OnReceiverConnectionAvailable( |
| 511 std::move(session_info), std::move(controller_connection_ptr), |
| 512 mojo::MakeRequest(&receiver_connection_ptr)); |
| 513 |
| 514 EXPECT_TRUE(receiver_connection_ptr); |
| 515 EXPECT_TRUE(receiver.connection_.proxy()); |
| 516 run_loop.RunUntilIdle(); |
| 517 } |
| 518 |
451 TEST_F(PresentationDispatcherTest, TestCloseSession) { | 519 TEST_F(PresentationDispatcherTest, TestCloseSession) { |
452 base::RunLoop run_loop; | 520 base::RunLoop run_loop; |
453 EXPECT_CALL(presentation_service_, | 521 EXPECT_CALL(presentation_service_, |
454 CloseConnection(gurl1_, presentation_id_.utf8())); | 522 CloseConnection(gurl1_, presentation_id_.utf8())); |
455 dispatcher_.closeSession(url1_, presentation_id_); | 523 dispatcher_.closeSession(url1_, presentation_id_); |
456 run_loop.RunUntilIdle(); | 524 run_loop.RunUntilIdle(); |
457 } | 525 } |
458 | 526 |
459 TEST_F(PresentationDispatcherTest, TestTerminateSession) { | 527 TEST_F(PresentationDispatcherTest, TestTerminateSession) { |
460 base::RunLoop run_loop; | 528 base::RunLoop run_loop; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 795 |
728 for (auto* mock_observer : mock_observers_) | 796 for (auto* mock_observer : mock_observers_) |
729 EXPECT_CALL(*mock_observer, availabilityChanged(false)); | 797 EXPECT_CALL(*mock_observer, availabilityChanged(false)); |
730 | 798 |
731 base::RunLoop run_loop_2; | 799 base::RunLoop run_loop_2; |
732 ChangeURLState(gurl2_, URLState::Unavailable); | 800 ChangeURLState(gurl2_, URLState::Unavailable); |
733 run_loop_2.RunUntilIdle(); | 801 run_loop_2.RunUntilIdle(); |
734 } | 802 } |
735 | 803 |
736 } // namespace content | 804 } // namespace content |
OLD | NEW |