Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: third_party/WebKit/Source/core/html/HTMLVideoElementTest.cpp

Issue 1514633006: Add HTMLVideoElementTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLVideoElementTest.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLVideoElementTest.cpp b/third_party/WebKit/Source/core/html/HTMLVideoElementTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5e74588549fb9646609c341765c26081cbb95afd
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/HTMLVideoElementTest.cpp
@@ -0,0 +1,145 @@
+// Copyright 2015 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/html/HTMLVideoElement.h"
+
+#include "core/dom/Document.h"
+#include "core/loader/EmptyClients.h"
+#include "core/page/NetworkStateNotifier.h"
+#include "core/testing/DummyPageHolder.h"
+#include "platform/UserGestureIndicator.h"
+#include "platform/testing/UnitTestHelpers.h"
+#include "public/platform/WebMediaPlayer.h"
+#include "public/platform/WebSize.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+class EmptyWebMediaPlayer : public WebMediaPlayer {
+public:
+ void load(LoadType, const WebURL&, CORSMode) override { };
+ void play() override { };
+ void pause() override { };
+ bool supportsSave() const override { return false; };
+ void seek(double seconds) override { };
+ void setRate(double) override { };
+ void setVolume(double) override { };
+ WebTimeRanges buffered() const override { return WebTimeRanges(); };
+ WebTimeRanges seekable() const override { return WebTimeRanges(); };
+ void setSinkId(const WebString& sinkId, const WebSecurityOrigin&, WebSetSinkIdCallbacks*) override { };
+ bool hasVideo() const override { return false; };
+ bool hasAudio() const override { return false; };
+ WebSize naturalSize() const override { return WebSize(0, 0); };
+ bool paused() const override { return false; };
+ bool seeking() const override { return false; };
+ double duration() const override { return 0.0; };
+ double currentTime() const override { return 0.0; };
+ NetworkState networkState() const override { return NetworkStateEmpty; };
+ ReadyState readyState() const override { return ReadyStateHaveNothing; };
+ bool didLoadingProgress() override { return false; };
+ bool hasSingleSecurityOrigin() const override { return true; };
+ bool didPassCORSAccessCheck() const override { return true; };
+ double mediaTimeForTimeValue(double timeValue) const override { return timeValue; };
+ unsigned decodedFrameCount() const override { return 0; };
+ unsigned droppedFrameCount() const override { return 0; };
+ unsigned audioDecodedByteCount() const override { return 0; };
+ unsigned videoDecodedByteCount() const override { return 0; };
+ void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode) override { };
+};
+
+class MockWebMediaPlayer : public EmptyWebMediaPlayer {
+public:
+ MOCK_METHOD1(setBufferingStrategy, void(BufferingStrategy));
+};
+
+class StubFrameLoaderClient : public EmptyFrameLoaderClient {
+public:
+ static PassOwnPtrWillBeRawPtr<StubFrameLoaderClient> create()
+ {
+ return adoptPtrWillBeNoop(new StubFrameLoaderClient);
+ }
+
+ PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(HTMLMediaElement&, const WebURL&, WebMediaPlayerClient*) override
+ {
+ return adoptPtr(new MockWebMediaPlayer);
+ }
+};
+
+} // namespace
+
+class HTMLVideoElementTest : public ::testing::Test {
+protected:
+ HTMLVideoElementTest()
+ : m_dummyPageHolder(DummyPageHolder::create(IntSize(640, 360), nullptr, StubFrameLoaderClient::create()))
+ {
+ // TODO(sandersd): This should be done by a settings initializer.
+ networkStateNotifier().setWebConnection(WebConnectionTypeWifi, 54.0);
+ m_video = HTMLVideoElement::create(m_dummyPageHolder->document());
+ }
+
+ void setSrc(const AtomicString& url)
+ {
+ m_video->setSrc(url);
+ testing::runPendingTasks();
+ }
+
+ MockWebMediaPlayer* webMediaPlayer()
+ {
+ return static_cast<MockWebMediaPlayer*>(m_video->webMediaPlayer());
+ }
+
+ OwnPtr<DummyPageHolder> m_dummyPageHolder;
+ RefPtrWillBePersistent<HTMLVideoElement> m_video;
+};
+
+TEST_F(HTMLVideoElementTest, setBufferingStrategy_NonUserPause)
+{
+ setSrc("http://foo.bar/");
+ MockWebMediaPlayer* player = webMediaPlayer();
+ ASSERT_TRUE(player);
+
+ // On play, the strategy is set to normal.
+ EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
+ m_video->play();
+ ::testing::Mock::VerifyAndClearExpectations(player);
+
+ // On a non-user pause, the strategy is not changed.
+ m_video->pause();
+ ::testing::Mock::VerifyAndClearExpectations(player);
+
+ // On play, the strategy is set to normal.
+ EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
+ m_video->play();
+ ::testing::Mock::VerifyAndClearExpectations(player);
+}
+
+TEST_F(HTMLVideoElementTest, setBufferingStrategy_UserPause)
+{
+ setSrc("http://foo.bar/");
+ MockWebMediaPlayer* player = webMediaPlayer();
+ ASSERT_TRUE(player);
+
+ // On play, the strategy is set to normal.
+ EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
+ m_video->play();
+ ::testing::Mock::VerifyAndClearExpectations(player);
+
+ // On a user pause, the strategy is set to aggressive.
+ EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Aggressive));
+ {
+ UserGestureIndicator gesture(DefinitelyProcessingUserGesture);
+ m_video->pause();
+ }
+ ::testing::Mock::VerifyAndClearExpectations(player);
+
+ // On play, the strategy is set to normal.
+ EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
+ m_video->play();
+ ::testing::Mock::VerifyAndClearExpectations(player);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698