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

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

Issue 2782373002: Remove MediaControls methods needed for the Cast button (Closed)
Patch Set: Removed unused from the header Created 3 years, 7 months 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
« no previous file with comments | « third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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) {
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 ThreadState::Current()->CollectAllGarbage();
308
309 // It has been GC'd.
310 EXPECT_EQ(nullptr, weak_persistent_video);
whywhat 2017/04/24 23:59:29 Kentaro, this fails (and a similar test in existin
311 }
312
313 TEST_F(RemotePlaybackTest, ReInsertingInDocumentRestoresListenersAndCallbacks) {
314 V8TestingScope scope;
315
316 auto page_holder = DummyPageHolder::Create();
317
318 HTMLMediaElement* element =
319 HTMLVideoElement::Create(page_holder->GetDocument());
320 element->SetBooleanAttribute(HTMLNames::controlsAttr, true);
321 page_holder->GetDocument().body()->AppendChild(element);
322
323 RemotePlayback* remote_playback =
324 HTMLMediaElementRemotePlayback::remote(*element);
325
326 // This should be a no-op. We keep a reference on the media element to avoid
327 // an unexpected GC.
328 {
329 Persistent<HTMLMediaElement> video_holder = element;
330 page_holder->GetDocument().body()->RemoveChild(element);
331 page_holder->GetDocument().body()->AppendChild(video_holder.Get());
332 EXPECT_TRUE(remote_playback->HasEventListeners());
333 EXPECT_TRUE(HasAvailabilityCallbacks(remote_playback));
334 }
335 }
336
276 } // namespace blink 337 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698