| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/presentation/PresentationReceiver.h" | 5 #include "modules/presentation/PresentationReceiver.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 using ::testing::StrictMock; | 66 using ::testing::StrictMock; |
| 67 | 67 |
| 68 TEST_F(PresentationReceiverTest, NoConnectionUnresolvedConnectionList) { | 68 TEST_F(PresentationReceiverTest, NoConnectionUnresolvedConnectionList) { |
| 69 V8TestingScope scope; | 69 V8TestingScope scope; |
| 70 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); | 70 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); |
| 71 | 71 |
| 72 auto event_handler = new StrictMock<MockEventListener>(); | 72 auto event_handler = new StrictMock<MockEventListener>(); |
| 73 AddConnectionavailableEventListener(event_handler, receiver); | 73 AddConnectionavailableEventListener(event_handler, receiver); |
| 74 EXPECT_CALL(*event_handler, handleEvent(testing::_, testing::_)).Times(0); | 74 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0); |
| 75 | 75 |
| 76 receiver->connectionList(scope.GetScriptState()); | 76 receiver->connectionList(scope.GetScriptState()); |
| 77 | 77 |
| 78 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kPending, | 78 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kPending, |
| 79 receiver); | 79 receiver); |
| 80 VerifyConnectionListSize(0, receiver); | 80 VerifyConnectionListSize(0, receiver); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(PresentationReceiverTest, OneConnectionResolvedConnectionListNoEvent) { | 83 TEST_F(PresentationReceiverTest, OneConnectionResolvedConnectionListNoEvent) { |
| 84 V8TestingScope scope; | 84 V8TestingScope scope; |
| 85 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); | 85 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); |
| 86 | 86 |
| 87 auto event_handler = new StrictMock<MockEventListener>(); | 87 auto event_handler = new StrictMock<MockEventListener>(); |
| 88 AddConnectionavailableEventListener(event_handler, receiver); | 88 AddConnectionavailableEventListener(event_handler, receiver); |
| 89 EXPECT_CALL(*event_handler, handleEvent(testing::_, testing::_)).Times(0); | 89 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0); |
| 90 | 90 |
| 91 receiver->connectionList(scope.GetScriptState()); | 91 receiver->connectionList(scope.GetScriptState()); |
| 92 | 92 |
| 93 // Receive first connection. | 93 // Receive first connection. |
| 94 receiver->OnReceiverConnectionAvailable( | 94 receiver->OnReceiverConnectionAvailable( |
| 95 WebPresentationInfo(KURL(NullURL(), "http://example.com"), "id")); | 95 WebPresentationInfo(KURL(NullURL(), "http://example.com"), "id")); |
| 96 | 96 |
| 97 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kResolved, | 97 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kResolved, |
| 98 receiver); | 98 receiver); |
| 99 VerifyConnectionListSize(1, receiver); | 99 VerifyConnectionListSize(1, receiver); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) { | 102 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) { |
| 103 V8TestingScope scope; | 103 V8TestingScope scope; |
| 104 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); | 104 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); |
| 105 | 105 |
| 106 StrictMock<MockEventListener>* event_handler = | 106 StrictMock<MockEventListener>* event_handler = |
| 107 new StrictMock<MockEventListener>(); | 107 new StrictMock<MockEventListener>(); |
| 108 AddConnectionavailableEventListener(event_handler, receiver); | 108 AddConnectionavailableEventListener(event_handler, receiver); |
| 109 EXPECT_CALL(*event_handler, handleEvent(testing::_, testing::_)).Times(1); | 109 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(1); |
| 110 | 110 |
| 111 receiver->connectionList(scope.GetScriptState()); | 111 receiver->connectionList(scope.GetScriptState()); |
| 112 | 112 |
| 113 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"), | 113 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"), |
| 114 "id"); | 114 "id"); |
| 115 // Receive first connection. | 115 // Receive first connection. |
| 116 receiver->OnReceiverConnectionAvailable(presentation_info); | 116 receiver->OnReceiverConnectionAvailable(presentation_info); |
| 117 // Receive second connection. | 117 // Receive second connection. |
| 118 receiver->OnReceiverConnectionAvailable(presentation_info); | 118 receiver->OnReceiverConnectionAvailable(presentation_info); |
| 119 | 119 |
| 120 VerifyConnectionListSize(2, receiver); | 120 VerifyConnectionListSize(2, receiver); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) { | 123 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) { |
| 124 V8TestingScope scope; | 124 V8TestingScope scope; |
| 125 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); | 125 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); |
| 126 | 126 |
| 127 StrictMock<MockEventListener>* event_handler = | 127 StrictMock<MockEventListener>* event_handler = |
| 128 new StrictMock<MockEventListener>(); | 128 new StrictMock<MockEventListener>(); |
| 129 AddConnectionavailableEventListener(event_handler, receiver); | 129 AddConnectionavailableEventListener(event_handler, receiver); |
| 130 EXPECT_CALL(*event_handler, handleEvent(testing::_, testing::_)).Times(0); | 130 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0); |
| 131 | 131 |
| 132 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"), | 132 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"), |
| 133 "id"); | 133 "id"); |
| 134 // Receive first connection. | 134 // Receive first connection. |
| 135 auto* connection1 = | 135 auto* connection1 = |
| 136 receiver->OnReceiverConnectionAvailable(presentation_info); | 136 receiver->OnReceiverConnectionAvailable(presentation_info); |
| 137 EXPECT_TRUE(connection1); | 137 EXPECT_TRUE(connection1); |
| 138 | 138 |
| 139 // Receive second connection. | 139 // Receive second connection. |
| 140 auto* connection2 = | 140 auto* connection2 = |
| 141 receiver->OnReceiverConnectionAvailable(presentation_info); | 141 receiver->OnReceiverConnectionAvailable(presentation_info); |
| 142 EXPECT_TRUE(connection2); | 142 EXPECT_TRUE(connection2); |
| 143 | 143 |
| 144 receiver->connectionList(scope.GetScriptState()); | 144 receiver->connectionList(scope.GetScriptState()); |
| 145 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kResolved, | 145 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kResolved, |
| 146 receiver); | 146 receiver); |
| 147 VerifyConnectionListSize(2, receiver); | 147 VerifyConnectionListSize(2, receiver); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(PresentationReceiverTest, CreateReceiver) { | 150 TEST_F(PresentationReceiverTest, CreateReceiver) { |
| 151 MockWebPresentationClient client; | 151 MockWebPresentationClient client; |
| 152 EXPECT_CALL(client, SetReceiver(testing::_)); | 152 EXPECT_CALL(client, SetReceiver(::testing::_)); |
| 153 | 153 |
| 154 V8TestingScope scope; | 154 V8TestingScope scope; |
| 155 new PresentationReceiver(&scope.GetFrame(), &client); | 155 new PresentationReceiver(&scope.GetFrame(), &client); |
| 156 } | 156 } |
| 157 | 157 |
| 158 TEST_F(PresentationReceiverTest, TestRemoveConnection) { | 158 TEST_F(PresentationReceiverTest, TestRemoveConnection) { |
| 159 V8TestingScope scope; | 159 V8TestingScope scope; |
| 160 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); | 160 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); |
| 161 | 161 |
| 162 // Receive first connection. | 162 // Receive first connection. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 EXPECT_TRUE(connection2); | 174 EXPECT_TRUE(connection2); |
| 175 | 175 |
| 176 receiver->connectionList(scope.GetScriptState()); | 176 receiver->connectionList(scope.GetScriptState()); |
| 177 VerifyConnectionListSize(2, receiver); | 177 VerifyConnectionListSize(2, receiver); |
| 178 | 178 |
| 179 receiver->RemoveConnection(connection1); | 179 receiver->RemoveConnection(connection1); |
| 180 VerifyConnectionListSize(1, receiver); | 180 VerifyConnectionListSize(1, receiver); |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |