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

Side by Side Diff: third_party/WebKit/Source/web/tests/MediaElementFillingViewportTest.cpp

Issue 2511143006: Detect change on the intersection of video and viewport. (Closed)
Patch Set: Rebase again. Created 4 years 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 2016 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/dom/Document.h"
6 #include "core/html/HTMLMediaElement.h"
7 #include "platform/testing/UnitTestHelpers.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "web/tests/sim/SimCompositor.h"
10 #include "web/tests/sim/SimDisplayItemList.h"
11 #include "web/tests/sim/SimRequest.h"
12 #include "web/tests/sim/SimTest.h"
13
14 namespace blink {
15
16 class MediaElementFillingViewportTest : public SimTest {
17 protected:
18 MediaElementFillingViewportTest() { webView().resize(WebSize(640, 480)); }
19
20 bool isMostlyFillingViewport(HTMLMediaElement* element) {
21 return element->m_mostlyFillingViewport;
22 }
23
24 bool viewportFillDebouncerTimerActive(HTMLMediaElement* element) {
25 return element->m_viewportFillDebouncerTimer.isActive();
26 }
27
28 void checkViewportIntersectionChanged(HTMLMediaElement* element) {
29 element->checkViewportIntersectionChanged();
30 }
31
32 std::unique_ptr<SimRequest> createMainResource() {
33 std::unique_ptr<SimRequest> mainResource =
34 wrapUnique(new SimRequest("https://example.com/", "text/html"));
35 loadURL("https://example.com");
36 return mainResource;
37 }
38 };
39
40 TEST_F(MediaElementFillingViewportTest, MostlyFillingViewport) {
41 std::unique_ptr<SimRequest> mainResource = createMainResource();
42 mainResource->complete(
43 "<!DOCTYPE html>"
44 "<html>"
45 "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; "
46 "height:100%;'>"
47 "source src='test.webm'"
48 "</video>"
49 "</html>");
50 compositor().beginFrame();
51
52 HTMLMediaElement* element =
53 toElement<HTMLMediaElement>(document().getElementById("video"));
54 checkViewportIntersectionChanged(element);
55 EXPECT_FALSE(isMostlyFillingViewport(element));
56 EXPECT_TRUE(viewportFillDebouncerTimerActive(element));
57 // TODO(xjz): Mock the time and check isMostlyFillingViewport() after 5s.
58 }
59
60 TEST_F(MediaElementFillingViewportTest, NotMostlyFillingViewport) {
61 std::unique_ptr<SimRequest> mainResource = createMainResource();
62 mainResource->complete(
63 "<!DOCTYPE html>"
64 "<html>"
65 "<video id='video' style = 'position:fixed; left:0; top:0; width:80%; "
66 "height:80%;'>"
67 "source src='test.webm'"
68 "</video>"
69 "</html>");
70 compositor().beginFrame();
71
72 HTMLMediaElement* element =
73 toElement<HTMLMediaElement>(document().getElementById("video"));
74 checkViewportIntersectionChanged(element);
75 EXPECT_FALSE(isMostlyFillingViewport(element));
76 EXPECT_FALSE(viewportFillDebouncerTimerActive(element));
77 }
78
79 TEST_F(MediaElementFillingViewportTest, FillingViewportChanged) {
80 std::unique_ptr<SimRequest> mainResource = createMainResource();
81 mainResource->complete(
82 "<!DOCTYPE html>"
83 "<html>"
84 "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; "
85 "height:100%;'>"
86 "source src='test.webm'"
87 "</video>"
88 "</html>");
89 compositor().beginFrame();
90
91 HTMLMediaElement* element =
92 toElement<HTMLMediaElement>(document().getElementById("video"));
93 checkViewportIntersectionChanged(element);
94 EXPECT_FALSE(isMostlyFillingViewport(element));
95 EXPECT_TRUE(viewportFillDebouncerTimerActive(element));
96
97 element->setAttribute("style",
98 "position:fixed; left:0; top:0; width:80%; height:80%;",
99 ASSERT_NO_EXCEPTION);
100 compositor().beginFrame();
101
102 checkViewportIntersectionChanged(element);
103 EXPECT_FALSE(isMostlyFillingViewport(element));
104 EXPECT_FALSE(viewportFillDebouncerTimerActive(element));
105 }
106
107 TEST_F(MediaElementFillingViewportTest, LargeVideo) {
108 std::unique_ptr<SimRequest> mainResource = createMainResource();
109 mainResource->complete(
110 "<!DOCTYPE html>"
111 "<html>"
112 "<video id='video' style = 'position:fixed; left:0; top:0; width:200%; "
113 "height:200%;'>"
114 "source src='test.webm'"
115 "</video>"
116 "</html>");
117 compositor().beginFrame();
118
119 HTMLMediaElement* element =
120 toElement<HTMLMediaElement>(document().getElementById("video"));
121 checkViewportIntersectionChanged(element);
122 EXPECT_FALSE(isMostlyFillingViewport(element));
123 EXPECT_TRUE(viewportFillDebouncerTimerActive(element));
124 }
125
126 TEST_F(MediaElementFillingViewportTest, VideoScrollOutHalf) {
127 std::unique_ptr<SimRequest> mainResource = createMainResource();
128 mainResource->complete(
129 "<!DOCTYPE html>"
130 "<html>"
131 "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; "
132 "height:100%;'>"
133 "source src='test.webm'"
134 "</video>"
135 "</html>");
136 compositor().beginFrame();
137
138 HTMLMediaElement* element =
139 toElement<HTMLMediaElement>(document().getElementById("video"));
140 checkViewportIntersectionChanged(element);
141 EXPECT_FALSE(isMostlyFillingViewport(element));
142 EXPECT_TRUE(viewportFillDebouncerTimerActive(element));
143
144 element->setAttribute(
145 "style", "position:fixed; left:0; top:240px; width:100%; height:100%;",
146 ASSERT_NO_EXCEPTION);
147 compositor().beginFrame();
148 checkViewportIntersectionChanged(element);
149 EXPECT_FALSE(isMostlyFillingViewport(element));
150 EXPECT_FALSE(viewportFillDebouncerTimerActive(element));
151 }
152
153 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | third_party/WebKit/public/platform/WebMediaPlayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698