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/remoteplayback/RemotePlayback.h" | 5 #include "modules/remoteplayback/RemotePlayback.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 49 |
50 class RemotePlaybackTest : public ::testing::Test { | 50 class RemotePlaybackTest : public ::testing::Test { |
51 protected: | 51 protected: |
52 void CancelPrompt(RemotePlayback* remote_playback) { | 52 void CancelPrompt(RemotePlayback* remote_playback) { |
53 remote_playback->PromptCancelled(); | 53 remote_playback->PromptCancelled(); |
54 } | 54 } |
55 | 55 |
56 void SetState(RemotePlayback* remote_playback, WebRemotePlaybackState state) { | 56 void SetState(RemotePlayback* remote_playback, WebRemotePlaybackState state) { |
57 remote_playback->StateChanged(state); | 57 remote_playback->StateChanged(state); |
58 } | 58 } |
59 | |
60 bool HasAvailabilityCallbacks(RemotePlayback* remote_playback) { | |
61 return !remote_playback->availability_callbacks_.IsEmpty(); | |
62 } | |
59 }; | 63 }; |
60 | 64 |
61 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) { | 65 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) { |
62 V8TestingScope scope; | 66 V8TestingScope scope; |
63 | 67 |
64 auto page_holder = DummyPageHolder::Create(); | 68 auto page_holder = DummyPageHolder::Create(); |
65 | 69 |
66 HTMLMediaElement* element = | 70 HTMLMediaElement* element = |
67 HTMLVideoElement::Create(page_holder->GetDocument()); | 71 HTMLVideoElement::Create(page_holder->GetDocument()); |
68 RemotePlayback* remote_playback = | 72 RemotePlayback* remote_playback = |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 // Runs pending promises. | 270 // Runs pending promises. |
267 v8::MicrotasksScope::PerformCheckpoint(scope.GetIsolate()); | 271 v8::MicrotasksScope::PerformCheckpoint(scope.GetIsolate()); |
268 | 272 |
269 // Verify mock expectations explicitly as the mock objects are garbage | 273 // Verify mock expectations explicitly as the mock objects are garbage |
270 // collected. | 274 // collected. |
271 ::testing::Mock::VerifyAndClear(resolve); | 275 ::testing::Mock::VerifyAndClear(resolve); |
272 ::testing::Mock::VerifyAndClear(reject); | 276 ::testing::Mock::VerifyAndClear(reject); |
273 ::testing::Mock::VerifyAndClear(callback_function); | 277 ::testing::Mock::VerifyAndClear(callback_function); |
274 } | 278 } |
275 | 279 |
280 TEST_F(RemotePlaybackTest, RemovingFromDocumentRemovesListenersAndCallbacks) { | |
mlamouri (slow - plz ping)
2017/04/25 12:19:21
This should be a media_controls/ test, shouldn't i
whywhat
2017/04/25 15:45:37
I guess so :)
| |
281 V8TestingScope scope; | |
282 | |
283 auto page_holder = DummyPageHolder::Create(); | |
284 | |
285 HTMLMediaElement* element = | |
286 HTMLVideoElement::Create(page_holder->GetDocument()); | |
287 element->SetBooleanAttribute(HTMLNames::controlsAttr, true); | |
288 page_holder->GetDocument().body()->AppendChild(element); | |
289 | |
290 RemotePlayback* remote_playback = | |
291 HTMLMediaElementRemotePlayback::remote(*element); | |
292 | |
293 EXPECT_TRUE(remote_playback->HasEventListeners()); | |
294 EXPECT_TRUE(HasAvailabilityCallbacks(remote_playback)); | |
295 | |
296 WeakPersistent<HTMLMediaElement> weak_persistent_video = element; | |
297 { | |
298 Persistent<HTMLMediaElement> persistent_video = element; | |
299 page_holder->GetDocument().body()->setInnerHTML(""); | |
300 | |
301 // When removed from the document, the event listeners should have been | |
302 // dropped. | |
303 EXPECT_FALSE(remote_playback->HasEventListeners()); | |
304 EXPECT_FALSE(HasAvailabilityCallbacks(remote_playback)); | |
305 } | |
306 | |
307 testing::RunPendingTasks(); | |
308 | |
309 ThreadState::Current()->CollectAllGarbage(); | |
310 | |
311 // It has been GC'd. | |
312 EXPECT_EQ(nullptr, weak_persistent_video); | |
313 } | |
314 | |
315 TEST_F(RemotePlaybackTest, ReInsertingInDocumentRestoresListenersAndCallbacks) { | |
mlamouri (slow - plz ping)
2017/04/25 12:19:21
ditto
| |
316 V8TestingScope scope; | |
317 | |
318 auto page_holder = DummyPageHolder::Create(); | |
319 | |
320 HTMLMediaElement* element = | |
321 HTMLVideoElement::Create(page_holder->GetDocument()); | |
322 element->SetBooleanAttribute(HTMLNames::controlsAttr, true); | |
323 page_holder->GetDocument().body()->AppendChild(element); | |
324 | |
325 RemotePlayback* remote_playback = | |
326 HTMLMediaElementRemotePlayback::remote(*element); | |
327 | |
328 // This should be a no-op. We keep a reference on the media element to avoid | |
329 // an unexpected GC. | |
330 { | |
331 Persistent<HTMLMediaElement> video_holder = element; | |
332 page_holder->GetDocument().body()->RemoveChild(element); | |
333 page_holder->GetDocument().body()->AppendChild(video_holder.Get()); | |
334 EXPECT_TRUE(remote_playback->HasEventListeners()); | |
335 EXPECT_TRUE(HasAvailabilityCallbacks(remote_playback)); | |
336 } | |
337 } | |
338 | |
276 } // namespace blink | 339 } // namespace blink |
OLD | NEW |