Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / base / android / media_player_bridge_unittest.cc
blob73e30dd2e9154220804ba5f000b69bde37bacb46
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"
11 namespace media {
13 namespace {
15 class MockMediaPlayerManager : public MediaPlayerManager {
16 public:
17 MOCK_METHOD0(GetMediaResourceGetter, MediaResourceGetter*());
18 MOCK_METHOD0(GetMediaUrlInterceptor, MediaUrlInterceptor*());
19 MOCK_METHOD3(OnTimeUpdate,
20 void(int player_id,
21 base::TimeDelta current_timestamp,
22 base::TimeTicks current_time_ticks));
23 MOCK_METHOD5(OnMediaMetadataChanged,
24 void(int player_id,
25 base::TimeDelta duration,
26 int width,
27 int height,
28 bool success));
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 {
48 public:
49 MediaPlayerBridgeTest()
50 : bridge_(0,
51 GURL(),
52 GURL(),
53 "",
54 false,
55 &manager_,
56 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested,
57 base::Unretained(&manager_)),
58 GURL(),
59 false) {}
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);
73 private:
74 // A message loop needs to be instantiated in order for the test to run
75 // properly.
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
85 // possible
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
91 // during this test.
92 ASSERT_FALSE(
93 SeekInternal(base::TimeDelta(), base::TimeDelta::FromSeconds(10)));
96 TEST_F(MediaPlayerBridgeTest, PreventBackwardSeekWhenItIsNotPossible) {
97 // Simulate the Java MediaPlayerBridge reporting that backward seeks are not
98 // possible
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
104 // during this test.
105 ASSERT_FALSE(
106 SeekInternal(base::TimeDelta::FromSeconds(10), base::TimeDelta()));
109 } // namespace media