Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/HTMLMediaElement.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "core/dom/DocumentUserGestureToken.h" | |
| 10 #include "core/dom/Fullscreen.h" | |
| 11 #include "core/html/HTMLDivElement.h" | |
| 12 #include "core/loader/EmptyClients.h" | |
| 13 #include "core/testing/DummyPageHolder.h" | |
| 14 #include "platform/UserGestureIndicator.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 class MockChromeClient : public EmptyChromeClient { | |
| 23 public: | |
| 24 MOCK_METHOD1(enterFullscreen, void(LocalFrame&)); | |
| 25 MOCK_METHOD1(exitFullscreen, void(LocalFrame&)); | |
| 26 }; | |
| 27 | |
| 28 using ::testing::_; | |
| 29 using ::testing::Sequence; | |
| 30 | |
| 31 } // anonymous namespace | |
| 32 | |
| 33 class HTMLMediaElementPersistentVideoTest : public ::testing::Test { | |
| 34 protected: | |
| 35 void SetUp() override { | |
| 36 m_chromeClient = new MockChromeClient(); | |
| 37 | |
| 38 Page::PageClients clients; | |
| 39 fillWithEmptyClients(clients); | |
| 40 clients.chromeClient = m_chromeClient.get(); | |
| 41 | |
| 42 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &clients); | |
| 43 document().body()->setInnerHTML("<body><div><video></video></div></body>"); | |
| 44 } | |
| 45 | |
| 46 Document& document() { return m_pageHolder->document(); } | |
| 47 | |
| 48 HTMLMediaElement* videoElement() { | |
| 49 return toHTMLMediaElement(document().querySelector("video")); | |
| 50 } | |
| 51 | |
| 52 HTMLDivElement* divElement() { | |
| 53 return toHTMLDivElement(document().querySelector("div")); | |
| 54 } | |
| 55 | |
| 56 Element* fullscreenElement() { | |
| 57 return Fullscreen::currentFullScreenElementFrom(document()); | |
| 58 } | |
| 59 | |
| 60 MockChromeClient& mockChromeClient() { return *m_chromeClient; } | |
| 61 | |
| 62 void simulateDidEnterFullscreen() { | |
| 63 Fullscreen::fromIfExists(document())->didEnterFullscreen(); | |
| 64 } | |
| 65 | |
| 66 void simulateDidExitFullscreen() { | |
| 67 Fullscreen::fromIfExists(document())->didExitFullscreen(); | |
| 68 } | |
| 69 | |
| 70 void simulateBecamePersistentVideo(bool value) { | |
| 71 videoElement()->onBecamePersistentVideo(value); | |
| 72 } | |
| 73 | |
| 74 bool isPersistentVideo() { return videoElement()->m_isPersistentVideo; } | |
| 75 | |
| 76 private: | |
| 77 std::unique_ptr<DummyPageHolder> m_pageHolder; | |
| 78 Persistent<MockChromeClient> m_chromeClient; | |
| 79 }; | |
| 80 | |
| 81 TEST_F(HTMLMediaElementPersistentVideoTest, testWhenNothingIsFullscreen) { | |
| 82 Sequence s; | |
| 83 | |
| 84 EXPECT_EQ(fullscreenElement(), nullptr); | |
| 85 | |
| 86 EXPECT_CALL(mockChromeClient(), enterFullscreen(_)).InSequence(s); | |
| 87 | |
| 88 // Make the video persistent. | |
| 89 simulateBecamePersistentVideo(true); | |
| 90 simulateDidEnterFullscreen(); | |
| 91 EXPECT_EQ(fullscreenElement(), videoElement()); | |
| 92 EXPECT_TRUE(isPersistentVideo()); | |
| 93 | |
| 94 // This should be no-op. | |
| 95 simulateBecamePersistentVideo(true); | |
|
mlamouri (slow - plz ping)
2017/03/16 17:44:49
Maybe add checks verifying that it's a no-op?
Zhiqiang Zhang (Slow)
2017/03/16 18:08:26
Done.
| |
| 96 | |
| 97 // Make the video not persitent. | |
| 98 EXPECT_CALL(mockChromeClient(), exitFullscreen(_)).InSequence(s); | |
| 99 simulateBecamePersistentVideo(false); | |
| 100 simulateDidExitFullscreen(); | |
| 101 EXPECT_EQ(fullscreenElement(), nullptr); | |
| 102 EXPECT_FALSE(isPersistentVideo()); | |
| 103 | |
| 104 // This should be no-op. | |
| 105 simulateBecamePersistentVideo(false); | |
|
mlamouri (slow - plz ping)
2017/03/16 17:44:49
Maybe we should check that the video is not fullsc
Zhiqiang Zhang (Slow)
2017/03/16 18:08:26
Done.
| |
| 106 } | |
| 107 | |
| 108 TEST_F(HTMLMediaElementPersistentVideoTest, testWhenVideoIsFullscreen) { | |
| 109 EXPECT_EQ(fullscreenElement(), nullptr); | |
| 110 | |
| 111 EXPECT_CALL(mockChromeClient(), enterFullscreen(_)).Times(1); | |
| 112 EXPECT_CALL(mockChromeClient(), exitFullscreen(_)).Times(0); | |
| 113 | |
| 114 // Fullscreen the video in advance. | |
| 115 UserGestureIndicator gestureIndicator( | |
| 116 DocumentUserGestureToken::create(&document())); | |
| 117 Fullscreen::requestFullscreen(*videoElement()); | |
| 118 simulateDidEnterFullscreen(); | |
| 119 EXPECT_EQ(fullscreenElement(), videoElement()); | |
| 120 | |
| 121 // This should be no-op. | |
| 122 simulateBecamePersistentVideo(true); | |
| 123 EXPECT_EQ(fullscreenElement(), videoElement()); | |
| 124 EXPECT_FALSE(isPersistentVideo()); | |
| 125 | |
| 126 // This should be no-op. | |
| 127 simulateBecamePersistentVideo(false); | |
| 128 EXPECT_EQ(fullscreenElement(), videoElement()); | |
| 129 EXPECT_FALSE(isPersistentVideo()); | |
| 130 } | |
| 131 | |
| 132 TEST_F(HTMLMediaElementPersistentVideoTest, testWhenDivIsFullscreen) { | |
| 133 EXPECT_EQ(fullscreenElement(), nullptr); | |
| 134 | |
| 135 EXPECT_CALL(mockChromeClient(), enterFullscreen(_)).Times(2); | |
| 136 EXPECT_CALL(mockChromeClient(), exitFullscreen(_)).Times(0); | |
| 137 | |
| 138 // Fullscreen the video in advance. | |
| 139 UserGestureIndicator gestureIndicator( | |
| 140 DocumentUserGestureToken::create(&document())); | |
| 141 Fullscreen::requestFullscreen(*divElement()); | |
| 142 simulateDidEnterFullscreen(); | |
| 143 EXPECT_EQ(fullscreenElement(), divElement()); | |
| 144 | |
| 145 // Make the video persistent. | |
| 146 simulateBecamePersistentVideo(true); | |
| 147 simulateDidEnterFullscreen(); | |
| 148 EXPECT_EQ(fullscreenElement(), videoElement()); | |
| 149 EXPECT_TRUE(isPersistentVideo()); | |
| 150 | |
| 151 // This should be no-op. | |
| 152 simulateBecamePersistentVideo(true); | |
|
mlamouri (slow - plz ping)
2017/03/16 17:44:49
same as above.
Zhiqiang Zhang (Slow)
2017/03/16 18:08:26
Done.
| |
| 153 | |
| 154 // Make the video not persistent. Don't call simulateDidExitFullscreen as | |
| 155 // there still a fullscreen element in stack. | |
| 156 simulateBecamePersistentVideo(false); | |
| 157 EXPECT_EQ(fullscreenElement(), divElement()); | |
| 158 EXPECT_FALSE(isPersistentVideo()); | |
| 159 } | |
| 160 | |
| 161 } // namespace blink | |
| OLD | NEW |