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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLVideoElementTest.cpp

Issue 2689323002: Media: Delete Pause-To-Buffer. (Closed)
Patch Set: Rebase. Created 3 years, 8 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
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 <memory>
8 #include "core/dom/Document.h"
9 #include "core/dom/DocumentUserGestureToken.h"
10 #include "core/loader/EmptyClients.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include "platform/UserGestureIndicator.h"
13 #include "platform/network/NetworkStateNotifier.h"
14 #include "platform/testing/EmptyWebMediaPlayer.h"
15 #include "platform/testing/UnitTestHelpers.h"
16 #include "public/platform/WebSize.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "wtf/PtrUtil.h"
20
21 namespace blink {
22
23 namespace {
24
25 class MockWebMediaPlayer : public EmptyWebMediaPlayer {
26 public:
27 MOCK_METHOD1(setBufferingStrategy, void(BufferingStrategy));
28 };
29
30 class StubLocalFrameClient : public EmptyLocalFrameClient {
31 public:
32 static StubLocalFrameClient* create() { return new StubLocalFrameClient; }
33
34 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer(
35 HTMLMediaElement&,
36 const WebMediaPlayerSource&,
37 WebMediaPlayerClient*) override {
38 return WTF::wrapUnique(new MockWebMediaPlayer);
39 }
40 };
41
42 } // namespace
43
44 class HTMLVideoElementTest : public ::testing::Test {
45 protected:
46 HTMLVideoElementTest()
47 : m_dummyPageHolder(
48 DummyPageHolder::create(IntSize(640, 360),
49 nullptr,
50 StubLocalFrameClient::create())) {
51 // TODO(sandersd): This should be done by a settings initializer.
52 networkStateNotifier().setWebConnection(WebConnectionTypeWifi, 54.0);
53 m_video = HTMLVideoElement::create(m_dummyPageHolder->document());
54 }
55
56 void setSrc(const AtomicString& url) {
57 m_video->setSrc(url);
58 testing::runPendingTasks();
59 }
60
61 MockWebMediaPlayer* webMediaPlayer() {
62 return static_cast<MockWebMediaPlayer*>(m_video->webMediaPlayer());
63 }
64
65 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
66 Persistent<HTMLVideoElement> m_video;
67 };
68
69 TEST_F(HTMLVideoElementTest, setBufferingStrategy_NonUserPause) {
70 setSrc("http://foo.bar/");
71 MockWebMediaPlayer* player = webMediaPlayer();
72 ASSERT_TRUE(player);
73
74 // On play, the strategy is set to normal.
75 EXPECT_CALL(*player,
76 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
77 m_video->play();
78 ::testing::Mock::VerifyAndClearExpectations(player);
79
80 // On a non-user pause, the strategy is not changed.
81 m_video->pause();
82 ::testing::Mock::VerifyAndClearExpectations(player);
83
84 // On play, the strategy is set to normal.
85 EXPECT_CALL(*player,
86 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
87 m_video->play();
88 ::testing::Mock::VerifyAndClearExpectations(player);
89 }
90
91 TEST_F(HTMLVideoElementTest, setBufferingStrategy_UserPause) {
92 setSrc("http://foo.bar/");
93 MockWebMediaPlayer* player = webMediaPlayer();
94 ASSERT_TRUE(player);
95
96 // On play, the strategy is set to normal.
97 EXPECT_CALL(*player,
98 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
99 m_video->play();
100 ::testing::Mock::VerifyAndClearExpectations(player);
101
102 // On a user pause, the strategy is set to aggressive.
103 EXPECT_CALL(*player, setBufferingStrategy(
104 WebMediaPlayer::BufferingStrategy::Aggressive));
105 {
106 UserGestureIndicator gesture(
107 DocumentUserGestureToken::create(&m_video->document()));
108 m_video->pause();
109 }
110 ::testing::Mock::VerifyAndClearExpectations(player);
111
112 // On play, the strategy is set to normal.
113 EXPECT_CALL(*player,
114 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal));
115 m_video->play();
116 ::testing::Mock::VerifyAndClearExpectations(player);
117 }
118
119 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.cpp ('k') | third_party/WebKit/public/platform/WebMediaPlayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698