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

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

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Fix compile error in presentation_connection_message Created 3 years, 9 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/common/presentation_connection_message.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 10 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "content/renderer/presentation/presentation_connection_proxy.h" 11 #include "content/renderer/presentation/presentation_connection_proxy.h"
11 #include "content/renderer/presentation/presentation_dispatcher.h" 12 #include "content/renderer/presentation/presentation_dispatcher.h"
12 #include "content/renderer/presentation/test_presentation_connection.h" 13 #include "content/renderer/presentation/test_presentation_connection.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" 15 #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 nConnection.h"
16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionCallbacks.h" 17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionCallbacks.h"
17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" 18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h"
20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h"
21 #include "third_party/WebKit/public/web/WebArrayBuffer.h" 22 #include "third_party/WebKit/public/web/WebArrayBuffer.h"
22 23
23 using ::testing::_; 24 using ::testing::_;
24 using ::testing::Invoke; 25 using ::testing::Invoke;
25 using blink::WebArrayBuffer; 26 using blink::WebArrayBuffer;
26 using blink::WebPresentationAvailabilityCallbacks; 27 using blink::WebPresentationAvailabilityCallbacks;
27 using blink::WebPresentationAvailabilityObserver; 28 using blink::WebPresentationAvailabilityObserver;
28 using blink::WebPresentationConnectionCallbacks; 29 using blink::WebPresentationConnectionCallbacks;
29 using blink::WebPresentationError; 30 using blink::WebPresentationError;
30 using blink::WebPresentationSessionInfo; 31 using blink::WebPresentationSessionInfo;
31 using blink::WebString; 32 using blink::WebString;
32 using blink::WebURL; 33 using blink::WebURL;
33 using blink::WebVector; 34 using blink::WebVector;
34 using blink::mojom::PresentationConnection; 35 using blink::mojom::PresentationConnection;
35 using blink::mojom::PresentationService; 36 using blink::mojom::PresentationService;
36 using blink::mojom::PresentationServiceClientPtr; 37 using blink::mojom::PresentationServiceClientPtr;
37 using blink::mojom::ConnectionMessage;
38 using blink::mojom::ConnectionMessagePtr;
39 38
40 // TODO(crbug.com/576808): Add test cases for the following: 39 // TODO(crbug.com/576808): Add test cases for the following:
41 // - State changes 40 // - State changes
42 // - Messages received 41 // - Messages received
43 // - Discarding queued messages when the frame navigates 42 // - Discarding queued messages when the frame navigates
44 // - Screen availability not supported 43 // - Screen availability not supported
45 // - Default presentation starting 44 // - Default presentation starting
46 45
47 namespace content { 46 namespace content {
48 47
(...skipping 20 matching lines...) Expand all
69 MOCK_METHOD1(StopListeningForScreenAvailability, 68 MOCK_METHOD1(StopListeningForScreenAvailability,
70 void(const GURL& availability_url)); 69 void(const GURL& availability_url));
71 MOCK_METHOD2(StartSession, 70 MOCK_METHOD2(StartSession,
72 void(const std::vector<GURL>& presentation_urls, 71 void(const std::vector<GURL>& presentation_urls,
73 const StartSessionCallback& callback)); 72 const StartSessionCallback& callback));
74 MOCK_METHOD3(JoinSession, 73 MOCK_METHOD3(JoinSession,
75 void(const std::vector<GURL>& presentation_urls, 74 void(const std::vector<GURL>& presentation_urls,
76 const base::Optional<std::string>& presentation_id, 75 const base::Optional<std::string>& presentation_id,
77 const JoinSessionCallback& callback)); 76 const JoinSessionCallback& callback));
78 77
79 // *Internal method is to work around lack of support for move-only types in 78 MOCK_METHOD3(SendConnectionMessage,
80 // GMock.
81 void SendConnectionMessage(
82 const PresentationSessionInfo& session_info,
83 ConnectionMessagePtr message_request,
84 const SendConnectionMessageCallback& callback) override {
85 SendConnectionMessageInternal(session_info, message_request.get(),
86 callback);
87 }
88 MOCK_METHOD3(SendConnectionMessageInternal,
89 void(const PresentationSessionInfo& session_info, 79 void(const PresentationSessionInfo& session_info,
90 ConnectionMessage* message_request, 80 const PresentationConnectionMessage& message_request,
91 const SendConnectionMessageCallback& callback)); 81 const SendConnectionMessageCallback& callback));
92
93 MOCK_METHOD2(CloseConnection, 82 MOCK_METHOD2(CloseConnection,
94 void(const GURL& presentation_url, 83 void(const GURL& presentation_url,
95 const std::string& presentation_id)); 84 const std::string& presentation_id));
96 MOCK_METHOD2(Terminate, 85 MOCK_METHOD2(Terminate,
97 void(const GURL& presentation_url, 86 void(const GURL& presentation_url,
98 const std::string& presentation_id)); 87 const std::string& presentation_id));
99 88
100 MOCK_METHOD1(ListenForConnectionMessages, 89 MOCK_METHOD1(ListenForConnectionMessages,
101 void(const PresentationSessionInfo& session_info)); 90 void(const PresentationSessionInfo& session_info));
102 91
103 void SetPresentationConnection( 92 void SetPresentationConnection(
104 const PresentationSessionInfo& session_info, 93 const PresentationSessionInfo& session_info,
105 blink::mojom::PresentationConnectionPtr controller_conn_ptr, 94 blink::mojom::PresentationConnectionPtr controller_conn_ptr,
106 blink::mojom::PresentationConnectionRequest receiver_conn_request) 95 blink::mojom::PresentationConnectionRequest receiver_conn_request)
107 override { 96 override {
108 SetPresentationConnection(session_info, controller_conn_ptr.get()); 97 SetPresentationConnection(session_info, controller_conn_ptr.get());
109 } 98 }
110 MOCK_METHOD2(SetPresentationConnection, 99 MOCK_METHOD2(SetPresentationConnection,
111 void(const PresentationSessionInfo& session_info, 100 void(const PresentationSessionInfo& session_info,
112 PresentationConnection* connection)); 101 PresentationConnection* connection));
113 }; 102 };
114 103
115 class TestPresentationConnectionProxy : public PresentationConnectionProxy { 104 class TestPresentationConnectionProxy : public PresentationConnectionProxy {
116 public: 105 public:
117 TestPresentationConnectionProxy(blink::WebPresentationConnection* connection) 106 TestPresentationConnectionProxy(blink::WebPresentationConnection* connection)
118 : PresentationConnectionProxy(connection) {} 107 : PresentationConnectionProxy(connection) {}
119 108
120 void SendConnectionMessage(blink::mojom::ConnectionMessagePtr session_message, 109 MOCK_CONST_METHOD2(SendConnectionMessage,
121 const OnMessageCallback& callback) const override { 110 void(const PresentationConnectionMessage&,
122 SendConnectionMessageInternal(session_message.get(), callback);
123 }
124 MOCK_CONST_METHOD2(SendConnectionMessageInternal,
125 void(blink::mojom::ConnectionMessage*,
126 const OnMessageCallback&)); 111 const OnMessageCallback&));
127 }; 112 };
128 113
129 class TestPresentationReceiver : public blink::WebPresentationReceiver { 114 class TestPresentationReceiver : public blink::WebPresentationReceiver {
130 public: 115 public:
131 blink::WebPresentationConnection* onReceiverConnectionAvailable( 116 blink::WebPresentationConnection* onReceiverConnectionAvailable(
132 const blink::WebPresentationSessionInfo&) override { 117 const blink::WebPresentationSessionInfo&) override {
133 return &connection_; 118 return &connection_;
134 } 119 }
135 120
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 run_loop.RunUntilIdle(); 400 run_loop.RunUntilIdle();
416 } 401 }
417 EXPECT_TRUE(connection.proxy()); 402 EXPECT_TRUE(connection.proxy());
418 } 403 }
419 404
420 TEST_F(PresentationDispatcherTest, TestSendString) { 405 TEST_F(PresentationDispatcherTest, TestSendString) {
421 WebString message = WebString::fromUTF8("test message"); 406 WebString message = WebString::fromUTF8("test message");
422 TestPresentationConnection connection; 407 TestPresentationConnection connection;
423 TestPresentationConnectionProxy connection_proxy(&connection); 408 TestPresentationConnectionProxy connection_proxy(&connection);
424 409
410 PresentationConnectionMessage expected_message(message.utf8());
411
425 base::RunLoop run_loop; 412 base::RunLoop run_loop;
426 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) 413 EXPECT_CALL(connection_proxy, SendConnectionMessage(_, _))
427 .WillOnce(Invoke([&message](ConnectionMessage* session_message, 414 .WillOnce(Invoke([&expected_message](
428 const OnMessageCallback& callback) { 415 const PresentationConnectionMessage& message_request,
429 EXPECT_EQ(blink::mojom::PresentationMessageType::TEXT, 416 const OnMessageCallback& callback) {
430 session_message->type); 417 EXPECT_EQ(message_request, expected_message);
431 EXPECT_EQ(message.utf8(), session_message->message.value()); 418 callback.Run(true);
432 })); 419 }));
420
433 dispatcher_.sendString(url1_, presentation_id_, message, &connection_proxy); 421 dispatcher_.sendString(url1_, presentation_id_, message, &connection_proxy);
434 run_loop.RunUntilIdle(); 422 run_loop.RunUntilIdle();
435 } 423 }
436 424
437 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { 425 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) {
426 std::vector<uint8_t> data(array_buffer_data(),
427 array_buffer_data() + array_buffer_.byteLength());
438 TestPresentationConnection connection; 428 TestPresentationConnection connection;
439 TestPresentationConnectionProxy connection_proxy(&connection); 429 TestPresentationConnectionProxy connection_proxy(&connection);
430 PresentationConnectionMessage expected_message(data);
440 431
441 base::RunLoop run_loop; 432 base::RunLoop run_loop;
442 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) 433 EXPECT_CALL(connection_proxy, SendConnectionMessage(_, _))
443 .WillOnce(Invoke([this](ConnectionMessage* message_request, 434 .WillOnce(Invoke([&expected_message](
444 const OnMessageCallback& callback) { 435 const PresentationConnectionMessage& message_request,
445 std::vector<uint8_t> data( 436 const OnMessageCallback& callback) {
446 array_buffer_data(), 437 EXPECT_EQ(message_request, expected_message);
447 array_buffer_data() + array_buffer_.byteLength()); 438 callback.Run(true);
448 EXPECT_TRUE(message_request->data.has_value());
449 EXPECT_EQ(data, message_request->data.value());
450 })); 439 }));
451 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), 440 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(),
452 array_buffer_.byteLength(), &connection_proxy); 441 array_buffer_.byteLength(), &connection_proxy);
453 run_loop.RunUntilIdle(); 442 run_loop.RunUntilIdle();
454 } 443 }
455 444
456 TEST_F(PresentationDispatcherTest, TestSendBlobData) { 445 TEST_F(PresentationDispatcherTest, TestSendBlobData) {
446 std::vector<uint8_t> data(array_buffer_data(),
447 array_buffer_data() + array_buffer_.byteLength());
457 TestPresentationConnection connection; 448 TestPresentationConnection connection;
458 TestPresentationConnectionProxy connection_proxy(&connection); 449 TestPresentationConnectionProxy connection_proxy(&connection);
450 PresentationConnectionMessage expected_message(data);
459 451
460 base::RunLoop run_loop; 452 base::RunLoop run_loop;
461 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) 453 EXPECT_CALL(connection_proxy, SendConnectionMessage(_, _))
462 .WillOnce(Invoke([this](ConnectionMessage* message_request, 454 .WillOnce(Invoke([&expected_message](
463 const OnMessageCallback& callback) { 455 const PresentationConnectionMessage& message_request,
464 std::vector<uint8_t> data( 456 const OnMessageCallback& callback) {
465 array_buffer_data(), 457 EXPECT_EQ(message_request, expected_message);
466 array_buffer_data() + array_buffer_.byteLength());
467 EXPECT_TRUE(message_request->data.has_value());
468 EXPECT_EQ(data, message_request->data.value());
469 callback.Run(true); 458 callback.Run(true);
470 })); 459 }));
471 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), 460 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(),
472 array_buffer_.byteLength(), &connection_proxy); 461 array_buffer_.byteLength(), &connection_proxy);
473 run_loop.RunUntilIdle(); 462 run_loop.RunUntilIdle();
474 } 463 }
475 464
476 TEST_F(PresentationDispatcherTest, TestOnReceiverConnectionAvailable) { 465 TEST_F(PresentationDispatcherTest, TestOnReceiverConnectionAvailable) {
477 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8()); 466 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8());
478 467
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 772
784 for (auto* mock_observer : mock_observers_) 773 for (auto* mock_observer : mock_observers_)
785 EXPECT_CALL(*mock_observer, availabilityChanged(false)); 774 EXPECT_CALL(*mock_observer, availabilityChanged(false));
786 775
787 base::RunLoop run_loop_2; 776 base::RunLoop run_loop_2;
788 ChangeURLState(gurl2_, URLState::Unavailable); 777 ChangeURLState(gurl2_, URLState::Unavailable);
789 run_loop_2.RunUntilIdle(); 778 run_loop_2.RunUntilIdle();
790 } 779 }
791 780
792 } // namespace content 781 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698