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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElementEventListenersTest.cpp

Issue 2793273002: Use internal hooks for notifying fullscreen changes to media controls (Closed)
Patch Set: update 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "core/html/HTMLMediaElement.h" 5 #include "core/html/HTMLMediaElement.h"
6 6
7 #include "core/dom/DocumentUserGestureToken.h" 7 #include "core/dom/DocumentUserGestureToken.h"
8 #include "core/dom/Fullscreen.h" 8 #include "core/dom/Fullscreen.h"
9 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/html/MediaCustomControlsFullscreenDetector.h" 10 #include "core/html/MediaCustomControlsFullscreenDetector.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 private: 74 private:
75 std::unique_ptr<DummyPageHolder> m_pageHolder; 75 std::unique_ptr<DummyPageHolder> m_pageHolder;
76 }; 76 };
77 77
78 TEST_F(HTMLMediaElementEventListenersTest, RemovingFromDocumentCollectsAll) { 78 TEST_F(HTMLMediaElementEventListenersTest, RemovingFromDocumentCollectsAll) {
79 EXPECT_EQ(video(), nullptr); 79 EXPECT_EQ(video(), nullptr);
80 document().body()->setInnerHTML("<body><video controls></video></body>"); 80 document().body()->setInnerHTML("<body><video controls></video></body>");
81 EXPECT_NE(video(), nullptr); 81 EXPECT_NE(video(), nullptr);
82 EXPECT_TRUE(video()->hasEventListeners()); 82 EXPECT_TRUE(video()->hasEventListeners());
83 EXPECT_NE(controls(), nullptr); 83 EXPECT_NE(controls(), nullptr);
84 EXPECT_TRUE(document().hasEventListeners());
85 84
86 WeakPersistent<HTMLVideoElement> weakPersistentVideo = video(); 85 WeakPersistent<HTMLVideoElement> weakPersistentVideo = video();
87 WeakPersistent<MediaControls> weakPersistentControls = controls(); 86 WeakPersistent<MediaControls> weakPersistentControls = controls();
88 { 87 {
89 Persistent<HTMLVideoElement> persistentVideo = video(); 88 Persistent<HTMLVideoElement> persistentVideo = video();
90 document().body()->setInnerHTML(""); 89 document().body()->setInnerHTML("");
91 90
92 // When removed from the document, the event listeners should have been
93 // dropped.
94 EXPECT_FALSE(document().hasEventListeners());
95 // The video element should still have some event listeners. 91 // The video element should still have some event listeners.
96 EXPECT_TRUE(persistentVideo->hasEventListeners()); 92 EXPECT_TRUE(persistentVideo->hasEventListeners());
97 } 93 }
98 94
99 ThreadState::current()->collectAllGarbage(); 95 ThreadState::current()->collectAllGarbage();
100 96
101 // They have been GC'd. 97 // They have been GC'd.
102 EXPECT_EQ(weakPersistentVideo, nullptr); 98 EXPECT_EQ(weakPersistentVideo, nullptr);
103 EXPECT_EQ(weakPersistentControls, nullptr); 99 EXPECT_EQ(weakPersistentControls, nullptr);
104 } 100 }
105 101
106 TEST_F(HTMLMediaElementEventListenersTest, 102 TEST_F(HTMLMediaElementEventListenersTest,
107 ReInsertingInDocumentCollectsControls) { 103 ReInsertingInDocumentCollectsControls) {
108 EXPECT_EQ(video(), nullptr); 104 EXPECT_EQ(video(), nullptr);
109 document().body()->setInnerHTML("<body><video controls></video></body>"); 105 document().body()->setInnerHTML("<body><video controls></video></body>");
110 EXPECT_NE(video(), nullptr); 106 EXPECT_NE(video(), nullptr);
111 EXPECT_TRUE(video()->hasEventListeners()); 107 EXPECT_TRUE(video()->hasEventListeners());
112 EXPECT_NE(controls(), nullptr); 108 EXPECT_NE(controls(), nullptr);
113 EXPECT_TRUE(document().hasEventListeners());
114 109
115 // This should be a no-op. We keep a reference on the VideoElement to avoid an 110 // This should be a no-op. We keep a reference on the VideoElement to avoid an
116 // unexpected GC. 111 // unexpected GC.
117 { 112 {
118 Persistent<HTMLVideoElement> videoHolder = video(); 113 Persistent<HTMLVideoElement> videoHolder = video();
119 document().body()->removeChild(video()); 114 document().body()->removeChild(video());
120 document().body()->appendChild(videoHolder.get()); 115 document().body()->appendChild(videoHolder.get());
121 } 116 }
122 117
123 EXPECT_TRUE(document().hasEventListeners());
124 EXPECT_TRUE(video()->hasEventListeners()); 118 EXPECT_TRUE(video()->hasEventListeners());
125 119
126 ThreadState::current()->collectAllGarbage(); 120 ThreadState::current()->collectAllGarbage();
127 121
128 EXPECT_NE(video(), nullptr); 122 EXPECT_NE(video(), nullptr);
129 EXPECT_NE(controls(), nullptr); 123 EXPECT_NE(controls(), nullptr);
130 EXPECT_EQ(controls(), video()->mediaControls()); 124 EXPECT_EQ(controls(), video()->mediaControls());
131 } 125 }
132 126
133 TEST_F(HTMLMediaElementEventListenersTest, 127 TEST_F(HTMLMediaElementEventListenersTest,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 EXPECT_FALSE(isCheckViewportIntersectionTimerActive(detector)); 169 EXPECT_FALSE(isCheckViewportIntersectionTimerActive(detector));
176 // Should only notify the false value when ExecutionContext is destroyed. 170 // Should only notify the false value when ExecutionContext is destroyed.
177 EXPECT_EQ(1u, observedResults.size()); 171 EXPECT_EQ(1u, observedResults.size());
178 EXPECT_FALSE(observedResults[0]); 172 EXPECT_FALSE(observedResults[0]);
179 173
180 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled( 174 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(
181 originalVideoFullscreenDetectionEnabled); 175 originalVideoFullscreenDetectionEnabled);
182 } 176 }
183 177
184 } // namespace blink 178 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698