OLD | NEW |
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 "base/test/mock_callback.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/test_presentation_connection.h" | 12 #include "content/renderer/presentation/test_presentation_connection.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" | 15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" |
15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" | 16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
16 | 17 |
17 using ::testing::_; | 18 using ::testing::_; |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 class PresentationConnectionProxyTest : public ::testing::Test { | 22 class PresentationConnectionProxyTest : public ::testing::Test { |
22 public: | 23 public: |
23 PresentationConnectionProxyTest() = default; | 24 PresentationConnectionProxyTest() = default; |
24 ~PresentationConnectionProxyTest() override = default; | 25 ~PresentationConnectionProxyTest() override = default; |
25 | 26 |
26 void SetUp() override { | 27 void SetUp() override { |
27 // Set up test connections and test connection proxies. | 28 // Set up test connections and test connection proxies. |
28 controller_connection_ = base::MakeUnique<TestPresentationConnection>(); | 29 controller_connection_ = base::MakeUnique<TestPresentationConnection>(); |
29 receiver_connection_ = base::MakeUnique<TestPresentationConnection>(); | 30 receiver_connection_ = base::MakeUnique<TestPresentationConnection>(); |
30 | 31 |
31 controller_connection_proxy_ = | 32 controller_connection_proxy_ = |
32 new ControllerConnectionProxy(controller_connection_.get()); | 33 new ControllerConnectionProxy(controller_connection_.get()); |
33 controller_connection_->BindProxy( | 34 controller_connection_->BindProxy( |
34 base::WrapUnique(controller_connection_proxy_)); | 35 base::WrapUnique(controller_connection_proxy_)); |
35 receiver_connection_proxy_ = | 36 receiver_connection_proxy_ = new ReceiverConnectionProxy( |
36 new ReceiverConnectionProxy(receiver_connection_.get()); | 37 receiver_connection_.get(), mock_connection_closed_callback_.Get()); |
37 receiver_connection_->BindProxy( | 38 receiver_connection_->BindProxy( |
38 base::WrapUnique(receiver_connection_proxy_)); | 39 base::WrapUnique(receiver_connection_proxy_)); |
39 | 40 |
40 EXPECT_CALL( | 41 EXPECT_CALL( |
41 *controller_connection_, | 42 *controller_connection_, |
42 DidChangeState(blink::WebPresentationConnectionState::kConnected)); | 43 DidChangeState(blink::WebPresentationConnectionState::kConnected)); |
43 EXPECT_CALL( | 44 EXPECT_CALL( |
44 *receiver_connection_, | 45 *receiver_connection_, |
45 DidChangeState(blink::WebPresentationConnectionState::kConnected)); | 46 DidChangeState(blink::WebPresentationConnectionState::kConnected)); |
46 | 47 |
(...skipping 10 matching lines...) Expand all Loading... |
57 | 58 |
58 void ExpectSendConnectionMessageCallback(bool success) { | 59 void ExpectSendConnectionMessageCallback(bool success) { |
59 EXPECT_TRUE(success); | 60 EXPECT_TRUE(success); |
60 } | 61 } |
61 | 62 |
62 protected: | 63 protected: |
63 std::unique_ptr<TestPresentationConnection> controller_connection_; | 64 std::unique_ptr<TestPresentationConnection> controller_connection_; |
64 std::unique_ptr<TestPresentationConnection> receiver_connection_; | 65 std::unique_ptr<TestPresentationConnection> receiver_connection_; |
65 ControllerConnectionProxy* controller_connection_proxy_; | 66 ControllerConnectionProxy* controller_connection_proxy_; |
66 ReceiverConnectionProxy* receiver_connection_proxy_; | 67 ReceiverConnectionProxy* receiver_connection_proxy_; |
| 68 base::MockCallback<ReceiverConnectionProxy::OnConnectionClosedCallback> |
| 69 mock_connection_closed_callback_; |
67 | 70 |
68 private: | 71 private: |
69 content::TestBrowserThreadBundle thread_bundle_; | 72 content::TestBrowserThreadBundle thread_bundle_; |
70 }; | 73 }; |
71 | 74 |
72 TEST_F(PresentationConnectionProxyTest, TestSendString) { | 75 TEST_F(PresentationConnectionProxyTest, TestSendString) { |
73 blink::WebString message = blink::WebString::FromUTF8("test message"); | 76 blink::WebString message = blink::WebString::FromUTF8("test message"); |
74 base::RunLoop run_loop; | 77 base::RunLoop run_loop; |
75 EXPECT_CALL(*receiver_connection_, DidReceiveTextMessage(message)); | 78 EXPECT_CALL(*receiver_connection_, DidReceiveTextMessage(message)); |
76 controller_connection_proxy_->SendConnectionMessage( | 79 controller_connection_proxy_->SendConnectionMessage( |
(...skipping 22 matching lines...) Expand all Loading... |
99 base::Bind( | 102 base::Bind( |
100 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, | 103 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, |
101 base::Unretained(this))); | 104 base::Unretained(this))); |
102 run_loop.RunUntilIdle(); | 105 run_loop.RunUntilIdle(); |
103 } | 106 } |
104 | 107 |
105 TEST_F(PresentationConnectionProxyTest, TestControllerConnectionCallsClose) { | 108 TEST_F(PresentationConnectionProxyTest, TestControllerConnectionCallsClose) { |
106 base::RunLoop run_loop; | 109 base::RunLoop run_loop; |
107 EXPECT_CALL(*controller_connection_, DidClose()); | 110 EXPECT_CALL(*controller_connection_, DidClose()); |
108 EXPECT_CALL(*receiver_connection_, DidClose()); | 111 EXPECT_CALL(*receiver_connection_, DidClose()); |
| 112 EXPECT_CALL(mock_connection_closed_callback_, Run()); |
109 controller_connection_proxy_->Close(); | 113 controller_connection_proxy_->Close(); |
110 run_loop.RunUntilIdle(); | 114 run_loop.RunUntilIdle(); |
111 } | 115 } |
112 | 116 |
113 TEST_F(PresentationConnectionProxyTest, TestReceiverConnectionCallsClose) { | 117 TEST_F(PresentationConnectionProxyTest, TestReceiverConnectionCallsClose) { |
114 base::RunLoop run_loop; | 118 base::RunLoop run_loop; |
115 EXPECT_CALL(*controller_connection_, DidClose()); | 119 EXPECT_CALL(*controller_connection_, DidClose()); |
116 EXPECT_CALL(*receiver_connection_, DidClose()); | 120 EXPECT_CALL(*receiver_connection_, DidClose()); |
| 121 EXPECT_CALL(mock_connection_closed_callback_, Run()); |
117 receiver_connection_proxy_->Close(); | 122 receiver_connection_proxy_->Close(); |
118 run_loop.RunUntilIdle(); | 123 run_loop.RunUntilIdle(); |
119 } | 124 } |
120 | 125 |
121 } // namespace content | 126 } // namespace content |
OLD | NEW |