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

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 Derek and Mark 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_connection_proxy.h"
10 #include "content/renderer/presentation/presentation_dispatcher.h" 11 #include "content/renderer/presentation/presentation_dispatcher.h"
12 #include "content/renderer/presentation/test_presentation_connection.h"
11 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
12 #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"
16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionCallbacks.h"
17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" 18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h"
15 #include "third_party/WebKit/public/web/WebArrayBuffer.h" 20 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
16 21
17 using ::testing::_; 22 using ::testing::_;
18 using ::testing::Invoke; 23 using ::testing::Invoke;
19 using blink::WebArrayBuffer; 24 using blink::WebArrayBuffer;
20 using blink::WebPresentationAvailabilityCallbacks; 25 using blink::WebPresentationAvailabilityCallbacks;
21 using blink::WebPresentationAvailabilityObserver; 26 using blink::WebPresentationAvailabilityObserver;
22 using blink::WebPresentationConnectionCallback; 27 using blink::WebPresentationConnectionCallbacks;
23 using blink::WebPresentationError; 28 using blink::WebPresentationError;
24 using blink::WebPresentationSessionInfo; 29 using blink::WebPresentationSessionInfo;
25 using blink::WebString; 30 using blink::WebString;
26 using blink::WebURL; 31 using blink::WebURL;
27 using blink::WebVector; 32 using blink::WebVector;
28 using blink::mojom::PresentationConnection; 33 using blink::mojom::PresentationConnection;
29 using blink::mojom::PresentationError; 34 using blink::mojom::PresentationError;
30 using blink::mojom::PresentationErrorPtr; 35 using blink::mojom::PresentationErrorPtr;
31 using blink::mojom::PresentationErrorType; 36 using blink::mojom::PresentationErrorType;
32 using blink::mojom::PresentationService; 37 using blink::mojom::PresentationService;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 }; 123 };
119 124
120 class MockPresentationAvailabilityCallbacks 125 class MockPresentationAvailabilityCallbacks
121 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> { 126 : public blink::WebCallbacks<bool, const blink::WebPresentationError&> {
122 public: 127 public:
123 MOCK_METHOD1(onSuccess, void(bool value)); 128 MOCK_METHOD1(onSuccess, void(bool value));
124 MOCK_METHOD1(onError, void(const blink::WebPresentationError&)); 129 MOCK_METHOD1(onError, void(const blink::WebPresentationError&));
125 }; 130 };
126 131
127 class TestWebPresentationConnectionCallback 132 class TestWebPresentationConnectionCallback
128 : public WebPresentationConnectionCallback { 133 : public WebPresentationConnectionCallbacks {
129 public: 134 public:
130 TestWebPresentationConnectionCallback(WebURL url, WebString id) 135 TestWebPresentationConnectionCallback(WebURL url, WebString id)
131 : url_(url), id_(id), callback_called_(false) {} 136 : url_(url), id_(id), callback_called_(false) {}
132 ~TestWebPresentationConnectionCallback() override { 137 ~TestWebPresentationConnectionCallback() override {
133 EXPECT_TRUE(callback_called_); 138 EXPECT_TRUE(callback_called_);
134 } 139 }
135 140
136 void onSuccess(const WebPresentationSessionInfo& info) override { 141 void onSuccess(const WebPresentationSessionInfo& info) override {
137 callback_called_ = true; 142 callback_called_ = true;
138 EXPECT_EQ(info.url, url_); 143 EXPECT_EQ(info.url, url_);
139 EXPECT_EQ(info.id, id_); 144 EXPECT_EQ(info.id, id_);
140 } 145 }
141 146
147 blink::WebPresentationConnection* getConnection() override {
148 return &connection_;
149 }
150
142 private: 151 private:
143 const WebURL url_; 152 const WebURL url_;
144 const WebString id_; 153 const WebString id_;
145 bool callback_called_; 154 bool callback_called_;
155 TestPresentationConnection connection_;
146 }; 156 };
147 157
148 class TestWebPresentationConnectionErrorCallback 158 class TestWebPresentationConnectionErrorCallback
149 : public WebPresentationConnectionCallback { 159 : public WebPresentationConnectionCallbacks {
150 public: 160 public:
151 TestWebPresentationConnectionErrorCallback( 161 TestWebPresentationConnectionErrorCallback(
152 WebPresentationError::ErrorType error_type, 162 WebPresentationError::ErrorType error_type,
153 WebString message) 163 WebString message)
154 : error_type_(error_type), message_(message), callback_called_(false) {} 164 : error_type_(error_type), message_(message), callback_called_(false) {}
155 ~TestWebPresentationConnectionErrorCallback() override { 165 ~TestWebPresentationConnectionErrorCallback() override {
156 EXPECT_TRUE(callback_called_); 166 EXPECT_TRUE(callback_called_);
157 } 167 }
158 168
159 void onError(const WebPresentationError& error) override { 169 void onError(const WebPresentationError& error) override {
160 callback_called_ = true; 170 callback_called_ = true;
161 EXPECT_EQ(error.errorType, error_type_); 171 EXPECT_EQ(error.errorType, error_type_);
162 EXPECT_EQ(error.message, message_); 172 EXPECT_EQ(error.message, message_);
163 } 173 }
164 174
175 blink::WebPresentationConnection* getConnection() override { return nullptr; }
176
165 private: 177 private:
166 const WebPresentationError::ErrorType error_type_; 178 const WebPresentationError::ErrorType error_type_;
167 const WebString message_; 179 const WebString message_;
168 bool callback_called_; 180 bool callback_called_;
169 }; 181 };
170 182
171 class TestPresentationDispatcher : public PresentationDispatcher { 183 class TestPresentationDispatcher : public PresentationDispatcher {
172 public: 184 public:
173 explicit TestPresentationDispatcher( 185 explicit TestPresentationDispatcher(
174 MockPresentationService* presentation_service) 186 MockPresentationService* presentation_service)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 .WillOnce(Invoke([this, &message]( 395 .WillOnce(Invoke([this, &message](
384 PresentationSessionInfo* session_info, 396 PresentationSessionInfo* session_info,
385 ConnectionMessage* message_request, 397 ConnectionMessage* message_request,
386 const PresentationService::SendConnectionMessageCallback& callback) { 398 const PresentationService::SendConnectionMessageCallback& callback) {
387 EXPECT_EQ(gurl1_, session_info->url); 399 EXPECT_EQ(gurl1_, session_info->url);
388 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 400 EXPECT_EQ(presentation_id_.utf8(), session_info->id);
389 EXPECT_TRUE(message_request->message.has_value()); 401 EXPECT_TRUE(message_request->message.has_value());
390 EXPECT_EQ(message.utf8(), message_request->message.value()); 402 EXPECT_EQ(message.utf8(), message_request->message.value());
391 callback.Run(true); 403 callback.Run(true);
392 })); 404 }));
393 dispatcher_.sendString(url1_, presentation_id_, message); 405 dispatcher_.sendString(url1_, presentation_id_, message, nullptr);
394 run_loop.RunUntilIdle(); 406 run_loop.RunUntilIdle();
395 } 407 }
396 408
397 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { 409 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) {
398 base::RunLoop run_loop; 410 base::RunLoop run_loop;
399 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 411 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
400 .WillOnce(Invoke([this]( 412 .WillOnce(Invoke([this](
401 PresentationSessionInfo* session_info, 413 PresentationSessionInfo* session_info,
402 ConnectionMessage* message_request, 414 ConnectionMessage* message_request,
403 const PresentationService::SendConnectionMessageCallback& callback) { 415 const PresentationService::SendConnectionMessageCallback& callback) {
404 EXPECT_EQ(gurl1_, session_info->url); 416 EXPECT_EQ(gurl1_, session_info->url);
405 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 417 EXPECT_EQ(presentation_id_.utf8(), session_info->id);
406 std::vector<uint8_t> data( 418 std::vector<uint8_t> data(
407 array_buffer_data(), 419 array_buffer_data(),
408 array_buffer_data() + array_buffer_.byteLength()); 420 array_buffer_data() + array_buffer_.byteLength());
409 EXPECT_TRUE(message_request->data.has_value()); 421 EXPECT_TRUE(message_request->data.has_value());
410 EXPECT_EQ(data, message_request->data.value()); 422 EXPECT_EQ(data, message_request->data.value());
411 callback.Run(true); 423 callback.Run(true);
412 })); 424 }));
413 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), 425 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(),
414 array_buffer_.byteLength()); 426 array_buffer_.byteLength(), nullptr);
415 run_loop.RunUntilIdle(); 427 run_loop.RunUntilIdle();
416 } 428 }
417 429
418 TEST_F(PresentationDispatcherTest, TestSendBlobData) { 430 TEST_F(PresentationDispatcherTest, TestSendBlobData) {
419 base::RunLoop run_loop; 431 base::RunLoop run_loop;
420 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _)) 432 EXPECT_CALL(presentation_service_, SendConnectionMessageInternal(_, _, _))
421 .WillOnce(Invoke([this]( 433 .WillOnce(Invoke([this](
422 PresentationSessionInfo* session_info, 434 PresentationSessionInfo* session_info,
423 ConnectionMessage* message_request, 435 ConnectionMessage* message_request,
424 const PresentationService::SendConnectionMessageCallback& callback) { 436 const PresentationService::SendConnectionMessageCallback& callback) {
425 EXPECT_EQ(gurl1_, session_info->url); 437 EXPECT_EQ(gurl1_, session_info->url);
426 EXPECT_EQ(presentation_id_.utf8(), session_info->id); 438 EXPECT_EQ(presentation_id_.utf8(), session_info->id);
427 std::vector<uint8_t> data( 439 std::vector<uint8_t> data(
428 array_buffer_data(), 440 array_buffer_data(),
429 array_buffer_data() + array_buffer_.byteLength()); 441 array_buffer_data() + array_buffer_.byteLength());
430 EXPECT_TRUE(message_request->data.has_value()); 442 EXPECT_TRUE(message_request->data.has_value());
431 EXPECT_EQ(data, message_request->data.value()); 443 EXPECT_EQ(data, message_request->data.value());
432 callback.Run(true); 444 callback.Run(true);
433 })); 445 }));
434 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), 446 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(),
435 array_buffer_.byteLength()); 447 array_buffer_.byteLength(), nullptr);
436 run_loop.RunUntilIdle(); 448 run_loop.RunUntilIdle();
437 } 449 }
438 450
439 TEST_F(PresentationDispatcherTest, TestCloseSession) { 451 TEST_F(PresentationDispatcherTest, TestCloseSession) {
440 base::RunLoop run_loop; 452 base::RunLoop run_loop;
441 EXPECT_CALL(presentation_service_, 453 EXPECT_CALL(presentation_service_,
442 CloseConnection(gurl1_, presentation_id_.utf8())); 454 CloseConnection(gurl1_, presentation_id_.utf8()));
443 dispatcher_.closeSession(url1_, presentation_id_); 455 dispatcher_.closeSession(url1_, presentation_id_);
444 run_loop.RunUntilIdle(); 456 run_loop.RunUntilIdle();
445 } 457 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 727
716 for (auto* mock_observer : mock_observers_) 728 for (auto* mock_observer : mock_observers_)
717 EXPECT_CALL(*mock_observer, availabilityChanged(false)); 729 EXPECT_CALL(*mock_observer, availabilityChanged(false));
718 730
719 base::RunLoop run_loop_2; 731 base::RunLoop run_loop_2;
720 ChangeURLState(gurl2_, URLState::Unavailable); 732 ChangeURLState(gurl2_, URLState::Unavailable);
721 run_loop_2.RunUntilIdle(); 733 run_loop_2.RunUntilIdle();
722 } 734 }
723 735
724 } // namespace content 736 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.cc ('k') | content/renderer/presentation/test_presentation_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698