| 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_dispatcher.h" | 10 #include "content/renderer/presentation/presentation_dispatcher.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" | 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" |
| 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" |
| 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnectionCallbacks.h" |
| 15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
| 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nError.h" | 16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nError.h" |
| 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" | 17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" |
| 15 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | 18 #include "third_party/WebKit/public/web/WebArrayBuffer.h" |
| 16 | 19 |
| 17 using ::testing::_; | 20 using ::testing::_; |
| 18 using ::testing::Invoke; | 21 using ::testing::Invoke; |
| 19 using blink::WebArrayBuffer; | 22 using blink::WebArrayBuffer; |
| 20 using blink::WebPresentationAvailabilityCallbacks; | 23 using blink::WebPresentationAvailabilityCallbacks; |
| 21 using blink::WebPresentationAvailabilityObserver; | 24 using blink::WebPresentationAvailabilityObserver; |
| 22 using blink::WebPresentationConnectionCallback; | 25 using blink::WebPresentationConnectionCallbacks; |
| 23 using blink::WebPresentationError; | 26 using blink::WebPresentationError; |
| 24 using blink::WebPresentationSessionInfo; | 27 using blink::WebPresentationSessionInfo; |
| 25 using blink::WebString; | 28 using blink::WebString; |
| 26 using blink::WebURL; | 29 using blink::WebURL; |
| 27 using blink::WebVector; | 30 using blink::WebVector; |
| 28 using blink::mojom::PresentationConnection; | 31 using blink::mojom::PresentationConnection; |
| 29 using blink::mojom::PresentationError; | 32 using blink::mojom::PresentationError; |
| 30 using blink::mojom::PresentationErrorPtr; | 33 using blink::mojom::PresentationErrorPtr; |
| 31 using blink::mojom::PresentationErrorType; | 34 using blink::mojom::PresentationErrorType; |
| 32 using blink::mojom::PresentationService; | 35 using blink::mojom::PresentationService; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 blink::mojom::PresentationConnectionRequest receiver_conn_request) | 113 blink::mojom::PresentationConnectionRequest receiver_conn_request) |
| 111 override { | 114 override { |
| 112 SetPresentationConnection(session.get(), controller_conn_ptr.get()); | 115 SetPresentationConnection(session.get(), controller_conn_ptr.get()); |
| 113 } | 116 } |
| 114 MOCK_METHOD2(SetPresentationConnection, | 117 MOCK_METHOD2(SetPresentationConnection, |
| 115 void(PresentationSessionInfo* session_info, | 118 void(PresentationSessionInfo* session_info, |
| 116 PresentationConnection* connection)); | 119 PresentationConnection* connection)); |
| 117 }; | 120 }; |
| 118 | 121 |
| 119 class TestWebPresentationConnectionCallback | 122 class TestWebPresentationConnectionCallback |
| 120 : public WebPresentationConnectionCallback { | 123 : public WebPresentationConnectionCallbacks { |
| 121 public: | 124 public: |
| 122 TestWebPresentationConnectionCallback(WebURL url, WebString id) | 125 TestWebPresentationConnectionCallback(WebURL url, WebString id) |
| 123 : url_(url), id_(id), callback_called_(false) {} | 126 : url_(url), id_(id), callback_called_(false) {} |
| 124 ~TestWebPresentationConnectionCallback() override { | 127 ~TestWebPresentationConnectionCallback() override { |
| 125 EXPECT_TRUE(callback_called_); | 128 EXPECT_TRUE(callback_called_); |
| 126 } | 129 } |
| 127 | 130 |
| 128 void onSuccess(const WebPresentationSessionInfo& info) override { | 131 void onSuccess(const WebPresentationSessionInfo& info) override { |
| 129 callback_called_ = true; | 132 callback_called_ = true; |
| 130 EXPECT_EQ(info.url, url_); | 133 EXPECT_EQ(info.url, url_); |
| 131 EXPECT_EQ(info.id, id_); | 134 EXPECT_EQ(info.id, id_); |
| 132 } | 135 } |
| 133 | 136 |
| 137 blink::WebPresentationConnection* getConnection() override { return nullptr; } |
| 138 |
| 134 private: | 139 private: |
| 135 const WebURL url_; | 140 const WebURL url_; |
| 136 const WebString id_; | 141 const WebString id_; |
| 137 bool callback_called_; | 142 bool callback_called_; |
| 138 }; | 143 }; |
| 139 | 144 |
| 140 class TestWebPresentationConnectionErrorCallback | 145 class TestWebPresentationConnectionErrorCallback |
| 141 : public WebPresentationConnectionCallback { | 146 : public WebPresentationConnectionCallbacks { |
| 142 public: | 147 public: |
| 143 TestWebPresentationConnectionErrorCallback( | 148 TestWebPresentationConnectionErrorCallback( |
| 144 WebPresentationError::ErrorType error_type, | 149 WebPresentationError::ErrorType error_type, |
| 145 WebString message) | 150 WebString message) |
| 146 : error_type_(error_type), message_(message), callback_called_(false) {} | 151 : error_type_(error_type), message_(message), callback_called_(false) {} |
| 147 ~TestWebPresentationConnectionErrorCallback() override { | 152 ~TestWebPresentationConnectionErrorCallback() override { |
| 148 EXPECT_TRUE(callback_called_); | 153 EXPECT_TRUE(callback_called_); |
| 149 } | 154 } |
| 150 | 155 |
| 151 void onError(const WebPresentationError& error) override { | 156 void onError(const WebPresentationError& error) override { |
| 152 callback_called_ = true; | 157 callback_called_ = true; |
| 153 EXPECT_EQ(error.errorType, error_type_); | 158 EXPECT_EQ(error.errorType, error_type_); |
| 154 EXPECT_EQ(error.message, message_); | 159 EXPECT_EQ(error.message, message_); |
| 155 } | 160 } |
| 156 | 161 |
| 162 blink::WebPresentationConnection* getConnection() override { return nullptr; } |
| 163 |
| 157 private: | 164 private: |
| 158 const WebPresentationError::ErrorType error_type_; | 165 const WebPresentationError::ErrorType error_type_; |
| 159 const WebString message_; | 166 const WebString message_; |
| 160 bool callback_called_; | 167 bool callback_called_; |
| 161 }; | 168 }; |
| 162 | 169 |
| 163 class TestPresentationDispatcher : public PresentationDispatcher { | 170 class TestPresentationDispatcher : public PresentationDispatcher { |
| 164 public: | 171 public: |
| 165 explicit TestPresentationDispatcher( | 172 explicit TestPresentationDispatcher( |
| 166 MockPresentationService* presentation_service) | 173 MockPresentationService* presentation_service) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 .WillOnce(Invoke([this, &message]( | 319 .WillOnce(Invoke([this, &message]( |
| 313 PresentationSessionInfo* session_info, | 320 PresentationSessionInfo* session_info, |
| 314 ConnectionMessage* message_request, | 321 ConnectionMessage* message_request, |
| 315 const PresentationService::SendConnectionMessageCallback& callback) { | 322 const PresentationService::SendConnectionMessageCallback& callback) { |
| 316 EXPECT_EQ(gurl1_, session_info->url); | 323 EXPECT_EQ(gurl1_, session_info->url); |
| 317 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | 324 EXPECT_EQ(presentation_id_.utf8(), session_info->id); |
| 318 EXPECT_TRUE(message_request->message.has_value()); | 325 EXPECT_TRUE(message_request->message.has_value()); |
| 319 EXPECT_EQ(message.utf8(), message_request->message.value()); | 326 EXPECT_EQ(message.utf8(), message_request->message.value()); |
| 320 callback.Run(true); | 327 callback.Run(true); |
| 321 })); | 328 })); |
| 322 dispatcher_.sendString(url1_, presentation_id_, message); | 329 dispatcher_.sendString(url1_, presentation_id_, message, nullptr); |
| 323 run_loop.RunUntilIdle(); | 330 run_loop.RunUntilIdle(); |
| 324 } | 331 } |
| 325 | 332 |
| 326 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { | 333 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { |
| 327 base::RunLoop run_loop; | 334 base::RunLoop run_loop; |
| 328 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 335 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) |
| 329 .WillOnce(Invoke([this]( | 336 .WillOnce(Invoke([this]( |
| 330 PresentationSessionInfo* session_info, | 337 PresentationSessionInfo* session_info, |
| 331 ConnectionMessage* message_request, | 338 ConnectionMessage* message_request, |
| 332 const PresentationService::SendConnectionMessageCallback& callback) { | 339 const PresentationService::SendConnectionMessageCallback& callback) { |
| 333 EXPECT_EQ(gurl1_, session_info->url); | 340 EXPECT_EQ(gurl1_, session_info->url); |
| 334 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | 341 EXPECT_EQ(presentation_id_.utf8(), session_info->id); |
| 335 std::vector<uint8_t> data( | 342 std::vector<uint8_t> data( |
| 336 array_buffer_data(), | 343 array_buffer_data(), |
| 337 array_buffer_data() + array_buffer_.byteLength()); | 344 array_buffer_data() + array_buffer_.byteLength()); |
| 338 EXPECT_TRUE(message_request->data.has_value()); | 345 EXPECT_TRUE(message_request->data.has_value()); |
| 339 EXPECT_EQ(data, message_request->data.value()); | 346 EXPECT_EQ(data, message_request->data.value()); |
| 340 callback.Run(true); | 347 callback.Run(true); |
| 341 })); | 348 })); |
| 342 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), | 349 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), |
| 343 array_buffer_.byteLength()); | 350 array_buffer_.byteLength(), nullptr); |
| 344 run_loop.RunUntilIdle(); | 351 run_loop.RunUntilIdle(); |
| 345 } | 352 } |
| 346 | 353 |
| 347 TEST_F(PresentationDispatcherTest, TestSendBlobData) { | 354 TEST_F(PresentationDispatcherTest, TestSendBlobData) { |
| 348 base::RunLoop run_loop; | 355 base::RunLoop run_loop; |
| 349 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 356 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) |
| 350 .WillOnce(Invoke([this]( | 357 .WillOnce(Invoke([this]( |
| 351 PresentationSessionInfo* session_info, | 358 PresentationSessionInfo* session_info, |
| 352 ConnectionMessage* message_request, | 359 ConnectionMessage* message_request, |
| 353 const PresentationService::SendConnectionMessageCallback& callback) { | 360 const PresentationService::SendConnectionMessageCallback& callback) { |
| 354 EXPECT_EQ(gurl1_, session_info->url); | 361 EXPECT_EQ(gurl1_, session_info->url); |
| 355 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | 362 EXPECT_EQ(presentation_id_.utf8(), session_info->id); |
| 356 std::vector<uint8_t> data( | 363 std::vector<uint8_t> data( |
| 357 array_buffer_data(), | 364 array_buffer_data(), |
| 358 array_buffer_data() + array_buffer_.byteLength()); | 365 array_buffer_data() + array_buffer_.byteLength()); |
| 359 EXPECT_TRUE(message_request->data.has_value()); | 366 EXPECT_TRUE(message_request->data.has_value()); |
| 360 EXPECT_EQ(data, message_request->data.value()); | 367 EXPECT_EQ(data, message_request->data.value()); |
| 361 callback.Run(true); | 368 callback.Run(true); |
| 362 })); | 369 })); |
| 363 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), | 370 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), |
| 364 array_buffer_.byteLength()); | 371 array_buffer_.byteLength(), nullptr); |
| 365 run_loop.RunUntilIdle(); | 372 run_loop.RunUntilIdle(); |
| 366 } | 373 } |
| 367 | 374 |
| 368 TEST_F(PresentationDispatcherTest, TestCloseSession) { | 375 TEST_F(PresentationDispatcherTest, TestCloseSession) { |
| 369 base::RunLoop run_loop; | 376 base::RunLoop run_loop; |
| 370 EXPECT_CALL(presentation_service_, | 377 EXPECT_CALL(presentation_service_, |
| 371 CloseConnection(gurl1_, presentation_id_.utf8())); | 378 CloseConnection(gurl1_, presentation_id_.utf8())); |
| 372 dispatcher_.closeSession(url1_, presentation_id_); | 379 dispatcher_.closeSession(url1_, presentation_id_); |
| 373 run_loop.RunUntilIdle(); | 380 run_loop.RunUntilIdle(); |
| 374 } | 381 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 419 } |
| 413 | 420 |
| 414 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { | 421 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { |
| 415 base::RunLoop run_loop; | 422 base::RunLoop run_loop; |
| 416 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); | 423 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); |
| 417 dispatcher_.setDefaultPresentationUrls(urls_); | 424 dispatcher_.setDefaultPresentationUrls(urls_); |
| 418 run_loop.RunUntilIdle(); | 425 run_loop.RunUntilIdle(); |
| 419 } | 426 } |
| 420 | 427 |
| 421 } // namespace content | 428 } // namespace content |
| OLD | NEW |