OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <memory> | |
6 #include <utility> | |
7 | |
8 #include "base/run_loop.h" | |
9 #include "content/public/test/test_browser_thread_bundle.h" | |
10 #include "content/renderer/presentation/presentation_connection_proxy.h" | |
11 #include "content/renderer/presentation/test_presentation_connection.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnection.h" | |
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" | |
15 | |
16 using ::testing::_; | |
17 | |
18 namespace content { | |
19 | |
20 class PresentationConnectionProxyTest : public ::testing::Test { | |
21 public: | |
22 PresentationConnectionProxyTest() {} | |
23 ~PresentationConnectionProxyTest() override {} | |
mlamouri (slow - plz ping)
2017/01/26 22:18:02
= default for both?
zhaobin
2017/01/26 22:48:14
Done.
| |
24 | |
25 void SetUp() override { | |
26 // Set up test connections and test connection proxies. | |
27 controller_connection_ = base::MakeUnique<TestPresentationConnection>(); | |
28 receiver_connection_ = base::MakeUnique<TestPresentationConnection>(); | |
29 | |
30 controller_connection_proxy_ = | |
31 new ControllerConnectionProxy(controller_connection_.get()); | |
32 controller_connection_->bindProxy( | |
33 base::WrapUnique(controller_connection_proxy_)); | |
34 receiver_connection_proxy_ = | |
35 new ReceiverConnectionProxy(receiver_connection_.get()); | |
36 receiver_connection_->bindProxy( | |
37 base::WrapUnique(receiver_connection_proxy_)); | |
38 | |
39 EXPECT_CALL( | |
40 *controller_connection_, | |
41 didChangeState(blink::WebPresentationConnectionState::Connected)); | |
42 EXPECT_CALL( | |
43 *receiver_connection_, | |
44 didChangeState(blink::WebPresentationConnectionState::Connected)); | |
45 | |
46 receiver_connection_proxy_->Bind( | |
47 controller_connection_proxy_->MakeRemoteRequest()); | |
48 receiver_connection_proxy_->BindControllerConnection( | |
49 controller_connection_proxy_->Bind()); | |
50 } | |
51 | |
52 void TearDown() override { | |
53 controller_connection_.reset(); | |
54 receiver_connection_.reset(); | |
55 } | |
56 | |
57 void ExpectSendConnectionMessageCallback(bool success) { | |
58 EXPECT_TRUE(success); | |
59 } | |
60 | |
61 protected: | |
62 std::unique_ptr<TestPresentationConnection> controller_connection_; | |
63 std::unique_ptr<TestPresentationConnection> receiver_connection_; | |
64 ControllerConnectionProxy* controller_connection_proxy_; | |
65 ReceiverConnectionProxy* receiver_connection_proxy_; | |
66 | |
67 private: | |
68 content::TestBrowserThreadBundle thread_bundle_; | |
69 }; | |
70 | |
71 TEST_F(PresentationConnectionProxyTest, TestSendString) { | |
72 blink::WebString message = blink::WebString::fromUTF8("test message"); | |
73 blink::mojom::ConnectionMessagePtr session_message = | |
74 blink::mojom::ConnectionMessage::New(); | |
75 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
76 session_message->message = message.utf8(); | |
77 | |
78 base::RunLoop run_loop; | |
79 EXPECT_CALL(*receiver_connection_, didReceiveTextMessage(message)); | |
80 controller_connection_proxy_->SendConnectionMessage( | |
81 std::move(session_message), | |
82 base::Bind( | |
83 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, | |
84 base::Unretained(this))); | |
85 run_loop.RunUntilIdle(); | |
86 } | |
87 | |
88 TEST_F(PresentationConnectionProxyTest, TestSendArrayBuffer) { | |
89 std::vector<uint8_t> expected_data; | |
90 expected_data.push_back(42); | |
91 expected_data.push_back(36); | |
92 | |
93 blink::mojom::ConnectionMessagePtr session_message = | |
94 blink::mojom::ConnectionMessage::New(); | |
95 session_message->type = blink::mojom::PresentationMessageType::BINARY; | |
96 session_message->data = expected_data; | |
97 | |
98 base::RunLoop run_loop; | |
99 EXPECT_CALL(*receiver_connection_, didReceiveBinaryMessage(_, _)) | |
100 .WillOnce(::testing::Invoke( | |
101 [this, &expected_data](const uint8_t* data, size_t length) { | |
102 std::vector<uint8_t> message_data(data, data + length); | |
103 EXPECT_EQ(expected_data, message_data); | |
104 })); | |
105 | |
106 controller_connection_proxy_->SendConnectionMessage( | |
107 std::move(session_message), | |
108 base::Bind( | |
109 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, | |
110 base::Unretained(this))); | |
111 run_loop.RunUntilIdle(); | |
112 } | |
113 | |
114 } // namespace content | |
OLD | NEW |