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

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

Issue 2758233003: Fix the conditions when fullscreen detector listeners are registered (Closed)
Patch Set: addressed mlamouri's comments Created 3 years, 9 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/core/html/MediaCustomControlsFullscreenDetector.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 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/MediaCustomControlsFullscreenDetector.h" 5 #include "core/html/MediaCustomControlsFullscreenDetector.h"
6 6
7 #include "core/EventTypeNames.h" 7 #include "core/EventTypeNames.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
10 #include "platform/RuntimeEnabledFeatures.h" 10 #include "platform/RuntimeEnabledFeatures.h"
(...skipping 15 matching lines...) Expand all
26 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test { 26 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test {
27 protected: 27 protected:
28 void SetUp() override { 28 void SetUp() override {
29 m_originalVideoFullscreenDetectionEnabled = 29 m_originalVideoFullscreenDetectionEnabled =
30 RuntimeEnabledFeatures::videoFullscreenDetectionEnabled(); 30 RuntimeEnabledFeatures::videoFullscreenDetectionEnabled();
31 31
32 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(true); 32 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(true);
33 33
34 m_pageHolder = DummyPageHolder::create(); 34 m_pageHolder = DummyPageHolder::create();
35 m_newPageHolder = DummyPageHolder::create(); 35 m_newPageHolder = DummyPageHolder::create();
36
37 m_video = HTMLVideoElement::create(m_pageHolder->document());
38 document().body()->appendChild(&videoElement());
39 } 36 }
40 37
41 void TearDown() override { 38 void TearDown() override {
42 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled( 39 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(
43 m_originalVideoFullscreenDetectionEnabled); 40 m_originalVideoFullscreenDetectionEnabled);
44 } 41 }
45 42
46 HTMLVideoElement& videoElement() const { return *m_video; } 43 HTMLVideoElement* videoElement() const {
47 MediaCustomControlsFullscreenDetector& fullscreenDetector() const { 44 return toHTMLVideoElement(document().querySelector("video"));
48 return *videoElement().m_customControlsFullscreenDetector; 45 }
46
47 static MediaCustomControlsFullscreenDetector* fullscreenDetectorFor(
48 HTMLVideoElement* videoElement) {
49 return videoElement->m_customControlsFullscreenDetector;
50 }
51
52 MediaCustomControlsFullscreenDetector* fullscreenDetector() const {
53 return fullscreenDetectorFor(videoElement());
49 } 54 }
50 55
51 Document& document() const { return m_pageHolder->document(); } 56 Document& document() const { return m_pageHolder->document(); }
52 Document& newDocument() const { return m_newPageHolder->document(); } 57 Document& newDocument() const { return m_newPageHolder->document(); }
53 58
54 bool checkEventListenerRegistered(EventTarget& target, 59 bool checkEventListenerRegistered(EventTarget& target,
55 const AtomicString& eventType, 60 const AtomicString& eventType,
56 EventListener* listener) { 61 EventListener* listener) {
57 EventListenerVector* listeners = target.getEventListeners(eventType); 62 EventListenerVector* listeners = target.getEventListeners(eventType);
58 if (!listeners) 63 if (!listeners)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 107
103 for (const TestParam& testParam : testParams) { 108 for (const TestParam& testParam : testParams) {
104 const IntRect& targetRect = testParam.targetRect; 109 const IntRect& targetRect = testParam.targetRect;
105 IntRect intersectionRect = intersection(targetRect, rootRect); 110 IntRect intersectionRect = intersection(targetRect, rootRect);
106 EXPECT_EQ(testParam.expectedResult, 111 EXPECT_EQ(testParam.expectedResult,
107 computeIsDominantVideo(targetRect, rootRect, intersectionRect)) 112 computeIsDominantVideo(targetRect, rootRect, intersectionRect))
108 << testParam.description << " failed"; 113 << testParam.description << " failed";
109 } 114 }
110 } 115 }
111 116
112 TEST_F(MediaCustomControlsFullscreenDetectorTest, documentMove) { 117 TEST_F(MediaCustomControlsFullscreenDetectorTest,
118 hasNoListenersBeforeAddingToDocument) {
119 HTMLVideoElement* video =
120 toHTMLVideoElement(document().createElement("video"));
121
122 EXPECT_FALSE(checkEventListenerRegistered(document(),
123 EventTypeNames::fullscreenchange,
124 fullscreenDetectorFor(video)));
125 EXPECT_FALSE(checkEventListenerRegistered(
126 document(), EventTypeNames::webkitfullscreenchange,
127 fullscreenDetectorFor(video)));
128 EXPECT_FALSE(checkEventListenerRegistered(
129 *video, EventTypeNames::loadedmetadata, fullscreenDetectorFor(video)));
130 }
131
132 TEST_F(MediaCustomControlsFullscreenDetectorTest,
133 hasListenersAfterAddToDocumentByScript) {
134 HTMLVideoElement* video =
135 toHTMLVideoElement(document().createElement("video"));
136 document().body()->appendChild(video);
137
113 EXPECT_TRUE(checkEventListenerRegistered( 138 EXPECT_TRUE(checkEventListenerRegistered(
114 document(), EventTypeNames::fullscreenchange, &fullscreenDetector())); 139 document(), EventTypeNames::fullscreenchange, fullscreenDetector()));
115 EXPECT_TRUE(checkEventListenerRegistered( 140 EXPECT_TRUE(checkEventListenerRegistered(
116 document(), EventTypeNames::webkitfullscreenchange, 141 document(), EventTypeNames::webkitfullscreenchange,
117 &fullscreenDetector())); 142 fullscreenDetector()));
118 EXPECT_FALSE(checkEventListenerRegistered( 143 EXPECT_TRUE(checkEventListenerRegistered(
119 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); 144 *videoElement(), EventTypeNames::loadedmetadata, fullscreenDetector()));
120 EXPECT_FALSE(checkEventListenerRegistered( 145 }
121 newDocument(), EventTypeNames::webkitfullscreenchange,
122 &fullscreenDetector()));
123 146
124 newDocument().body()->appendChild(&videoElement()); 147 TEST_F(MediaCustomControlsFullscreenDetectorTest,
148 hasListenersAfterAddToDocumentByParser) {
149 document().body()->setInnerHTML("<body><video></video></body>");
125 150
126 EXPECT_FALSE(checkEventListenerRegistered( 151 EXPECT_TRUE(checkEventListenerRegistered(
127 document(), EventTypeNames::fullscreenchange, &fullscreenDetector())); 152 document(), EventTypeNames::fullscreenchange, fullscreenDetector()));
153 EXPECT_TRUE(checkEventListenerRegistered(
154 document(), EventTypeNames::webkitfullscreenchange,
155 fullscreenDetector()));
156 EXPECT_TRUE(checkEventListenerRegistered(
157 *videoElement(), EventTypeNames::loadedmetadata, fullscreenDetector()));
158 }
159
160 TEST_F(MediaCustomControlsFullscreenDetectorTest,
161 hasListenersAfterDocumentMove) {
162 HTMLVideoElement* video =
163 toHTMLVideoElement(document().createElement("video"));
164 document().body()->appendChild(video);
165
166 newDocument().body()->appendChild(videoElement());
167
168 EXPECT_FALSE(checkEventListenerRegistered(document(),
169 EventTypeNames::fullscreenchange,
170 fullscreenDetectorFor(video)));
128 EXPECT_FALSE(checkEventListenerRegistered( 171 EXPECT_FALSE(checkEventListenerRegistered(
129 document(), EventTypeNames::webkitfullscreenchange, 172 document(), EventTypeNames::webkitfullscreenchange,
130 &fullscreenDetector())); 173 fullscreenDetectorFor(video)));
131 EXPECT_TRUE(checkEventListenerRegistered( 174
132 newDocument(), EventTypeNames::fullscreenchange, &fullscreenDetector())); 175 EXPECT_TRUE(checkEventListenerRegistered(newDocument(),
176 EventTypeNames::fullscreenchange,
177 fullscreenDetectorFor(video)));
133 EXPECT_TRUE(checkEventListenerRegistered( 178 EXPECT_TRUE(checkEventListenerRegistered(
134 newDocument(), EventTypeNames::webkitfullscreenchange, 179 newDocument(), EventTypeNames::webkitfullscreenchange,
135 &fullscreenDetector())); 180 fullscreenDetectorFor(video)));
181
182 EXPECT_TRUE(checkEventListenerRegistered(
183 *video, EventTypeNames::loadedmetadata, fullscreenDetectorFor(video)));
136 } 184 }
137 185
138 } // namespace blink 186 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/MediaCustomControlsFullscreenDetector.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698