Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp

Issue 2484973005: [Blink, RemotePlaybackAPI] Create WebRemotePlaybackClient in HTMLMediaElement ctor to avoid lazy in… (Closed)
Patch Set: Removed <v8.h> from HTMLMediaElement.cpp Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/remoteplayback/RemotePlayback.h" 5 #include "modules/remoteplayback/RemotePlayback.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "bindings/core/v8/V8BindingForTesting.h" 8 #include "bindings/core/v8/V8BindingForTesting.h"
9 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" 9 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h"
10 #include "core/dom/DocumentUserGestureToken.h" 10 #include "core/dom/DocumentUserGestureToken.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 }; 62 };
63 63
64 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) { 64 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
65 V8TestingScope scope; 65 V8TestingScope scope;
66 66
67 auto pageHolder = DummyPageHolder::create(); 67 auto pageHolder = DummyPageHolder::create();
68 68
69 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 69 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
70 RemotePlayback* remotePlayback = 70 RemotePlayback* remotePlayback =
71 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 71 HTMLMediaElementRemotePlayback::remote(*element);
72 72
73 auto resolve = MockFunction::create(scope.getScriptState()); 73 auto resolve = MockFunction::create(scope.getScriptState());
74 auto reject = MockFunction::create(scope.getScriptState()); 74 auto reject = MockFunction::create(scope.getScriptState());
75 75
76 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 76 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
77 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 77 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
78 78
79 UserGestureIndicator indicator(DocumentUserGestureToken::create( 79 UserGestureIndicator indicator(DocumentUserGestureToken::create(
80 &pageHolder->document(), UserGestureToken::NewGesture)); 80 &pageHolder->document(), UserGestureToken::NewGesture));
81 remotePlayback->prompt().then(resolve->bind(), reject->bind()); 81 remotePlayback->prompt(scope.getScriptState())
82 .then(resolve->bind(), reject->bind());
82 cancelPrompt(remotePlayback); 83 cancelPrompt(remotePlayback);
83 84
84 // Runs pending promises. 85 // Runs pending promises.
85 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 86 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
86 87
87 // Verify mock expectations explicitly as the mock objects are garbage 88 // Verify mock expectations explicitly as the mock objects are garbage
88 // collected. 89 // collected.
89 ::testing::Mock::VerifyAndClear(resolve); 90 ::testing::Mock::VerifyAndClear(resolve);
90 ::testing::Mock::VerifyAndClear(reject); 91 ::testing::Mock::VerifyAndClear(reject);
91 } 92 }
92 93
93 TEST_F(RemotePlaybackTest, PromptConnectedRejectsWhenCancelled) { 94 TEST_F(RemotePlaybackTest, PromptConnectedRejectsWhenCancelled) {
94 V8TestingScope scope; 95 V8TestingScope scope;
95 96
96 auto pageHolder = DummyPageHolder::create(); 97 auto pageHolder = DummyPageHolder::create();
97 98
98 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 99 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
99 RemotePlayback* remotePlayback = 100 RemotePlayback* remotePlayback =
100 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 101 HTMLMediaElementRemotePlayback::remote(*element);
101 102
102 auto resolve = MockFunction::create(scope.getScriptState()); 103 auto resolve = MockFunction::create(scope.getScriptState());
103 auto reject = MockFunction::create(scope.getScriptState()); 104 auto reject = MockFunction::create(scope.getScriptState());
104 105
105 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 106 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
106 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 107 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
107 108
108 setState(remotePlayback, WebRemotePlaybackState::Connected); 109 setState(remotePlayback, WebRemotePlaybackState::Connected);
109 110
110 UserGestureIndicator indicator(DocumentUserGestureToken::create( 111 UserGestureIndicator indicator(DocumentUserGestureToken::create(
111 &pageHolder->document(), UserGestureToken::NewGesture)); 112 &pageHolder->document(), UserGestureToken::NewGesture));
112 remotePlayback->prompt().then(resolve->bind(), reject->bind()); 113 remotePlayback->prompt(scope.getScriptState())
114 .then(resolve->bind(), reject->bind());
113 cancelPrompt(remotePlayback); 115 cancelPrompt(remotePlayback);
114 116
115 // Runs pending promises. 117 // Runs pending promises.
116 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 118 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
117 119
118 // Verify mock expectations explicitly as the mock objects are garbage 120 // Verify mock expectations explicitly as the mock objects are garbage
119 // collected. 121 // collected.
120 ::testing::Mock::VerifyAndClear(resolve); 122 ::testing::Mock::VerifyAndClear(resolve);
121 ::testing::Mock::VerifyAndClear(reject); 123 ::testing::Mock::VerifyAndClear(reject);
122 } 124 }
123 125
124 TEST_F(RemotePlaybackTest, PromptConnectedResolvesWhenDisconnected) { 126 TEST_F(RemotePlaybackTest, PromptConnectedResolvesWhenDisconnected) {
125 V8TestingScope scope; 127 V8TestingScope scope;
126 128
127 auto pageHolder = DummyPageHolder::create(); 129 auto pageHolder = DummyPageHolder::create();
128 130
129 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 131 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
130 RemotePlayback* remotePlayback = 132 RemotePlayback* remotePlayback =
131 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 133 HTMLMediaElementRemotePlayback::remote(*element);
132 134
133 auto resolve = MockFunction::create(scope.getScriptState()); 135 auto resolve = MockFunction::create(scope.getScriptState());
134 auto reject = MockFunction::create(scope.getScriptState()); 136 auto reject = MockFunction::create(scope.getScriptState());
135 137
136 EXPECT_CALL(*resolve, call(::testing::_)).Times(1); 138 EXPECT_CALL(*resolve, call(::testing::_)).Times(1);
137 EXPECT_CALL(*reject, call(::testing::_)).Times(0); 139 EXPECT_CALL(*reject, call(::testing::_)).Times(0);
138 140
139 setState(remotePlayback, WebRemotePlaybackState::Connected); 141 setState(remotePlayback, WebRemotePlaybackState::Connected);
140 142
141 UserGestureIndicator indicator(DocumentUserGestureToken::create( 143 UserGestureIndicator indicator(DocumentUserGestureToken::create(
142 &pageHolder->document(), UserGestureToken::NewGesture)); 144 &pageHolder->document(), UserGestureToken::NewGesture));
143 remotePlayback->prompt().then(resolve->bind(), reject->bind()); 145 remotePlayback->prompt(scope.getScriptState())
146 .then(resolve->bind(), reject->bind());
144 147
145 setState(remotePlayback, WebRemotePlaybackState::Disconnected); 148 setState(remotePlayback, WebRemotePlaybackState::Disconnected);
146 149
147 // Runs pending promises. 150 // Runs pending promises.
148 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 151 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
149 152
150 // Verify mock expectations explicitly as the mock objects are garbage 153 // Verify mock expectations explicitly as the mock objects are garbage
151 // collected. 154 // collected.
152 ::testing::Mock::VerifyAndClear(resolve); 155 ::testing::Mock::VerifyAndClear(resolve);
153 ::testing::Mock::VerifyAndClear(reject); 156 ::testing::Mock::VerifyAndClear(reject);
154 } 157 }
155 158
156 TEST_F(RemotePlaybackTest, StateChangeEvents) { 159 TEST_F(RemotePlaybackTest, StateChangeEvents) {
157 V8TestingScope scope; 160 V8TestingScope scope;
158 161
159 auto pageHolder = DummyPageHolder::create(); 162 auto pageHolder = DummyPageHolder::create();
160 163
161 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 164 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
162 RemotePlayback* remotePlayback = 165 RemotePlayback* remotePlayback =
163 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 166 HTMLMediaElementRemotePlayback::remote(*element);
164 167
165 auto connectingHandler = new ::testing::StrictMock<MockEventListener>(); 168 auto connectingHandler = new ::testing::StrictMock<MockEventListener>();
166 auto connectHandler = new ::testing::StrictMock<MockEventListener>(); 169 auto connectHandler = new ::testing::StrictMock<MockEventListener>();
167 auto disconnectHandler = new ::testing::StrictMock<MockEventListener>(); 170 auto disconnectHandler = new ::testing::StrictMock<MockEventListener>();
168 171
169 remotePlayback->addEventListener(EventTypeNames::connecting, 172 remotePlayback->addEventListener(EventTypeNames::connecting,
170 connectingHandler); 173 connectingHandler);
171 remotePlayback->addEventListener(EventTypeNames::connect, connectHandler); 174 remotePlayback->addEventListener(EventTypeNames::connect, connectHandler);
172 remotePlayback->addEventListener(EventTypeNames::disconnect, 175 remotePlayback->addEventListener(EventTypeNames::disconnect,
173 disconnectHandler); 176 disconnectHandler);
(...skipping 20 matching lines...) Expand all
194 } 197 }
195 198
196 TEST_F(RemotePlaybackTest, 199 TEST_F(RemotePlaybackTest,
197 DisableRemotePlaybackRejectsPromptWithInvalidStateError) { 200 DisableRemotePlaybackRejectsPromptWithInvalidStateError) {
198 V8TestingScope scope; 201 V8TestingScope scope;
199 202
200 auto pageHolder = DummyPageHolder::create(); 203 auto pageHolder = DummyPageHolder::create();
201 204
202 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 205 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
203 RemotePlayback* remotePlayback = 206 RemotePlayback* remotePlayback =
204 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 207 HTMLMediaElementRemotePlayback::remote(*element);
205 208
206 MockFunction* resolve = MockFunction::create(scope.getScriptState()); 209 MockFunction* resolve = MockFunction::create(scope.getScriptState());
207 MockFunction* reject = MockFunction::create(scope.getScriptState()); 210 MockFunction* reject = MockFunction::create(scope.getScriptState());
208 211
209 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 212 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
210 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 213 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
211 214
212 UserGestureIndicator indicator(DocumentUserGestureToken::create( 215 UserGestureIndicator indicator(DocumentUserGestureToken::create(
213 &pageHolder->document(), UserGestureToken::NewGesture)); 216 &pageHolder->document(), UserGestureToken::NewGesture));
214 remotePlayback->prompt().then(resolve->bind(), reject->bind()); 217 remotePlayback->prompt(scope.getScriptState())
218 .then(resolve->bind(), reject->bind());
215 HTMLMediaElementRemotePlayback::setBooleanAttribute( 219 HTMLMediaElementRemotePlayback::setBooleanAttribute(
216 HTMLNames::disableremoteplaybackAttr, *element, true); 220 HTMLNames::disableremoteplaybackAttr, *element, true);
217 221
218 // Runs pending promises. 222 // Runs pending promises.
219 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 223 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
220 224
221 // Verify mock expectations explicitly as the mock objects are garbage 225 // Verify mock expectations explicitly as the mock objects are garbage
222 // collected. 226 // collected.
223 ::testing::Mock::VerifyAndClear(resolve); 227 ::testing::Mock::VerifyAndClear(resolve);
224 ::testing::Mock::VerifyAndClear(reject); 228 ::testing::Mock::VerifyAndClear(reject);
225 } 229 }
226 230
227 TEST_F(RemotePlaybackTest, DisableRemotePlaybackCancelsAvailabilityCallbacks) { 231 TEST_F(RemotePlaybackTest, DisableRemotePlaybackCancelsAvailabilityCallbacks) {
228 V8TestingScope scope; 232 V8TestingScope scope;
229 233
230 auto pageHolder = DummyPageHolder::create(); 234 auto pageHolder = DummyPageHolder::create();
231 235
232 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 236 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
233 RemotePlayback* remotePlayback = 237 RemotePlayback* remotePlayback =
234 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 238 HTMLMediaElementRemotePlayback::remote(*element);
235 239
236 MockFunction* callbackFunction = MockFunction::create(scope.getScriptState()); 240 MockFunction* callbackFunction = MockFunction::create(scope.getScriptState());
237 RemotePlaybackAvailabilityCallback* availabilityCallback = 241 RemotePlaybackAvailabilityCallback* availabilityCallback =
238 RemotePlaybackAvailabilityCallback::create(scope.getScriptState(), 242 RemotePlaybackAvailabilityCallback::create(scope.getScriptState(),
239 callbackFunction->bind()); 243 callbackFunction->bind());
240 244
241 // The initial call upon registering will not happen as it's posted on the 245 // The initial call upon registering will not happen as it's posted on the
242 // message loop. 246 // message loop.
243 EXPECT_CALL(*callbackFunction, call(::testing::_)).Times(0); 247 EXPECT_CALL(*callbackFunction, call(::testing::_)).Times(0);
244 248
245 MockFunction* resolve = MockFunction::create(scope.getScriptState()); 249 MockFunction* resolve = MockFunction::create(scope.getScriptState());
246 MockFunction* reject = MockFunction::create(scope.getScriptState()); 250 MockFunction* reject = MockFunction::create(scope.getScriptState());
247 251
248 EXPECT_CALL(*resolve, call(::testing::_)).Times(1); 252 EXPECT_CALL(*resolve, call(::testing::_)).Times(1);
249 EXPECT_CALL(*reject, call(::testing::_)).Times(0); 253 EXPECT_CALL(*reject, call(::testing::_)).Times(0);
250 254
251 remotePlayback->watchAvailability(availabilityCallback) 255 remotePlayback
256 ->watchAvailability(scope.getScriptState(), availabilityCallback)
252 .then(resolve->bind(), reject->bind()); 257 .then(resolve->bind(), reject->bind());
253 258
254 HTMLMediaElementRemotePlayback::setBooleanAttribute( 259 HTMLMediaElementRemotePlayback::setBooleanAttribute(
255 HTMLNames::disableremoteplaybackAttr, *element, true); 260 HTMLNames::disableremoteplaybackAttr, *element, true);
256 setAvailability(remotePlayback, true); 261 setAvailability(remotePlayback, true);
257 262
258 // Runs pending promises. 263 // Runs pending promises.
259 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 264 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
260 265
261 // Verify mock expectations explicitly as the mock objects are garbage 266 // Verify mock expectations explicitly as the mock objects are garbage
262 // collected. 267 // collected.
263 ::testing::Mock::VerifyAndClear(resolve); 268 ::testing::Mock::VerifyAndClear(resolve);
264 ::testing::Mock::VerifyAndClear(reject); 269 ::testing::Mock::VerifyAndClear(reject);
265 ::testing::Mock::VerifyAndClear(callbackFunction); 270 ::testing::Mock::VerifyAndClear(callbackFunction);
266 } 271 }
267 272
268 } // namespace blink 273 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698