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

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

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Remove TODO 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 19 matching lines...) Expand all
68 MOCK_METHOD1(ListenForScreenAvailability, void(const GURL& availability_url)); 67 MOCK_METHOD1(ListenForScreenAvailability, void(const GURL& availability_url));
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
79 MOCK_METHOD2(CloseConnection, 77 MOCK_METHOD2(CloseConnection,
80 void(const GURL& presentation_url, 78 void(const GURL& presentation_url,
81 const std::string& presentation_id)); 79 const std::string& presentation_id));
82 MOCK_METHOD2(Terminate, 80 MOCK_METHOD2(Terminate,
83 void(const GURL& presentation_url, 81 void(const GURL& presentation_url,
84 const std::string& presentation_id)); 82 const std::string& presentation_id));
85 83
86 MOCK_METHOD1(ListenForConnectionMessages, 84 MOCK_METHOD1(ListenForConnectionMessages,
87 void(const PresentationSessionInfo& session_info)); 85 void(const PresentationSessionInfo& session_info));
88 86
89 void SetPresentationConnection( 87 void SetPresentationConnection(
90 const PresentationSessionInfo& session_info, 88 const PresentationSessionInfo& session_info,
91 blink::mojom::PresentationConnectionPtr controller_conn_ptr, 89 blink::mojom::PresentationConnectionPtr controller_conn_ptr,
92 blink::mojom::PresentationConnectionRequest receiver_conn_request) 90 blink::mojom::PresentationConnectionRequest receiver_conn_request)
93 override { 91 override {
94 SetPresentationConnection(session_info, controller_conn_ptr.get()); 92 SetPresentationConnection(session_info, controller_conn_ptr.get());
95 } 93 }
96 MOCK_METHOD2(SetPresentationConnection, 94 MOCK_METHOD2(SetPresentationConnection,
97 void(const PresentationSessionInfo& session_info, 95 void(const PresentationSessionInfo& session_info,
98 PresentationConnection* connection)); 96 PresentationConnection* connection));
99 }; 97 };
100 98
101 class TestPresentationConnectionProxy : public PresentationConnectionProxy { 99 class TestPresentationConnectionProxy : public PresentationConnectionProxy {
102 public: 100 public:
103 TestPresentationConnectionProxy(blink::WebPresentationConnection* connection) 101 TestPresentationConnectionProxy(blink::WebPresentationConnection* connection)
104 : PresentationConnectionProxy(connection) {} 102 : PresentationConnectionProxy(connection) {}
105 103
106 void SendConnectionMessage(blink::mojom::ConnectionMessagePtr session_message, 104 MOCK_CONST_METHOD2(SendConnectionMessage,
107 const OnMessageCallback& callback) const override { 105 void(const PresentationConnectionMessage&,
108 SendConnectionMessageInternal(session_message.get(), callback);
109 }
110 MOCK_CONST_METHOD2(SendConnectionMessageInternal,
111 void(blink::mojom::ConnectionMessage*,
112 const OnMessageCallback&)); 106 const OnMessageCallback&));
113 }; 107 };
114 108
115 class TestPresentationReceiver : public blink::WebPresentationReceiver { 109 class TestPresentationReceiver : public blink::WebPresentationReceiver {
116 public: 110 public:
117 blink::WebPresentationConnection* onReceiverConnectionAvailable( 111 blink::WebPresentationConnection* onReceiverConnectionAvailable(
118 const blink::WebPresentationSessionInfo&) override { 112 const blink::WebPresentationSessionInfo&) override {
119 return &connection_; 113 return &connection_;
120 } 114 }
121 115
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 run_loop.RunUntilIdle(); 395 run_loop.RunUntilIdle();
402 } 396 }
403 EXPECT_TRUE(connection.proxy()); 397 EXPECT_TRUE(connection.proxy());
404 } 398 }
405 399
406 TEST_F(PresentationDispatcherTest, TestSendString) { 400 TEST_F(PresentationDispatcherTest, TestSendString) {
407 WebString message = WebString::fromUTF8("test message"); 401 WebString message = WebString::fromUTF8("test message");
408 TestPresentationConnection connection; 402 TestPresentationConnection connection;
409 TestPresentationConnectionProxy connection_proxy(&connection); 403 TestPresentationConnectionProxy connection_proxy(&connection);
410 404
405 PresentationConnectionMessage expected_message(message.utf8());
406
411 base::RunLoop run_loop; 407 base::RunLoop run_loop;
412 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) 408 EXPECT_CALL(connection_proxy, SendConnectionMessage(_, _))
413 .WillOnce(Invoke([&message](ConnectionMessage* session_message, 409 .WillOnce(Invoke([&expected_message](
414 const OnMessageCallback& callback) { 410 const PresentationConnectionMessage& message_request,
415 EXPECT_EQ(blink::mojom::PresentationMessageType::TEXT, 411 const OnMessageCallback& callback) {
416 session_message->type); 412 EXPECT_EQ(message_request, expected_message);
417 EXPECT_EQ(message.utf8(), session_message->message.value()); 413 callback.Run(true);
418 })); 414 }));
415
419 dispatcher_.sendString(url1_, presentation_id_, message, &connection_proxy); 416 dispatcher_.sendString(url1_, presentation_id_, message, &connection_proxy);
420 run_loop.RunUntilIdle(); 417 run_loop.RunUntilIdle();
421 } 418 }
422 419
423 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) { 420 TEST_F(PresentationDispatcherTest, TestSendArrayBuffer) {
421 std::vector<uint8_t> data(array_buffer_data(),
422 array_buffer_data() + array_buffer_.byteLength());
424 TestPresentationConnection connection; 423 TestPresentationConnection connection;
425 TestPresentationConnectionProxy connection_proxy(&connection); 424 TestPresentationConnectionProxy connection_proxy(&connection);
425 PresentationConnectionMessage expected_message(data);
426 426
427 base::RunLoop run_loop; 427 base::RunLoop run_loop;
428 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) 428 EXPECT_CALL(connection_proxy, SendConnectionMessage(_, _))
429 .WillOnce(Invoke([this](ConnectionMessage* message_request, 429 .WillOnce(Invoke([&expected_message](
430 const OnMessageCallback& callback) { 430 const PresentationConnectionMessage& message_request,
431 std::vector<uint8_t> data( 431 const OnMessageCallback& callback) {
432 array_buffer_data(), 432 EXPECT_EQ(message_request, expected_message);
433 array_buffer_data() + array_buffer_.byteLength()); 433 callback.Run(true);
434 EXPECT_TRUE(message_request->data.has_value());
435 EXPECT_EQ(data, message_request->data.value());
436 })); 434 }));
437 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(), 435 dispatcher_.sendArrayBuffer(url1_, presentation_id_, array_buffer_data(),
438 array_buffer_.byteLength(), &connection_proxy); 436 array_buffer_.byteLength(), &connection_proxy);
439 run_loop.RunUntilIdle(); 437 run_loop.RunUntilIdle();
440 } 438 }
441 439
442 TEST_F(PresentationDispatcherTest, TestSendBlobData) { 440 TEST_F(PresentationDispatcherTest, TestSendBlobData) {
441 std::vector<uint8_t> data(array_buffer_data(),
442 array_buffer_data() + array_buffer_.byteLength());
443 TestPresentationConnection connection; 443 TestPresentationConnection connection;
444 TestPresentationConnectionProxy connection_proxy(&connection); 444 TestPresentationConnectionProxy connection_proxy(&connection);
445 PresentationConnectionMessage expected_message(data);
445 446
446 base::RunLoop run_loop; 447 base::RunLoop run_loop;
447 EXPECT_CALL(connection_proxy, SendConnectionMessageInternal(_, _)) 448 EXPECT_CALL(connection_proxy, SendConnectionMessage(_, _))
448 .WillOnce(Invoke([this](ConnectionMessage* message_request, 449 .WillOnce(Invoke([&expected_message](
449 const OnMessageCallback& callback) { 450 const PresentationConnectionMessage& message_request,
450 std::vector<uint8_t> data( 451 const OnMessageCallback& callback) {
451 array_buffer_data(), 452 EXPECT_EQ(message_request, expected_message);
452 array_buffer_data() + array_buffer_.byteLength());
453 EXPECT_TRUE(message_request->data.has_value());
454 EXPECT_EQ(data, message_request->data.value());
455 callback.Run(true); 453 callback.Run(true);
456 })); 454 }));
457 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(), 455 dispatcher_.sendBlobData(url1_, presentation_id_, array_buffer_data(),
458 array_buffer_.byteLength(), &connection_proxy); 456 array_buffer_.byteLength(), &connection_proxy);
459 run_loop.RunUntilIdle(); 457 run_loop.RunUntilIdle();
460 } 458 }
461 459
462 TEST_F(PresentationDispatcherTest, TestOnReceiverConnectionAvailable) { 460 TEST_F(PresentationDispatcherTest, TestOnReceiverConnectionAvailable) {
463 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8()); 461 PresentationSessionInfo session_info(gurl1_, presentation_id_.utf8());
464 462
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 767
770 for (auto* mock_observer : mock_observers_) 768 for (auto* mock_observer : mock_observers_)
771 EXPECT_CALL(*mock_observer, availabilityChanged(false)); 769 EXPECT_CALL(*mock_observer, availabilityChanged(false));
772 770
773 base::RunLoop run_loop_2; 771 base::RunLoop run_loop_2;
774 ChangeURLState(gurl2_, URLState::Unavailable); 772 ChangeURLState(gurl2_, URLState::Unavailable);
775 run_loop_2.RunUntilIdle(); 773 run_loop_2.RunUntilIdle();
776 } 774 }
777 775
778 } // namespace content 776 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698