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

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

Issue 2780403004: Create core/html/media/ and move auxiliary media files in it. (Closed)
Patch Set: actually add autoplay files 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/html/MediaCustomControlsFullscreenDetector.h"
6
7 #include "core/EventTypeNames.h"
8 #include "core/html/HTMLVideoElement.h"
9 #include "core/testing/DummyPageHolder.h"
10 #include "platform/RuntimeEnabledFeatures.h"
11 #include "platform/geometry/IntRect.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace blink {
15
16 namespace {
17
18 struct TestParam {
19 String description;
20 IntRect targetRect;
21 bool expectedResult;
22 };
23
24 } // anonymous namespace
25
26 class MediaCustomControlsFullscreenDetectorTest : public ::testing::Test {
27 protected:
28 void SetUp() override {
29 m_originalVideoFullscreenDetectionEnabled =
30 RuntimeEnabledFeatures::videoFullscreenDetectionEnabled();
31
32 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(true);
33
34 m_pageHolder = DummyPageHolder::create();
35 m_newPageHolder = DummyPageHolder::create();
36 }
37
38 void TearDown() override {
39 RuntimeEnabledFeatures::setVideoFullscreenDetectionEnabled(
40 m_originalVideoFullscreenDetectionEnabled);
41 }
42
43 HTMLVideoElement* videoElement() const {
44 return toHTMLVideoElement(document().querySelector("video"));
45 }
46
47 static MediaCustomControlsFullscreenDetector* fullscreenDetectorFor(
48 HTMLVideoElement* videoElement) {
49 return videoElement->m_customControlsFullscreenDetector;
50 }
51
52 MediaCustomControlsFullscreenDetector* fullscreenDetector() const {
53 return fullscreenDetectorFor(videoElement());
54 }
55
56 Document& document() const { return m_pageHolder->document(); }
57 Document& newDocument() const { return m_newPageHolder->document(); }
58
59 bool checkEventListenerRegistered(EventTarget& target,
60 const AtomicString& eventType,
61 EventListener* listener) {
62 EventListenerVector* listeners = target.getEventListeners(eventType);
63 if (!listeners)
64 return false;
65
66 for (const auto& registeredListener : *listeners) {
67 if (registeredListener.listener() == listener)
68 return true;
69 }
70 return false;
71 }
72
73 static bool computeIsDominantVideo(const IntRect& targetRect,
74 const IntRect& rootRect,
75 const IntRect& intersectionRect) {
76 return MediaCustomControlsFullscreenDetector::
77 computeIsDominantVideoForTests(targetRect, rootRect, intersectionRect);
78 }
79
80 private:
81 std::unique_ptr<DummyPageHolder> m_pageHolder;
82 std::unique_ptr<DummyPageHolder> m_newPageHolder;
83 Persistent<HTMLVideoElement> m_video;
84
85 bool m_originalVideoFullscreenDetectionEnabled;
86 };
87
88 TEST_F(MediaCustomControlsFullscreenDetectorTest, computeIsDominantVideo) {
89 // TestWithParam cannot be applied here as IntRect needs the memory allocator
90 // to be initialized, but the array of parameters is statically initialized,
91 // which is before the memory allocation initialization.
92 TestParam testParams[] = {
93 {"xCompleteFill", {0, 0, 100, 50}, true},
94 {"yCompleteFill", {0, 0, 50, 100}, true},
95 {"xyCompleteFill", {0, 0, 100, 100}, true},
96 {"xIncompleteFillTooSmall", {0, 0, 84, 50}, false},
97 {"yIncompleteFillTooSmall", {0, 0, 50, 84}, false},
98 {"xIncompleteFillJustRight", {0, 0, 86, 50}, true},
99 {"yIncompleteFillJustRight", {0, 0, 50, 86}, true},
100 {"xVisibleProportionTooSmall", {-26, 0, 100, 100}, false},
101 {"yVisibleProportionTooSmall", {0, -26, 100, 100}, false},
102 {"xVisibleProportionJustRight", {-24, 0, 100, 100}, true},
103 {"yVisibleProportionJustRight", {0, -24, 100, 100}, true},
104 };
105
106 IntRect rootRect(0, 0, 100, 100);
107
108 for (const TestParam& testParam : testParams) {
109 const IntRect& targetRect = testParam.targetRect;
110 IntRect intersectionRect = intersection(targetRect, rootRect);
111 EXPECT_EQ(testParam.expectedResult,
112 computeIsDominantVideo(targetRect, rootRect, intersectionRect))
113 << testParam.description << " failed";
114 }
115 }
116
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
138 EXPECT_TRUE(checkEventListenerRegistered(
139 document(), EventTypeNames::fullscreenchange, fullscreenDetector()));
140 EXPECT_TRUE(checkEventListenerRegistered(
141 document(), EventTypeNames::webkitfullscreenchange,
142 fullscreenDetector()));
143 EXPECT_TRUE(checkEventListenerRegistered(
144 *videoElement(), EventTypeNames::loadedmetadata, fullscreenDetector()));
145 }
146
147 TEST_F(MediaCustomControlsFullscreenDetectorTest,
148 hasListenersAfterAddToDocumentByParser) {
149 document().body()->setInnerHTML("<body><video></video></body>");
150
151 EXPECT_TRUE(checkEventListenerRegistered(
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)));
171 EXPECT_FALSE(checkEventListenerRegistered(
172 document(), EventTypeNames::webkitfullscreenchange,
173 fullscreenDetectorFor(video)));
174
175 EXPECT_TRUE(checkEventListenerRegistered(newDocument(),
176 EventTypeNames::fullscreenchange,
177 fullscreenDetectorFor(video)));
178 EXPECT_TRUE(checkEventListenerRegistered(
179 newDocument(), EventTypeNames::webkitfullscreenchange,
180 fullscreenDetectorFor(video)));
181
182 EXPECT_TRUE(checkEventListenerRegistered(
183 *video, EventTypeNames::loadedmetadata, fullscreenDetectorFor(video)));
184 }
185
186 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698