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_dispatcher.h" | 11 #include "content/renderer/presentation/presentation_dispatcher.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" | 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" |
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnection.h" | |
15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionCallbacks.h" | |
16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" | |
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" | 17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" |
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" | 18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" |
15 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | 19 #include "third_party/WebKit/public/web/WebArrayBuffer.h" |
16 | 20 |
17 using ::testing::_; | 21 using ::testing::_; |
18 using ::testing::Invoke; | 22 using ::testing::Invoke; |
19 using blink::WebArrayBuffer; | 23 using blink::WebArrayBuffer; |
20 using blink::WebPresentationAvailabilityCallbacks; | 24 using blink::WebPresentationAvailabilityCallbacks; |
21 using blink::WebPresentationAvailabilityObserver; | 25 using blink::WebPresentationAvailabilityObserver; |
22 using blink::WebPresentationConnectionCallback; | 26 using blink::WebPresentationConnectionCallbacks; |
23 using blink::WebPresentationError; | 27 using blink::WebPresentationError; |
24 using blink::WebPresentationSessionInfo; | 28 using blink::WebPresentationSessionInfo; |
25 using blink::WebString; | 29 using blink::WebString; |
26 using blink::WebURL; | 30 using blink::WebURL; |
27 using blink::WebVector; | 31 using blink::WebVector; |
28 using blink::mojom::PresentationConnection; | 32 using blink::mojom::PresentationConnection; |
29 using blink::mojom::PresentationError; | 33 using blink::mojom::PresentationError; |
30 using blink::mojom::PresentationErrorPtr; | 34 using blink::mojom::PresentationErrorPtr; |
31 using blink::mojom::PresentationErrorType; | 35 using blink::mojom::PresentationErrorType; |
32 using blink::mojom::PresentationService; | 36 using blink::mojom::PresentationService; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 blink::mojom::PresentationConnectionPtr controller_conn_ptr, | 114 blink::mojom::PresentationConnectionPtr controller_conn_ptr, |
111 blink::mojom::PresentationConnectionRequest receiver_conn_request) | 115 blink::mojom::PresentationConnectionRequest receiver_conn_request) |
112 override { | 116 override { |
113 SetPresentationConnection(session.get(), controller_conn_ptr.get()); | 117 SetPresentationConnection(session.get(), controller_conn_ptr.get()); |
114 } | 118 } |
115 MOCK_METHOD2(SetPresentationConnection, | 119 MOCK_METHOD2(SetPresentationConnection, |
116 void(PresentationSessionInfo* session_info, | 120 void(PresentationSessionInfo* session_info, |
117 PresentationConnection* connection)); | 121 PresentationConnection* connection)); |
118 }; | 122 }; |
119 | 123 |
124 class TestPresentationConnection : public blink::WebPresentationConnection { | |
mark a. foltz
2017/01/23 20:18:42
Is this identical to the one in presentation_conne
zhaobin
2017/01/24 01:23:24
Done.
| |
125 public: | |
126 void bindProxy( | |
127 std::unique_ptr<blink::WebPresentationConnectionProxy> proxy) override { | |
128 proxy_ = std::move(proxy); | |
129 } | |
130 MOCK_METHOD1(didReceiveTextMessage, void(const WebString& message)); | |
131 MOCK_METHOD2(didReceiveBinaryMessage, | |
132 void(const uint8_t* data, size_t length)); | |
133 MOCK_METHOD1(didChangeState, void(blink::WebPresentationConnectionState)); | |
134 | |
135 std::unique_ptr<blink::WebPresentationConnectionProxy> proxy_; | |
136 }; | |
137 | |
120 class TestWebPresentationConnectionCallback | 138 class TestWebPresentationConnectionCallback |
121 : public WebPresentationConnectionCallback { | 139 : public WebPresentationConnectionCallbacks { |
122 public: | 140 public: |
123 TestWebPresentationConnectionCallback(WebURL url, WebString id) | 141 TestWebPresentationConnectionCallback(WebURL url, WebString id) |
124 : url_(url), id_(id), callback_called_(false) {} | 142 : url_(url), id_(id), callback_called_(false) {} |
125 ~TestWebPresentationConnectionCallback() override { | 143 ~TestWebPresentationConnectionCallback() override { |
126 EXPECT_TRUE(callback_called_); | 144 EXPECT_TRUE(callback_called_); |
127 } | 145 } |
128 | 146 |
129 void onSuccess(const WebPresentationSessionInfo& info) override { | 147 void onSuccess(const WebPresentationSessionInfo& info) override { |
130 callback_called_ = true; | 148 callback_called_ = true; |
131 EXPECT_EQ(info.url, url_); | 149 EXPECT_EQ(info.url, url_); |
132 EXPECT_EQ(info.id, id_); | 150 EXPECT_EQ(info.id, id_); |
133 } | 151 } |
134 | 152 |
153 blink::WebPresentationConnection* getConnection() override { | |
154 return &connection_; | |
155 } | |
156 | |
135 private: | 157 private: |
136 const WebURL url_; | 158 const WebURL url_; |
137 const WebString id_; | 159 const WebString id_; |
138 bool callback_called_; | 160 bool callback_called_; |
161 TestPresentationConnection connection_; | |
139 }; | 162 }; |
140 | 163 |
141 class TestWebPresentationConnectionErrorCallback | 164 class TestWebPresentationConnectionErrorCallback |
142 : public WebPresentationConnectionCallback { | 165 : public WebPresentationConnectionCallbacks { |
143 public: | 166 public: |
144 TestWebPresentationConnectionErrorCallback( | 167 TestWebPresentationConnectionErrorCallback( |
145 WebPresentationError::ErrorType error_type, | 168 WebPresentationError::ErrorType error_type, |
146 WebString message) | 169 WebString message) |
147 : error_type_(error_type), message_(message), callback_called_(false) {} | 170 : error_type_(error_type), message_(message), callback_called_(false) {} |
148 ~TestWebPresentationConnectionErrorCallback() override { | 171 ~TestWebPresentationConnectionErrorCallback() override { |
149 EXPECT_TRUE(callback_called_); | 172 EXPECT_TRUE(callback_called_); |
150 } | 173 } |
151 | 174 |
152 void onError(const WebPresentationError& error) override { | 175 void onError(const WebPresentationError& error) override { |
153 callback_called_ = true; | 176 callback_called_ = true; |
154 EXPECT_EQ(error.errorType, error_type_); | 177 EXPECT_EQ(error.errorType, error_type_); |
155 EXPECT_EQ(error.message, message_); | 178 EXPECT_EQ(error.message, message_); |
156 } | 179 } |
157 | 180 |
181 blink::WebPresentationConnection* getConnection() override { return nullptr; } | |
182 | |
158 private: | 183 private: |
159 const WebPresentationError::ErrorType error_type_; | 184 const WebPresentationError::ErrorType error_type_; |
160 const WebString message_; | 185 const WebString message_; |
161 bool callback_called_; | 186 bool callback_called_; |
162 }; | 187 }; |
163 | 188 |
164 class TestPresentationDispatcher : public PresentationDispatcher { | 189 class TestPresentationDispatcher : public PresentationDispatcher { |
165 public: | 190 public: |
166 explicit TestPresentationDispatcher( | 191 explicit TestPresentationDispatcher( |
167 MockPresentationService* presentation_service) | 192 MockPresentationService* presentation_service) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 .WillOnce(Invoke([this, &message]( | 338 .WillOnce(Invoke([this, &message]( |
314 PresentationSessionInfo* session_info, | 339 PresentationSessionInfo* session_info, |
315 ConnectionMessage* message_request, | 340 ConnectionMessage* message_request, |
316 const PresentationService::SendConnectionMessageCallback& callback) { | 341 const PresentationService::SendConnectionMessageCallback& callback) { |
317 EXPECT_EQ(gurl1_, session_info->url); | 342 EXPECT_EQ(gurl1_, session_info->url); |
318 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | 343 EXPECT_EQ(presentation_id_.utf8(), session_info->id); |
319 EXPECT_TRUE(message_request->message.has_value()); | 344 EXPECT_TRUE(message_request->message.has_value()); |
320 EXPECT_EQ(message.utf8(), message_request->message.value()); | 345 EXPECT_EQ(message.utf8(), message_request->message.value()); |
321 callback.Run(true); | 346 callback.Run(true); |
322 })); | 347 })); |
323 dispatcher_.sendString(url1_, presentation_id_, message); | 348 dispatcher_.sendString(url1_, presentation_id_, message, nullptr); |
324 run_loop.RunUntilIdle(); | 349 run_loop.RunUntilIdle(); |
325 } | 350 } |
326 | 351 |
327 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { | 352 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { |
328 base::RunLoop run_loop; | 353 base::RunLoop run_loop; |
329 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 354 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) |
330 .WillOnce(Invoke([this]( | 355 .WillOnce(Invoke([this]( |
331 PresentationSessionInfo* session_info, | 356 PresentationSessionInfo* session_info, |
332 ConnectionMessage* message_request, | 357 ConnectionMessage* message_request, |
333 const PresentationService::SendConnectionMessageCallback& callback) { | 358 const PresentationService::SendConnectionMessageCallback& callback) { |
334 EXPECT_EQ(gurl1_, session_info->url); | 359 EXPECT_EQ(gurl1_, session_info->url); |
335 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | 360 EXPECT_EQ(presentation_id_.utf8(), session_info->id); |
336 std::vector<uint8_t> data( | 361 std::vector<uint8_t> data( |
337 array_buffer_data(), | 362 array_buffer_data(), |
338 array_buffer_data() + array_buffer_.byteLength()); | 363 array_buffer_data() + array_buffer_.byteLength()); |
339 EXPECT_TRUE(message_request->data.has_value()); | 364 EXPECT_TRUE(message_request->data.has_value()); |
340 EXPECT_EQ(data, message_request->data.value()); | 365 EXPECT_EQ(data, message_request->data.value()); |
341 callback.Run(true); | 366 callback.Run(true); |
342 })); | 367 })); |
343 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), | 368 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), |
344 array_buffer_.byteLength()); | 369 array_buffer_.byteLength(), nullptr); |
345 run_loop.RunUntilIdle(); | 370 run_loop.RunUntilIdle(); |
346 } | 371 } |
347 | 372 |
348 TEST_F(PresentationDispatcherTest, TestSendBlobData) { | 373 TEST_F(PresentationDispatcherTest, TestSendBlobData) { |
349 base::RunLoop run_loop; | 374 base::RunLoop run_loop; |
350 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) | 375 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) |
351 .WillOnce(Invoke([this]( | 376 .WillOnce(Invoke([this]( |
352 PresentationSessionInfo* session_info, | 377 PresentationSessionInfo* session_info, |
353 ConnectionMessage* message_request, | 378 ConnectionMessage* message_request, |
354 const PresentationService::SendConnectionMessageCallback& callback) { | 379 const PresentationService::SendConnectionMessageCallback& callback) { |
355 EXPECT_EQ(gurl1_, session_info->url); | 380 EXPECT_EQ(gurl1_, session_info->url); |
356 EXPECT_EQ(presentation_id_.utf8(), session_info->id); | 381 EXPECT_EQ(presentation_id_.utf8(), session_info->id); |
357 std::vector<uint8_t> data( | 382 std::vector<uint8_t> data( |
358 array_buffer_data(), | 383 array_buffer_data(), |
359 array_buffer_data() + array_buffer_.byteLength()); | 384 array_buffer_data() + array_buffer_.byteLength()); |
360 EXPECT_TRUE(message_request->data.has_value()); | 385 EXPECT_TRUE(message_request->data.has_value()); |
361 EXPECT_EQ(data, message_request->data.value()); | 386 EXPECT_EQ(data, message_request->data.value()); |
362 callback.Run(true); | 387 callback.Run(true); |
363 })); | 388 })); |
364 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), | 389 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), |
365 array_buffer_.byteLength()); | 390 array_buffer_.byteLength(), nullptr); |
366 run_loop.RunUntilIdle(); | 391 run_loop.RunUntilIdle(); |
367 } | 392 } |
368 | 393 |
369 TEST_F(PresentationDispatcherTest, TestCloseSession) { | 394 TEST_F(PresentationDispatcherTest, TestCloseSession) { |
370 base::RunLoop run_loop; | 395 base::RunLoop run_loop; |
371 EXPECT_CALL(presentation_service_, | 396 EXPECT_CALL(presentation_service_, |
372 CloseConnection(gurl1_, presentation_id_.utf8())); | 397 CloseConnection(gurl1_, presentation_id_.utf8())); |
373 dispatcher_.closeSession(url1_, presentation_id_); | 398 dispatcher_.closeSession(url1_, presentation_id_); |
374 run_loop.RunUntilIdle(); | 399 run_loop.RunUntilIdle(); |
375 } | 400 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 } | 438 } |
414 | 439 |
415 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { | 440 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { |
416 base::RunLoop run_loop; | 441 base::RunLoop run_loop; |
417 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); | 442 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); |
418 dispatcher_.setDefaultPresentationUrls(urls_); | 443 dispatcher_.setDefaultPresentationUrls(urls_); |
419 run_loop.RunUntilIdle(); | 444 run_loop.RunUntilIdle(); |
420 } | 445 } |
421 | 446 |
422 } // namespace content | 447 } // namespace content |
OLD | NEW |