Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 void compositeFrame() { | |
| 33 compositor().beginFrame(); | |
| 34 testing::runPendingTasks(); | |
|
ojan
2016/11/30 07:09:40
This would be for running tasks that are scheduled
xjz
2016/11/30 18:58:16
Done.
| |
| 35 ASSERT_FALSE(compositor().needsBeginFrame()); | |
| 36 } | |
| 37 | |
| 38 std::unique_ptr<SimRequest> createMainResource() { | |
| 39 std::unique_ptr<SimRequest> mainResource = | |
| 40 wrapUnique(new SimRequest("https://example.com/", "text/html")); | |
| 41 loadURL("https://example.com"); | |
| 42 return mainResource; | |
| 43 } | |
| 44 }; | |
| 45 | |
| 46 TEST_F(MediaElementFillingViewportTest, MostlyFillingViewport) { | |
| 47 std::unique_ptr<SimRequest> mainResource = createMainResource(); | |
| 48 mainResource->complete( | |
| 49 "<!DOCTYPE html>" | |
| 50 "<html>" | |
| 51 "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; " | |
| 52 "height:100%;'>" | |
| 53 "source src='test.webm'" | |
| 54 "</video>" | |
| 55 "</html>"); | |
| 56 compositeFrame(); | |
| 57 | |
| 58 HTMLMediaElement* element = | |
| 59 toElement<HTMLMediaElement>(document().getElementById("video")); | |
| 60 checkViewportIntersectionChanged(element); | |
| 61 EXPECT_FALSE(isMostlyFillingViewport(element)); | |
| 62 EXPECT_TRUE(viewportFillDebouncerTimerActive(element)); | |
| 63 // TODO(xjz): Mock the time and check isMostlyFillingViewport() after 5s. | |
| 64 } | |
| 65 | |
| 66 TEST_F(MediaElementFillingViewportTest, NotMostlyFillingViewport) { | |
| 67 std::unique_ptr<SimRequest> mainResource = createMainResource(); | |
| 68 mainResource->complete( | |
| 69 "<!DOCTYPE html>" | |
| 70 "<html>" | |
| 71 "<video id='video' style = 'position:fixed; left:0; top:0; width:80%; " | |
| 72 "height:80%;'>" | |
| 73 "source src='test.webm'" | |
| 74 "</video>" | |
| 75 "</html>"); | |
| 76 compositeFrame(); | |
| 77 | |
| 78 HTMLMediaElement* element = | |
| 79 toElement<HTMLMediaElement>(document().getElementById("video")); | |
| 80 checkViewportIntersectionChanged(element); | |
| 81 EXPECT_FALSE(isMostlyFillingViewport(element)); | |
| 82 EXPECT_FALSE(viewportFillDebouncerTimerActive(element)); | |
| 83 } | |
| 84 | |
| 85 TEST_F(MediaElementFillingViewportTest, FillingViewportChanged) { | |
|
ojan
2016/11/30 07:09:40
For good measure, you might also want to test the
xjz
2016/11/30 18:58:16
Done.
| |
| 86 std::unique_ptr<SimRequest> mainResource = createMainResource(); | |
| 87 mainResource->complete( | |
| 88 "<!DOCTYPE html>" | |
| 89 "<html>" | |
| 90 "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; " | |
| 91 "height:100%;'>" | |
| 92 "source src='test.webm'" | |
| 93 "</video>" | |
| 94 "</html>"); | |
| 95 compositeFrame(); | |
| 96 | |
| 97 HTMLMediaElement* element = | |
| 98 toElement<HTMLMediaElement>(document().getElementById("video")); | |
| 99 checkViewportIntersectionChanged(element); | |
| 100 EXPECT_FALSE(isMostlyFillingViewport(element)); | |
| 101 EXPECT_TRUE(viewportFillDebouncerTimerActive(element)); | |
| 102 | |
| 103 element->setAttribute("style", | |
| 104 "position:fixed; left:0; top:0; width:80%; height:80%;", | |
| 105 ASSERT_NO_EXCEPTION); | |
| 106 compositeFrame(); | |
| 107 | |
| 108 checkViewportIntersectionChanged(element); | |
| 109 EXPECT_FALSE(isMostlyFillingViewport(element)); | |
| 110 EXPECT_FALSE(viewportFillDebouncerTimerActive(element)); | |
| 111 } | |
| 112 | |
| 113 } // namespace blink | |
| OLD | NEW |