Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/html/HTMLVideoElement.h" | |
| 7 | |
| 8 #include "core/dom/Document.h" | |
| 9 #include "core/loader/EmptyClients.h" | |
| 10 #include "core/page/NetworkStateNotifier.h" | |
| 11 #include "core/testing/DummyPageHolder.h" | |
| 12 #include "platform/UserGestureIndicator.h" | |
| 13 #include "platform/testing/UnitTestHelpers.h" | |
| 14 #include "public/platform/WebMediaPlayer.h" | |
| 15 #include "public/platform/WebSize.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace blink { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 class EmptyWebMediaPlayer : public WebMediaPlayer { | |
|
sandersd (OOO until July 31)
2015/12/17 19:05:56
It seems like this should be in a separate file, b
philipj_slow
2015/12/18 15:02:27
Not that I'm aware of, until now we haven't had an
mlamouri (slow - plz ping)
2016/01/05 15:00:07
What about doing something similar to:
https://cod
| |
| 24 public: | |
| 25 void load(LoadType, const WebURL&, CORSMode) override { }; | |
| 26 void play() override { }; | |
| 27 void pause() override { }; | |
| 28 bool supportsSave() const override { return false; }; | |
| 29 void seek(double seconds) override { }; | |
| 30 void setRate(double) override { }; | |
| 31 void setVolume(double) override { }; | |
| 32 WebTimeRanges buffered() const override { return WebTimeRanges(); }; | |
| 33 WebTimeRanges seekable() const override { return WebTimeRanges(); }; | |
| 34 void setSinkId(const WebString& sinkId, const WebSecurityOrigin&, WebSetSink IdCallbacks*) override { }; | |
| 35 bool hasVideo() const override { return false; }; | |
| 36 bool hasAudio() const override { return false; }; | |
| 37 WebSize naturalSize() const override { return WebSize(0, 0); }; | |
| 38 bool paused() const override { return false; }; | |
| 39 bool seeking() const override { return false; }; | |
| 40 double duration() const override { return 0.0; }; | |
| 41 double currentTime() const override { return 0.0; }; | |
| 42 NetworkState networkState() const override { return NetworkStateEmpty; }; | |
| 43 ReadyState readyState() const override { return ReadyStateHaveNothing; }; | |
| 44 bool didLoadingProgress() override { return false; }; | |
| 45 bool hasSingleSecurityOrigin() const override { return true; }; | |
| 46 bool didPassCORSAccessCheck() const override { return true; }; | |
| 47 double mediaTimeForTimeValue(double timeValue) const override { return timeV alue; }; | |
| 48 unsigned decodedFrameCount() const override { return 0; }; | |
| 49 unsigned droppedFrameCount() const override { return 0; }; | |
| 50 unsigned audioDecodedByteCount() const override { return 0; }; | |
| 51 unsigned videoDecodedByteCount() const override { return 0; }; | |
| 52 void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode ) override { }; | |
| 53 }; | |
| 54 | |
| 55 class MockWebMediaPlayer : public EmptyWebMediaPlayer { | |
| 56 public: | |
| 57 MOCK_METHOD1(setBufferingStrategy, void(BufferingStrategy)); | |
| 58 }; | |
| 59 | |
| 60 class StubFrameLoaderClient : public EmptyFrameLoaderClient { | |
| 61 public: | |
| 62 static PassOwnPtrWillBeRawPtr<StubFrameLoaderClient> create() | |
| 63 { | |
| 64 return adoptPtrWillBeNoop(new StubFrameLoaderClient); | |
| 65 } | |
| 66 | |
| 67 PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(HTMLMediaElement&, const Web URL&, WebMediaPlayerClient*) override | |
| 68 { | |
| 69 return adoptPtr(new MockWebMediaPlayer); | |
| 70 } | |
| 71 }; | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 class HTMLVideoElementTest : public ::testing::Test { | |
|
sandersd (OOO until July 31)
2015/12/17 19:05:56
The test cases here are better on HTMLMediaElement
philipj_slow
2015/12/18 15:02:27
Just HTMLVideoElementTest seems fine, if unit test
| |
| 76 protected: | |
| 77 HTMLVideoElementTest() | |
| 78 : m_dummyPageHolder(DummyPageHolder::create(IntSize(640, 360), nullptr, StubFrameLoaderClient::create())) | |
| 79 { | |
| 80 // TODO(sandersd): This should be done by a settings initializer. | |
| 81 networkStateNotifier().setWebConnection(WebConnectionTypeWifi, 54.0); | |
| 82 m_video = HTMLVideoElement::create(m_dummyPageHolder->document()); | |
| 83 } | |
| 84 | |
| 85 void setSrc(const AtomicString& url) | |
| 86 { | |
| 87 m_video->setSrc(url); | |
| 88 testing::runPendingTasks(); | |
| 89 } | |
| 90 | |
| 91 MockWebMediaPlayer* webMediaPlayer() | |
| 92 { | |
| 93 return static_cast<MockWebMediaPlayer*>(m_video->webMediaPlayer()); | |
| 94 } | |
| 95 | |
| 96 OwnPtr<DummyPageHolder> m_dummyPageHolder; | |
| 97 RefPtrWillBeMember<HTMLVideoElement> m_video; | |
|
sof
2016/01/05 18:51:48
RefPtrWillBePersistent<>
sandersd (OOO until July 31)
2016/01/08 00:02:11
Done.
| |
| 98 }; | |
| 99 | |
| 100 TEST_F(HTMLVideoElementTest, setBufferingStrategy_NonUserPause) | |
| 101 { | |
| 102 setSrc("http://foo.bar/"); | |
| 103 MockWebMediaPlayer* player = webMediaPlayer(); | |
| 104 ASSERT_TRUE(player); | |
| 105 | |
| 106 // On play, the strategy is set to normal. | |
| 107 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal)); | |
| 108 m_video->play(); | |
| 109 ::testing::Mock::VerifyAndClearExpectations(player); | |
| 110 | |
| 111 // On a non-user pause, the strategy is not changed. | |
| 112 m_video->pause(); | |
| 113 ::testing::Mock::VerifyAndClearExpectations(player); | |
| 114 | |
| 115 // On play, the strategy is set to normal. | |
| 116 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal)); | |
| 117 m_video->play(); | |
| 118 ::testing::Mock::VerifyAndClearExpectations(player); | |
| 119 } | |
| 120 | |
| 121 TEST_F(HTMLVideoElementTest, setBufferingStrategy_UserPause) | |
| 122 { | |
| 123 setSrc("http://foo.bar/"); | |
| 124 MockWebMediaPlayer* player = webMediaPlayer(); | |
| 125 ASSERT_TRUE(player); | |
| 126 | |
| 127 // On play, the strategy is set to normal. | |
| 128 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal)); | |
| 129 video->play(); | |
| 130 ::testing::Mock::VerifyAndClearExpectations(player); | |
| 131 | |
| 132 // On a user pause, the strategy is set to aggressive. | |
| 133 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Aggressive)); | |
| 134 { | |
| 135 UserGestureIndicator gesture(DefinitelyProcessingUserGesture); | |
| 136 video->pause(); | |
| 137 } | |
| 138 ::testing::Mock::VerifyAndClearExpectations(player); | |
| 139 | |
| 140 // On play, the strategy is set to normal. | |
| 141 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal)); | |
| 142 video->play(); | |
| 143 ::testing::Mock::VerifyAndClearExpectations(player); | |
| 144 } | |
| 145 | |
| 146 } // namespace blink | |
| OLD | NEW |