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.
5 #include "base/message_loop/message_loop.h"
6 #include "media/base/android/media_player_bridge.h"
7 #include "media/base/android/media_player_manager.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 class MockMediaPlayerManager
: public MediaPlayerManager
{
17 MOCK_METHOD0(GetMediaResourceGetter
, MediaResourceGetter
*());
18 MOCK_METHOD0(GetMediaUrlInterceptor
, MediaUrlInterceptor
*());
19 MOCK_METHOD3(OnTimeUpdate
,
21 base::TimeDelta current_timestamp
,
22 base::TimeTicks current_time_ticks
));
23 MOCK_METHOD5(OnMediaMetadataChanged
,
25 base::TimeDelta duration
,
29 MOCK_METHOD1(OnPlaybackComplete
, void(int player_id
));
30 MOCK_METHOD1(OnMediaInterrupted
, void(int player_id
));
31 MOCK_METHOD2(OnBufferingUpdate
, void(int player_id
, int percentage
));
32 MOCK_METHOD2(OnSeekComplete
,
33 void(int player_id
, const base::TimeDelta
& current_time
));
34 MOCK_METHOD2(OnError
, void(int player_id
, int error
));
35 MOCK_METHOD3(OnVideoSizeChanged
, void(int player_id
, int width
, int height
));
36 MOCK_METHOD2(OnAudibleStateChanged
, void(int player_id
, bool is_audible_now
));
37 MOCK_METHOD1(OnWaitingForDecryptionKey
, void(int player_id
));
38 MOCK_METHOD0(GetFullscreenPlayer
, MediaPlayerAndroid
*());
39 MOCK_METHOD1(GetPlayer
, MediaPlayerAndroid
*(int player_id
));
40 MOCK_METHOD1(RequestPlay
, bool(int player_id
));
42 void OnMediaResourcesRequested(int player_id
) {}
45 } // anonymous namespace
47 class MediaPlayerBridgeTest
: public testing::Test
{
49 MediaPlayerBridgeTest()
56 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested
,
57 base::Unretained(&manager_
)),
61 void SetCanSeekForward(bool can_seek_forward
) {
62 bridge_
.can_seek_forward_
= can_seek_forward
;
65 void SetCanSeekBackward(bool can_seek_backward
) {
66 bridge_
.can_seek_backward_
= can_seek_backward
;
69 bool SeekInternal(const base::TimeDelta
& current_time
, base::TimeDelta time
) {
70 return bridge_
.SeekInternal(current_time
, time
);
74 // A message loop needs to be instantiated in order for the test to run
76 base::MessageLoop message_loop_
;
77 MockMediaPlayerManager manager_
;
78 MediaPlayerBridge bridge_
;
80 DISALLOW_COPY_AND_ASSIGN(MediaPlayerBridgeTest
);
83 TEST_F(MediaPlayerBridgeTest
, PreventForwardSeekWhenItIsNotPossible
) {
84 // Simulate the Java MediaPlayerBridge reporting that forward seeks are not
86 SetCanSeekForward(false);
87 SetCanSeekBackward(true);
89 // If this assertion fails, seeks will be allowed which will result in a
90 // crash because j_media_player_bridge_ cannot be properly instantiated
93 SeekInternal(base::TimeDelta(), base::TimeDelta::FromSeconds(10)));
96 TEST_F(MediaPlayerBridgeTest
, PreventBackwardSeekWhenItIsNotPossible
) {
97 // Simulate the Java MediaPlayerBridge reporting that backward seeks are not
99 SetCanSeekForward(true);
100 SetCanSeekBackward(false);
102 // If this assertion fails, seeks will be allowed which will result in a
103 // crash because j_media_player_bridge_ cannot be properly instantiated
106 SeekInternal(base::TimeDelta::FromSeconds(10), base::TimeDelta()));