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 "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
11 #include "modules/presentation/PresentationConnectionList.h" | 11 #include "modules/presentation/PresentationConnectionList.h" |
12 #include "public/platform/modules/presentation/WebPresentationClient.h" | |
12 #include "public/platform/modules/presentation/WebPresentationConnectionClient.h " | 13 #include "public/platform/modules/presentation/WebPresentationConnectionClient.h " |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include <v8.h> | 16 #include <v8.h> |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class MockEventListener : public EventListener { | 20 class MockEventListener : public EventListener { |
20 public: | 21 public: |
21 MockEventListener() | 22 MockEventListener() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 const PresentationReceiver* receiver) | 67 const PresentationReceiver* receiver) |
67 { | 68 { |
68 EXPECT_EQ(expectedSize, receiver->m_connectionList->m_connections.size()); | 69 EXPECT_EQ(expectedSize, receiver->m_connectionList->m_connections.size()); |
69 } | 70 } |
70 | 71 |
71 using ::testing::StrictMock; | 72 using ::testing::StrictMock; |
72 | 73 |
73 TEST_F(PresentationReceiverTest, NoConnectionUnresolvedConnectionList) | 74 TEST_F(PresentationReceiverTest, NoConnectionUnresolvedConnectionList) |
74 { | 75 { |
75 V8TestingScope scope; | 76 V8TestingScope scope; |
76 auto receiver = new PresentationReceiver(&scope.frame()); | 77 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); |
mark a. foltz
2016/09/15 16:53:18
Please add a test case with a mock WebPresentation
| |
77 | 78 |
78 auto eventHandler = new StrictMock<MockEventListener>(); | 79 auto eventHandler = new StrictMock<MockEventListener>(); |
79 addConnectionavailableEventListener(eventHandler, receiver); | 80 addConnectionavailableEventListener(eventHandler, receiver); |
80 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); | 81 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); |
81 | 82 |
82 receiver->connectionList(scope.getScriptState()); | 83 receiver->connectionList(scope.getScriptState()); |
83 | 84 |
84 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Pending, receiv er); | 85 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Pending, receiv er); |
85 verifyConnectionListSize(0, receiver); | 86 verifyConnectionListSize(0, receiver); |
86 } | 87 } |
87 | 88 |
88 TEST_F(PresentationReceiverTest, OneConnectionResolvedConnectionListNoEvent) | 89 TEST_F(PresentationReceiverTest, OneConnectionResolvedConnectionListNoEvent) |
89 { | 90 { |
90 V8TestingScope scope; | 91 V8TestingScope scope; |
91 auto receiver = new PresentationReceiver(&scope.frame()); | 92 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); |
92 | 93 |
93 auto eventHandler = new StrictMock<MockEventListener>(); | 94 auto eventHandler = new StrictMock<MockEventListener>(); |
94 addConnectionavailableEventListener(eventHandler, receiver); | 95 addConnectionavailableEventListener(eventHandler, receiver); |
95 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); | 96 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); |
96 | 97 |
97 receiver->connectionList(scope.getScriptState()); | 98 receiver->connectionList(scope.getScriptState()); |
98 | 99 |
99 // Receive first connection. | 100 // Receive first connection. |
100 auto connectionClient = new TestWebPresentationConnectionClient(); | 101 auto connectionClient = new TestWebPresentationConnectionClient(); |
101 receiver->onConnectionReceived(connectionClient); | 102 receiver->onReceiverConnectionAvailable(connectionClient); |
102 | 103 |
103 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved, recei ver); | 104 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved, recei ver); |
104 verifyConnectionListSize(1, receiver); | 105 verifyConnectionListSize(1, receiver); |
105 } | 106 } |
106 | 107 |
107 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) | 108 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) |
108 { | 109 { |
109 V8TestingScope scope; | 110 V8TestingScope scope; |
110 auto receiver = new PresentationReceiver(&scope.frame()); | 111 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); |
111 | 112 |
112 StrictMock<MockEventListener>* eventHandler = new StrictMock<MockEventListen er>(); | 113 StrictMock<MockEventListener>* eventHandler = new StrictMock<MockEventListen er>(); |
113 addConnectionavailableEventListener(eventHandler, receiver); | 114 addConnectionavailableEventListener(eventHandler, receiver); |
114 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(1); | 115 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(1); |
115 | 116 |
116 receiver->connectionList(scope.getScriptState()); | 117 receiver->connectionList(scope.getScriptState()); |
117 // Receive first connection. | 118 // Receive first connection. |
118 auto connectionClient1 = new TestWebPresentationConnectionClient(); | 119 auto connectionClient1 = new TestWebPresentationConnectionClient(); |
119 receiver->onConnectionReceived(connectionClient1); | 120 receiver->onReceiverConnectionAvailable(connectionClient1); |
120 | 121 |
121 // Receive second connection. | 122 // Receive second connection. |
122 auto connectionClient2 = new TestWebPresentationConnectionClient(); | 123 auto connectionClient2 = new TestWebPresentationConnectionClient(); |
123 receiver->onConnectionReceived(connectionClient2); | 124 receiver->onReceiverConnectionAvailable(connectionClient2); |
124 | 125 |
125 verifyConnectionListSize(2, receiver); | 126 verifyConnectionListSize(2, receiver); |
126 } | 127 } |
127 | 128 |
128 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) | 129 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) |
129 { | 130 { |
130 V8TestingScope scope; | 131 V8TestingScope scope; |
131 auto receiver = new PresentationReceiver(&scope.frame()); | 132 auto receiver = new PresentationReceiver(&scope.frame(), nullptr); |
132 | 133 |
133 StrictMock<MockEventListener>* eventHandler = new StrictMock<MockEventListen er>(); | 134 StrictMock<MockEventListener>* eventHandler = new StrictMock<MockEventListen er>(); |
134 addConnectionavailableEventListener(eventHandler, receiver); | 135 addConnectionavailableEventListener(eventHandler, receiver); |
135 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); | 136 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_)).Times(0); |
136 | 137 |
137 // Receive first connection. | 138 // Receive first connection. |
138 auto connectionClient1 = new TestWebPresentationConnectionClient(); | 139 auto connectionClient1 = new TestWebPresentationConnectionClient(); |
139 receiver->onConnectionReceived(connectionClient1); | 140 receiver->onReceiverConnectionAvailable(connectionClient1); |
140 | 141 |
141 // Receive second connection. | 142 // Receive second connection. |
142 auto connectionClient2 = new TestWebPresentationConnectionClient(); | 143 auto connectionClient2 = new TestWebPresentationConnectionClient(); |
143 receiver->onConnectionReceived(connectionClient2); | 144 receiver->onReceiverConnectionAvailable(connectionClient2); |
144 | 145 |
145 receiver->connectionList(scope.getScriptState()); | 146 receiver->connectionList(scope.getScriptState()); |
146 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved, recei ver); | 147 verifyConnectionListPropertyState(ScriptPromisePropertyBase::Resolved, recei ver); |
147 verifyConnectionListSize(2, receiver); | 148 verifyConnectionListSize(2, receiver); |
148 } | 149 } |
149 | 150 |
150 } // namespace blink | 151 } // namespace blink |
OLD | NEW |