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

Unified Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp

Issue 2782373002: Remove MediaControls methods needed for the Cast button (Closed)
Patch Set: Fixed more tests Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
diff --git a/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp b/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
index b84147a705aec06215a8f1df4078be6f81ae4873..656cd905b62412853259b19019411a28ddd08448 100644
--- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
+++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
@@ -56,6 +56,10 @@ class RemotePlaybackTest : public ::testing::Test {
void SetState(RemotePlayback* remote_playback, WebRemotePlaybackState state) {
remote_playback->StateChanged(state);
}
+
+ bool HasAvailabilityCallbacks(RemotePlayback* remote_playback) {
+ return !remote_playback->availability_callbacks_.IsEmpty();
+ }
};
TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
@@ -273,4 +277,63 @@ TEST_F(RemotePlaybackTest, DisableRemotePlaybackCancelsAvailabilityCallbacks) {
::testing::Mock::VerifyAndClear(callback_function);
}
+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 :)
+ V8TestingScope scope;
+
+ auto page_holder = DummyPageHolder::Create();
+
+ HTMLMediaElement* element =
+ HTMLVideoElement::Create(page_holder->GetDocument());
+ element->SetBooleanAttribute(HTMLNames::controlsAttr, true);
+ page_holder->GetDocument().body()->AppendChild(element);
+
+ RemotePlayback* remote_playback =
+ HTMLMediaElementRemotePlayback::remote(*element);
+
+ EXPECT_TRUE(remote_playback->HasEventListeners());
+ EXPECT_TRUE(HasAvailabilityCallbacks(remote_playback));
+
+ WeakPersistent<HTMLMediaElement> weak_persistent_video = element;
+ {
+ Persistent<HTMLMediaElement> persistent_video = element;
+ page_holder->GetDocument().body()->setInnerHTML("");
+
+ // When removed from the document, the event listeners should have been
+ // dropped.
+ EXPECT_FALSE(remote_playback->HasEventListeners());
+ EXPECT_FALSE(HasAvailabilityCallbacks(remote_playback));
+ }
+
+ testing::RunPendingTasks();
+
+ ThreadState::Current()->CollectAllGarbage();
+
+ // It has been GC'd.
+ EXPECT_EQ(nullptr, weak_persistent_video);
+}
+
+TEST_F(RemotePlaybackTest, ReInsertingInDocumentRestoresListenersAndCallbacks) {
mlamouri (slow - plz ping) 2017/04/25 12:19:21 ditto
+ V8TestingScope scope;
+
+ auto page_holder = DummyPageHolder::Create();
+
+ HTMLMediaElement* element =
+ HTMLVideoElement::Create(page_holder->GetDocument());
+ element->SetBooleanAttribute(HTMLNames::controlsAttr, true);
+ page_holder->GetDocument().body()->AppendChild(element);
+
+ RemotePlayback* remote_playback =
+ HTMLMediaElementRemotePlayback::remote(*element);
+
+ // This should be a no-op. We keep a reference on the media element to avoid
+ // an unexpected GC.
+ {
+ Persistent<HTMLMediaElement> video_holder = element;
+ page_holder->GetDocument().body()->RemoveChild(element);
+ page_holder->GetDocument().body()->AppendChild(video_holder.Get());
+ EXPECT_TRUE(remote_playback->HasEventListeners());
+ EXPECT_TRUE(HasAvailabilityCallbacks(remote_playback));
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698