OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/html/HTMLVideoElement.h" | 5 #include "core/html/HTMLVideoElement.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/DocumentUserGestureToken.h" | 8 #include "core/dom/DocumentUserGestureToken.h" |
9 #include "core/loader/EmptyClients.h" | 9 #include "core/loader/EmptyClients.h" |
10 #include "core/page/NetworkStateNotifier.h" | 10 #include "core/page/NetworkStateNotifier.h" |
11 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
12 #include "platform/RuntimeEnabledFeatures.h" | |
12 #include "platform/UserGestureIndicator.h" | 13 #include "platform/UserGestureIndicator.h" |
13 #include "platform/testing/UnitTestHelpers.h" | 14 #include "platform/testing/UnitTestHelpers.h" |
14 #include "public/platform/WebMediaPlayer.h" | 15 #include "public/platform/WebMediaPlayer.h" |
15 #include "public/platform/WebSize.h" | 16 #include "public/platform/WebSize.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "wtf/PtrUtil.h" | 19 #include "wtf/PtrUtil.h" |
19 #include <memory> | 20 #include <memory> |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 unsigned decodedFrameCount() const override { return 0; }; | 56 unsigned decodedFrameCount() const override { return 0; }; |
56 unsigned droppedFrameCount() const override { return 0; }; | 57 unsigned droppedFrameCount() const override { return 0; }; |
57 size_t audioDecodedByteCount() const override { return 0; }; | 58 size_t audioDecodedByteCount() const override { return 0; }; |
58 size_t videoDecodedByteCount() const override { return 0; }; | 59 size_t videoDecodedByteCount() const override { return 0; }; |
59 void paint(WebCanvas*, const WebRect&, SkPaint&) override{}; | 60 void paint(WebCanvas*, const WebRect&, SkPaint&) override{}; |
60 }; | 61 }; |
61 | 62 |
62 class MockWebMediaPlayer : public EmptyWebMediaPlayer { | 63 class MockWebMediaPlayer : public EmptyWebMediaPlayer { |
63 public: | 64 public: |
64 MOCK_METHOD1(setBufferingStrategy, void(BufferingStrategy)); | 65 MOCK_METHOD1(setBufferingStrategy, void(BufferingStrategy)); |
66 MOCK_METHOD1(selectedVideoTrackChanged, | |
67 void(blink::WebMediaPlayer::TrackId*)); | |
68 MOCK_CONST_METHOD0(hasAudio, bool()); | |
69 MOCK_CONST_METHOD0(hasVideo, bool()); | |
65 }; | 70 }; |
66 | 71 |
67 class StubFrameLoaderClient : public EmptyFrameLoaderClient { | 72 class StubFrameLoaderClient : public EmptyFrameLoaderClient { |
68 public: | 73 public: |
69 static StubFrameLoaderClient* create() { return new StubFrameLoaderClient; } | 74 static StubFrameLoaderClient* create() { return new StubFrameLoaderClient; } |
70 | 75 |
71 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer( | 76 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer( |
72 HTMLMediaElement&, | 77 HTMLMediaElement&, |
73 const WebMediaPlayerSource&, | 78 const WebMediaPlayerSource&, |
74 WebMediaPlayerClient*) override { | 79 WebMediaPlayerClient*) override { |
(...skipping 13 matching lines...) Expand all Loading... | |
88 // TODO(sandersd): This should be done by a settings initializer. | 93 // TODO(sandersd): This should be done by a settings initializer. |
89 networkStateNotifier().setWebConnection(WebConnectionTypeWifi, 54.0); | 94 networkStateNotifier().setWebConnection(WebConnectionTypeWifi, 54.0); |
90 m_video = HTMLVideoElement::create(m_dummyPageHolder->document()); | 95 m_video = HTMLVideoElement::create(m_dummyPageHolder->document()); |
91 } | 96 } |
92 | 97 |
93 void setSrc(const AtomicString& url) { | 98 void setSrc(const AtomicString& url) { |
94 m_video->setSrc(url); | 99 m_video->setSrc(url); |
95 testing::runPendingTasks(); | 100 testing::runPendingTasks(); |
96 } | 101 } |
97 | 102 |
103 void setReadyState(HTMLMediaElement::ReadyState state) { | |
104 m_video->setReadyState(state); | |
105 } | |
106 | |
107 void hide() { m_video->hidden(); } | |
108 | |
109 void show() { m_video->shown(); } | |
110 | |
98 MockWebMediaPlayer* webMediaPlayer() { | 111 MockWebMediaPlayer* webMediaPlayer() { |
99 return static_cast<MockWebMediaPlayer*>(m_video->webMediaPlayer()); | 112 return static_cast<MockWebMediaPlayer*>(m_video->webMediaPlayer()); |
100 } | 113 } |
101 | 114 |
102 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 115 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
103 Persistent<HTMLVideoElement> m_video; | 116 Persistent<HTMLVideoElement> m_video; |
104 }; | 117 }; |
105 | 118 |
106 TEST_F(HTMLVideoElementTest, setBufferingStrategy_NonUserPause) { | 119 TEST_F(HTMLVideoElementTest, setBufferingStrategy_NonUserPause) { |
107 setSrc("http://foo.bar/"); | 120 setSrc("http://foo.bar/"); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 159 } |
147 ::testing::Mock::VerifyAndClearExpectations(player); | 160 ::testing::Mock::VerifyAndClearExpectations(player); |
148 | 161 |
149 // On play, the strategy is set to normal. | 162 // On play, the strategy is set to normal. |
150 EXPECT_CALL(*player, | 163 EXPECT_CALL(*player, |
151 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal)); | 164 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal)); |
152 m_video->play(); | 165 m_video->play(); |
153 ::testing::Mock::VerifyAndClearExpectations(player); | 166 ::testing::Mock::VerifyAndClearExpectations(player); |
154 } | 167 } |
155 | 168 |
169 TEST_F(HTMLVideoElementTest, unselectSelectVideoTrackWhenHiddenAndShown) { | |
170 RuntimeEnabledFeatures::setBackgroundVideoTrackOptimizationEnabled(true); | |
171 | |
172 setSrc("http://foo.bar/"); | |
173 MockWebMediaPlayer* player = webMediaPlayer(); | |
174 ASSERT_TRUE(player); | |
175 | |
176 EXPECT_CALL(*player, hasAudio()).WillRepeatedly(::testing::Return(true)); | |
177 EXPECT_CALL(*player, hasVideo()).WillRepeatedly(::testing::Return(true)); | |
178 | |
179 setReadyState(HTMLMediaElement::kHaveMetadata); | |
180 | |
181 EXPECT_CALL(*player, selectedVideoTrackChanged(nullptr)); | |
182 hide(); | |
183 ::testing::Mock::VerifyAndClearExpectations(player); | |
184 | |
185 EXPECT_CALL(*player, selectedVideoTrackChanged(::testing::_)); | |
186 show(); | |
187 ::testing::Mock::VerifyAndClearExpectations(player); | |
188 } | |
mlamouri (slow - plz ping)
2016/11/12 23:35:48
tests <3
| |
189 | |
156 } // namespace blink | 190 } // namespace blink |
OLD | NEW |