Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/MediaElementFillingViewportTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/MediaElementFillingViewportTest.cpp b/third_party/WebKit/Source/web/tests/MediaElementFillingViewportTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d712eccf7c8c50a87a36ac54dddea79e7f99a41b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/web/tests/MediaElementFillingViewportTest.cpp |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/dom/Document.h" |
| +#include "core/html/HTMLMediaElement.h" |
| +#include "platform/testing/UnitTestHelpers.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "web/tests/sim/SimCompositor.h" |
| +#include "web/tests/sim/SimDisplayItemList.h" |
| +#include "web/tests/sim/SimRequest.h" |
| +#include "web/tests/sim/SimTest.h" |
| + |
| +namespace blink { |
| + |
| +class MediaElementFillingViewportTest : public SimTest { |
| + protected: |
| + MediaElementFillingViewportTest() { webView().resize(WebSize(640, 480)); } |
| + |
| + bool isMostlyFillingViewport(HTMLMediaElement* element) { |
| + return element->m_mostlyFillingViewport; |
| + } |
| + |
| + bool viewportFillDebouncerTimerActive(HTMLMediaElement* element) { |
| + return element->m_viewportFillDebouncerTimer.isActive(); |
| + } |
| + |
| + void checkViewportIntersectionChanged(HTMLMediaElement* element) { |
| + element->checkViewportIntersectionChanged(); |
| + } |
| + |
| + void compositeFrame() { |
| + compositor().beginFrame(); |
| + 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.
|
| + ASSERT_FALSE(compositor().needsBeginFrame()); |
| + } |
| + |
| + std::unique_ptr<SimRequest> createMainResource() { |
| + std::unique_ptr<SimRequest> mainResource = |
| + wrapUnique(new SimRequest("https://example.com/", "text/html")); |
| + loadURL("https://example.com"); |
| + return mainResource; |
| + } |
| +}; |
| + |
| +TEST_F(MediaElementFillingViewportTest, MostlyFillingViewport) { |
| + std::unique_ptr<SimRequest> mainResource = createMainResource(); |
| + mainResource->complete( |
| + "<!DOCTYPE html>" |
| + "<html>" |
| + "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; " |
| + "height:100%;'>" |
| + "source src='test.webm'" |
| + "</video>" |
| + "</html>"); |
| + compositeFrame(); |
| + |
| + HTMLMediaElement* element = |
| + toElement<HTMLMediaElement>(document().getElementById("video")); |
| + checkViewportIntersectionChanged(element); |
| + EXPECT_FALSE(isMostlyFillingViewport(element)); |
| + EXPECT_TRUE(viewportFillDebouncerTimerActive(element)); |
| + // TODO(xjz): Mock the time and check isMostlyFillingViewport() after 5s. |
| +} |
| + |
| +TEST_F(MediaElementFillingViewportTest, NotMostlyFillingViewport) { |
| + std::unique_ptr<SimRequest> mainResource = createMainResource(); |
| + mainResource->complete( |
| + "<!DOCTYPE html>" |
| + "<html>" |
| + "<video id='video' style = 'position:fixed; left:0; top:0; width:80%; " |
| + "height:80%;'>" |
| + "source src='test.webm'" |
| + "</video>" |
| + "</html>"); |
| + compositeFrame(); |
| + |
| + HTMLMediaElement* element = |
| + toElement<HTMLMediaElement>(document().getElementById("video")); |
| + checkViewportIntersectionChanged(element); |
| + EXPECT_FALSE(isMostlyFillingViewport(element)); |
| + EXPECT_FALSE(viewportFillDebouncerTimerActive(element)); |
| +} |
| + |
| +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.
|
| + std::unique_ptr<SimRequest> mainResource = createMainResource(); |
| + mainResource->complete( |
| + "<!DOCTYPE html>" |
| + "<html>" |
| + "<video id='video' style = 'position:fixed; left:0; top:0; width:100%; " |
| + "height:100%;'>" |
| + "source src='test.webm'" |
| + "</video>" |
| + "</html>"); |
| + compositeFrame(); |
| + |
| + HTMLMediaElement* element = |
| + toElement<HTMLMediaElement>(document().getElementById("video")); |
| + checkViewportIntersectionChanged(element); |
| + EXPECT_FALSE(isMostlyFillingViewport(element)); |
| + EXPECT_TRUE(viewportFillDebouncerTimerActive(element)); |
| + |
| + element->setAttribute("style", |
| + "position:fixed; left:0; top:0; width:80%; height:80%;", |
| + ASSERT_NO_EXCEPTION); |
| + compositeFrame(); |
| + |
| + checkViewportIntersectionChanged(element); |
| + EXPECT_FALSE(isMostlyFillingViewport(element)); |
| + EXPECT_FALSE(viewportFillDebouncerTimerActive(element)); |
| +} |
| + |
| +} // namespace blink |