Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: content/renderer/presentation/presentation_dispatcher_unittest.cc

Issue 2471263003: [Presentation API] (4th)(1-UA blink side) Add WebPresentationConnection and WebPresentationConnecti… (Closed)
Patch Set: resolve code review comments from dcheng Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 blink::mojom::PresentationConnectionRequest receiver_conn_request) 114 blink::mojom::PresentationConnectionRequest receiver_conn_request)
112 override { 115 override {
113 SetPresentationConnection(session.get(), controller_conn_ptr.get()); 116 SetPresentationConnection(session.get(), controller_conn_ptr.get());
114 } 117 }
115 MOCK_METHOD2(SetPresentationConnection, 118 MOCK_METHOD2(SetPresentationConnection,
116 void(PresentationSessionInfo* session_info, 119 void(PresentationSessionInfo* session_info,
117 PresentationConnection* connection)); 120 PresentationConnection* connection));
118 }; 121 };
119 122
120 class TestWebPresentationConnectionCallback 123 class TestWebPresentationConnectionCallback
121 : public WebPresentationConnectionCallback { 124 : public WebPresentationConnectionCallbacks {
122 public: 125 public:
123 TestWebPresentationConnectionCallback(WebURL url, WebString id) 126 TestWebPresentationConnectionCallback(WebURL url, WebString id)
124 : url_(url), id_(id), callback_called_(false) {} 127 : url_(url), id_(id), callback_called_(false) {}
125 ~TestWebPresentationConnectionCallback() override { 128 ~TestWebPresentationConnectionCallback() override {
126 EXPECT_TRUE(callback_called_); 129 EXPECT_TRUE(callback_called_);
127 } 130 }
128 131
129 void onSuccess(const WebPresentationSessionInfo& info) override { 132 void onSuccess(const WebPresentationSessionInfo& info) override {
130 callback_called_ = true; 133 callback_called_ = true;
131 EXPECT_EQ(info.url, url_); 134 EXPECT_EQ(info.url, url_);
132 EXPECT_EQ(info.id, id_); 135 EXPECT_EQ(info.id, id_);
133 } 136 }
134 137
138 blink::WebPresentationConnection* getConnection() override { return nullptr; }
139
135 private: 140 private:
136 const WebURL url_; 141 const WebURL url_;
137 const WebString id_; 142 const WebString id_;
138 bool callback_called_; 143 bool callback_called_;
139 }; 144 };
140 145
141 class TestWebPresentationConnectionErrorCallback 146 class TestWebPresentationConnectionErrorCallback
142 : public WebPresentationConnectionCallback { 147 : public WebPresentationConnectionCallbacks {
143 public: 148 public:
144 TestWebPresentationConnectionErrorCallback( 149 TestWebPresentationConnectionErrorCallback(
145 WebPresentationError::ErrorType error_type, 150 WebPresentationError::ErrorType error_type,
146 WebString message) 151 WebString message)
147 : error_type_(error_type), message_(message), callback_called_(false) {} 152 : error_type_(error_type), message_(message), callback_called_(false) {}
148 ~TestWebPresentationConnectionErrorCallback() override { 153 ~TestWebPresentationConnectionErrorCallback() override {
149 EXPECT_TRUE(callback_called_); 154 EXPECT_TRUE(callback_called_);
150 } 155 }
151 156
152 void onError(const WebPresentationError& error) override { 157 void onError(const WebPresentationError& error) override {
153 callback_called_ = true; 158 callback_called_ = true;
154 EXPECT_EQ(error.errorType, error_type_); 159 EXPECT_EQ(error.errorType, error_type_);
155 EXPECT_EQ(error.message, message_); 160 EXPECT_EQ(error.message, message_);
156 } 161 }
157 162
163 blink::WebPresentationConnection* getConnection() override { return nullptr; }
164
158 private: 165 private:
159 const WebPresentationError::ErrorType error_type_; 166 const WebPresentationError::ErrorType error_type_;
160 const WebString message_; 167 const WebString message_;
161 bool callback_called_; 168 bool callback_called_;
162 }; 169 };
163 170
164 class TestPresentationDispatcher : public PresentationDispatcher { 171 class TestPresentationDispatcher : public PresentationDispatcher {
165 public: 172 public:
166 explicit TestPresentationDispatcher( 173 explicit TestPresentationDispatcher(
167 MockPresentationService* presentation_service) 174 MockPresentationService* presentation_service)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 .WillOnce(Invoke([this, &message]( 320 .WillOnce(Invoke([this, &message](
314 PresentationSessionInfo* session_info, 321 PresentationSessionInfo* session_info,
315 ConnectionMessage* message_request, 322 ConnectionMessage* message_request,
316 const PresentationService::SendConnectionMessageCallback& callback) { 323 const PresentationService::SendConnectionMessageCallback& callback) {
317 EXPECT_EQ(gurl1_, session_info->url); 324 EXPECT_EQ(gurl1_, session_info->url);
318 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 325 EXPECT_EQ(presentation_id_.utf8(), session_info->id);
319 EXPECT_TRUE(message_request->message.has_value()); 326 EXPECT_TRUE(message_request->message.has_value());
320 EXPECT_EQ(message.utf8(), message_request->message.value()); 327 EXPECT_EQ(message.utf8(), message_request->message.value());
321 callback.Run(true); 328 callback.Run(true);
322 })); 329 }));
323 dispatcher_.sendString(url1_, presentation_id_, message); 330 dispatcher_.sendString(url1_, presentation_id_, message, nullptr);
324 run_loop.RunUntilIdle(); 331 run_loop.RunUntilIdle();
325 } 332 }
326 333
327 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { 334 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) {
328 base::RunLoop run_loop; 335 base::RunLoop run_loop;
329 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 336 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
330 .WillOnce(Invoke([this]( 337 .WillOnce(Invoke([this](
331 PresentationSessionInfo* session_info, 338 PresentationSessionInfo* session_info,
332 ConnectionMessage* message_request, 339 ConnectionMessage* message_request,
333 const PresentationService::SendConnectionMessageCallback& callback) { 340 const PresentationService::SendConnectionMessageCallback& callback) {
334 EXPECT_EQ(gurl1_, session_info->url); 341 EXPECT_EQ(gurl1_, session_info->url);
335 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 342 EXPECT_EQ(presentation_id_.utf8(), session_info->id);
336 std::vector<uint8_t> data( 343 std::vector<uint8_t> data(
337 array_buffer_data(), 344 array_buffer_data(),
338 array_buffer_data() + array_buffer_.byteLength()); 345 array_buffer_data() + array_buffer_.byteLength());
339 EXPECT_TRUE(message_request->data.has_value()); 346 EXPECT_TRUE(message_request->data.has_value());
340 EXPECT_EQ(data, message_request->data.value()); 347 EXPECT_EQ(data, message_request->data.value());
341 callback.Run(true); 348 callback.Run(true);
342 })); 349 }));
343 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), 350 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(),
344 array_buffer_.byteLength()); 351 array_buffer_.byteLength(), nullptr);
345 run_loop.RunUntilIdle(); 352 run_loop.RunUntilIdle();
346 } 353 }
347 354
348 TEST_F(PresentationDispatcherTest, TestSendBlobData) { 355 TEST_F(PresentationDispatcherTest, TestSendBlobData) {
349 base::RunLoop run_loop; 356 base::RunLoop run_loop;
350 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 357 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
351 .WillOnce(Invoke([this]( 358 .WillOnce(Invoke([this](
352 PresentationSessionInfo* session_info, 359 PresentationSessionInfo* session_info,
353 ConnectionMessage* message_request, 360 ConnectionMessage* message_request,
354 const PresentationService::SendConnectionMessageCallback& callback) { 361 const PresentationService::SendConnectionMessageCallback& callback) {
355 EXPECT_EQ(gurl1_, session_info->url); 362 EXPECT_EQ(gurl1_, session_info->url);
356 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 363 EXPECT_EQ(presentation_id_.utf8(), session_info->id);
357 std::vector<uint8_t> data( 364 std::vector<uint8_t> data(
358 array_buffer_data(), 365 array_buffer_data(),
359 array_buffer_data() + array_buffer_.byteLength()); 366 array_buffer_data() + array_buffer_.byteLength());
360 EXPECT_TRUE(message_request->data.has_value()); 367 EXPECT_TRUE(message_request->data.has_value());
361 EXPECT_EQ(data, message_request->data.value()); 368 EXPECT_EQ(data, message_request->data.value());
362 callback.Run(true); 369 callback.Run(true);
363 })); 370 }));
364 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), 371 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(),
365 array_buffer_.byteLength()); 372 array_buffer_.byteLength(), nullptr);
366 run_loop.RunUntilIdle(); 373 run_loop.RunUntilIdle();
367 } 374 }
368 375
369 TEST_F(PresentationDispatcherTest, TestCloseSession) { 376 TEST_F(PresentationDispatcherTest, TestCloseSession) {
370 base::RunLoop run_loop; 377 base::RunLoop run_loop;
371 EXPECT_CALL(presentation_service_, 378 EXPECT_CALL(presentation_service_,
372 CloseConnection(gurl1_, presentation_id_.utf8())); 379 CloseConnection(gurl1_, presentation_id_.utf8()));
373 dispatcher_.closeSession(url1_, presentation_id_); 380 dispatcher_.closeSession(url1_, presentation_id_);
374 run_loop.RunUntilIdle(); 381 run_loop.RunUntilIdle();
375 } 382 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 420 }
414 421
415 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) { 422 TEST_F(PresentationDispatcherTest, TestSetDefaultPresentationUrls) {
416 base::RunLoop run_loop; 423 base::RunLoop run_loop;
417 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_)); 424 EXPECT_CALL(presentation_service_, SetDefaultPresentationUrls(gurls_));
418 dispatcher_.setDefaultPresentationUrls(urls_); 425 dispatcher_.setDefaultPresentationUrls(urls_);
419 run_loop.RunUntilIdle(); 426 run_loop.RunUntilIdle();
420 } 427 }
421 428
422 } // namespace content 429 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698