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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "core/html/HTMLVideoElement.h"
6
7 #include "core/dom/Document.h"
8 #include "core/loader/EmptyClients.h"
9 #include "core/page/NetworkStateNotifier.h"
10 #include "core/testing/DummyPageHolder.h"
11 #include "platform/UserGestureIndicator.h"
12 #include "platform/testing/UnitTestHelpers.h"
13 #include "public/platform/WebMediaPlayer.h"
14 #include "public/platform/WebSize.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 EmptyWebMediaPlayer : public WebMediaPlayer {
23 public:
24 void load(LoadType, const WebURL&, CORSMode) override { };
25 void play() override { };
26 void pause() override { };
27 bool supportsSave() const override { return false; };
28 void seek(double seconds) override { };
29 void setRate(double) override { };
30 void setVolume(double) override { };
31 WebTimeRanges buffered() const override { return WebTimeRanges(); };
32 WebTimeRanges seekable() const override { return WebTimeRanges(); };
33 void setSinkId(const WebString& sinkId, const WebSecurityOrigin&, WebSetSink IdCallbacks*) override { };
34 bool hasVideo() const override { return false; };
35 bool hasAudio() const override { return false; };
36 WebSize naturalSize() const override { return WebSize(0, 0); };
37 bool paused() const override { return false; };
38 bool seeking() const override { return false; };
39 double duration() const override { return 0.0; };
40 double currentTime() const override { return 0.0; };
41 NetworkState networkState() const override { return NetworkStateEmpty; };
42 ReadyState readyState() const override { return ReadyStateHaveNothing; };
43 bool didLoadingProgress() override { return false; };
44 bool hasSingleSecurityOrigin() const override { return true; };
45 bool didPassCORSAccessCheck() const override { return true; };
46 double mediaTimeForTimeValue(double timeValue) const override { return timeV alue; };
47 unsigned decodedFrameCount() const override { return 0; };
48 unsigned droppedFrameCount() const override { return 0; };
49 unsigned audioDecodedByteCount() const override { return 0; };
50 unsigned videoDecodedByteCount() const override { return 0; };
51 void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode ) override { };
52 };
53
54 class MockWebMediaPlayer : public EmptyWebMediaPlayer {
55 public:
56 MOCK_METHOD1(setBufferingStrategy, void(BufferingStrategy));
57 };
58
59 class StubFrameLoaderClient : public EmptyFrameLoaderClient {
60 public:
61 static PassOwnPtrWillBeRawPtr<StubFrameLoaderClient> create()
62 {
63 return adoptPtrWillBeNoop(new StubFrameLoaderClient);
64 }
65
66 PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(HTMLMediaElement&, const Web URL&, WebMediaPlayerClient*) override
67 {
68 return adoptPtr(new MockWebMediaPlayer);
69 }
70 };
71
72 } // namespace
73
74 class HTMLVideoElementTest : public ::testing::Test {
75 protected:
76 HTMLVideoElementTest()
77 : m_dummyPageHolder(DummyPageHolder::create(IntSize(640, 360), nullptr, StubFrameLoaderClient::create()))
78 {
79 // TODO(sandersd): This should be done by a settings initializer.
80 networkStateNotifier().setWebConnection(WebConnectionTypeWifi, 54.0);
81 m_video = HTMLVideoElement::create(m_dummyPageHolder->document());
82 }
83
84 void setSrc(const AtomicString& url)
85 {
86 m_video->setSrc(url);
87 testing::runPendingTasks();
88 }
89
90 MockWebMediaPlayer* webMediaPlayer()
91 {
92 return static_cast<MockWebMediaPlayer*>(m_video->webMediaPlayer());
93 }
94
95 OwnPtr<DummyPageHolder> m_dummyPageHolder;
96 RefPtrWillBePersistent<HTMLVideoElement> m_video;
97 };
98
99 TEST_F(HTMLVideoElementTest, setBufferingStrategy_NonUserPause)
100 {
101 setSrc("http://foo.bar/");
102 MockWebMediaPlayer* player = webMediaPlayer();
103 ASSERT_TRUE(player);
104
105 // On play, the strategy is set to normal.
106 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal));
107 m_video->play();
108 ::testing::Mock::VerifyAndClearExpectations(player);
109
110 // On a non-user pause, the strategy is not changed.
111 m_video->pause();
112 ::testing::Mock::VerifyAndClearExpectations(player);
113
114 // On play, the strategy is set to normal.
115 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal));
116 m_video->play();
117 ::testing::Mock::VerifyAndClearExpectations(player);
118 }
119
120 TEST_F(HTMLVideoElementTest, setBufferingStrategy_UserPause)
121 {
122 setSrc("http://foo.bar/");
123 MockWebMediaPlayer* player = webMediaPlayer();
124 ASSERT_TRUE(player);
125
126 // On play, the strategy is set to normal.
127 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal));
128 m_video->play();
129 ::testing::Mock::VerifyAndClearExpectations(player);
130
131 // On a user pause, the strategy is set to aggressive.
132 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Aggressive));
133 {
134 UserGestureIndicator gesture(DefinitelyProcessingUserGesture);
135 m_video->pause();
136 }
137 ::testing::Mock::VerifyAndClearExpectations(player);
138
139 // On play, the strategy is set to normal.
140 EXPECT_CALL(*player, setBufferingStrategy(WebMediaPlayer::BufferingStrategy: :Normal));
141 m_video->play();
142 ::testing::Mock::VerifyAndClearExpectations(player);
143 }
144
145 } // namespace blink
OLDNEW
« 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