| 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" |
| 17 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nInfo.h" |
| 18 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nReceiver.h" |
| 16 | 19 |
| 17 using ::testing::_; | 20 using ::testing::_; |
| 18 | 21 |
| 19 namespace content { | 22 namespace content { |
| 20 | 23 |
| 24 class MockWebPresentationReceiver : public blink::WebPresentationReceiver { |
| 25 public: |
| 26 MOCK_METHOD1( |
| 27 OnReceiverConnectionAvailable, |
| 28 blink::WebPresentationConnection*(const blink::WebPresentationInfo&)); |
| 29 MOCK_METHOD1(DidChangeConnectionState, |
| 30 void(blink::WebPresentationConnectionState)); |
| 31 MOCK_METHOD0(TerminateConnection, void()); |
| 32 MOCK_METHOD1(RemoveConnection, void(blink::WebPresentationConnection*)); |
| 33 }; |
| 34 |
| 21 class PresentationConnectionProxyTest : public ::testing::Test { | 35 class PresentationConnectionProxyTest : public ::testing::Test { |
| 22 public: | 36 public: |
| 23 PresentationConnectionProxyTest() = default; | 37 PresentationConnectionProxyTest() = default; |
| 24 ~PresentationConnectionProxyTest() override = default; | 38 ~PresentationConnectionProxyTest() override = default; |
| 25 | 39 |
| 26 void SetUp() override { | 40 void SetUp() override { |
| 27 // Set up test connections and test connection proxies. | 41 // Set up test connections and test connection proxies. |
| 28 controller_connection_ = base::MakeUnique<TestPresentationConnection>(); | 42 controller_connection_ = base::MakeUnique<TestPresentationConnection>(); |
| 29 receiver_connection_ = base::MakeUnique<TestPresentationConnection>(); | 43 receiver_connection_ = base::MakeUnique<TestPresentationConnection>(); |
| 30 | 44 |
| 31 controller_connection_proxy_ = | 45 controller_connection_proxy_ = |
| 32 new ControllerConnectionProxy(controller_connection_.get()); | 46 new ControllerConnectionProxy(controller_connection_.get()); |
| 33 controller_connection_->BindProxy( | 47 controller_connection_->BindProxy( |
| 34 base::WrapUnique(controller_connection_proxy_)); | 48 base::WrapUnique(controller_connection_proxy_)); |
| 35 receiver_connection_proxy_ = | 49 receiver_connection_proxy_ = new ReceiverConnectionProxy( |
| 36 new ReceiverConnectionProxy(receiver_connection_.get()); | 50 receiver_connection_.get(), &mock_receiver_); |
| 37 receiver_connection_->BindProxy( | 51 receiver_connection_->BindProxy( |
| 38 base::WrapUnique(receiver_connection_proxy_)); | 52 base::WrapUnique(receiver_connection_proxy_)); |
| 39 | 53 |
| 40 EXPECT_CALL( | 54 EXPECT_CALL( |
| 41 *controller_connection_, | 55 *controller_connection_, |
| 42 DidChangeState(blink::WebPresentationConnectionState::kConnected)); | 56 DidChangeState(blink::WebPresentationConnectionState::kConnected)); |
| 43 EXPECT_CALL( | 57 EXPECT_CALL( |
| 44 *receiver_connection_, | 58 *receiver_connection_, |
| 45 DidChangeState(blink::WebPresentationConnectionState::kConnected)); | 59 DidChangeState(blink::WebPresentationConnectionState::kConnected)); |
| 46 | 60 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 | 71 |
| 58 void ExpectSendConnectionMessageCallback(bool success) { | 72 void ExpectSendConnectionMessageCallback(bool success) { |
| 59 EXPECT_TRUE(success); | 73 EXPECT_TRUE(success); |
| 60 } | 74 } |
| 61 | 75 |
| 62 protected: | 76 protected: |
| 63 std::unique_ptr<TestPresentationConnection> controller_connection_; | 77 std::unique_ptr<TestPresentationConnection> controller_connection_; |
| 64 std::unique_ptr<TestPresentationConnection> receiver_connection_; | 78 std::unique_ptr<TestPresentationConnection> receiver_connection_; |
| 65 ControllerConnectionProxy* controller_connection_proxy_; | 79 ControllerConnectionProxy* controller_connection_proxy_; |
| 66 ReceiverConnectionProxy* receiver_connection_proxy_; | 80 ReceiverConnectionProxy* receiver_connection_proxy_; |
| 81 MockWebPresentationReceiver mock_receiver_; |
| 67 | 82 |
| 68 private: | 83 private: |
| 69 content::TestBrowserThreadBundle thread_bundle_; | 84 content::TestBrowserThreadBundle thread_bundle_; |
| 70 }; | 85 }; |
| 71 | 86 |
| 72 TEST_F(PresentationConnectionProxyTest, TestSendString) { | 87 TEST_F(PresentationConnectionProxyTest, TestSendString) { |
| 73 blink::WebString message = blink::WebString::FromUTF8("test message"); | 88 blink::WebString message = blink::WebString::FromUTF8("test message"); |
| 74 base::RunLoop run_loop; | 89 base::RunLoop run_loop; |
| 75 EXPECT_CALL(*receiver_connection_, DidReceiveTextMessage(message)); | 90 EXPECT_CALL(*receiver_connection_, DidReceiveTextMessage(message)); |
| 76 controller_connection_proxy_->SendConnectionMessage( | 91 controller_connection_proxy_->SendConnectionMessage( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 99 base::Bind( | 114 base::Bind( |
| 100 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, | 115 &PresentationConnectionProxyTest::ExpectSendConnectionMessageCallback, |
| 101 base::Unretained(this))); | 116 base::Unretained(this))); |
| 102 run_loop.RunUntilIdle(); | 117 run_loop.RunUntilIdle(); |
| 103 } | 118 } |
| 104 | 119 |
| 105 TEST_F(PresentationConnectionProxyTest, TestControllerConnectionCallsClose) { | 120 TEST_F(PresentationConnectionProxyTest, TestControllerConnectionCallsClose) { |
| 106 base::RunLoop run_loop; | 121 base::RunLoop run_loop; |
| 107 EXPECT_CALL(*controller_connection_, DidClose()); | 122 EXPECT_CALL(*controller_connection_, DidClose()); |
| 108 EXPECT_CALL(*receiver_connection_, DidClose()); | 123 EXPECT_CALL(*receiver_connection_, DidClose()); |
| 124 EXPECT_CALL(mock_receiver_, RemoveConnection(receiver_connection_.get())); |
| 109 controller_connection_proxy_->Close(); | 125 controller_connection_proxy_->Close(); |
| 110 run_loop.RunUntilIdle(); | 126 run_loop.RunUntilIdle(); |
| 111 } | 127 } |
| 112 | 128 |
| 113 TEST_F(PresentationConnectionProxyTest, TestReceiverConnectionCallsClose) { | 129 TEST_F(PresentationConnectionProxyTest, TestReceiverConnectionCallsClose) { |
| 114 base::RunLoop run_loop; | 130 base::RunLoop run_loop; |
| 115 EXPECT_CALL(*controller_connection_, DidClose()); | 131 EXPECT_CALL(*controller_connection_, DidClose()); |
| 116 EXPECT_CALL(*receiver_connection_, DidClose()); | 132 EXPECT_CALL(*receiver_connection_, DidClose()); |
| 133 EXPECT_CALL(mock_receiver_, RemoveConnection(receiver_connection_.get())); |
| 117 receiver_connection_proxy_->Close(); | 134 receiver_connection_proxy_->Close(); |
| 118 run_loop.RunUntilIdle(); | 135 run_loop.RunUntilIdle(); |
| 119 } | 136 } |
| 120 | 137 |
| 121 TEST_F(PresentationConnectionProxyTest, TestReceiverNotifyTargetConnection) { | 138 TEST_F(PresentationConnectionProxyTest, TestReceiverNotifyTargetConnection) { |
| 122 base::RunLoop run_loop; | 139 base::RunLoop run_loop; |
| 123 EXPECT_CALL( | 140 EXPECT_CALL( |
| 124 *controller_connection_, | 141 *controller_connection_, |
| 125 DidChangeState(blink::WebPresentationConnectionState::kTerminated)); | 142 DidChangeState(blink::WebPresentationConnectionState::kTerminated)); |
| 126 receiver_connection_proxy_->NotifyTargetConnection( | 143 receiver_connection_proxy_->NotifyTargetConnection( |
| 127 blink::WebPresentationConnectionState::kTerminated); | 144 blink::WebPresentationConnectionState::kTerminated); |
| 128 run_loop.RunUntilIdle(); | 145 run_loop.RunUntilIdle(); |
| 129 } | 146 } |
| 130 | 147 |
| 131 } // namespace content | 148 } // namespace content |
| OLD | NEW |