cc: Remove tile and scale specific code from raster source
[chromium-blink-merge.git] / media / base / test_helpers.h
blob3401a09bdb01a3b140b4aeb7a66ac4fce72ac53e
1 // Copyright (c) 2012 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 #ifndef MEDIA_BASE_TEST_HELPERS_H_
6 #define MEDIA_BASE_TEST_HELPERS_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "media/base/channel_layout.h"
11 #include "media/base/pipeline_status.h"
12 #include "media/base/sample_format.h"
13 #include "media/base/video_decoder_config.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "ui/gfx/geometry/size.h"
17 namespace base {
18 class MessageLoop;
19 class TimeDelta;
22 namespace media {
24 class AudioBuffer;
25 class DecoderBuffer;
27 // Return a callback that expects to be run once.
28 base::Closure NewExpectedClosure();
29 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status);
31 // Helper class for running a message loop until a callback has run. Useful for
32 // testing classes that run on more than a single thread.
34 // Events are intended for single use and cannot be reset.
35 class WaitableMessageLoopEvent {
36 public:
37 WaitableMessageLoopEvent();
38 ~WaitableMessageLoopEvent();
40 // Returns a thread-safe closure that will signal |this| when executed.
41 base::Closure GetClosure();
42 PipelineStatusCB GetPipelineStatusCB();
44 // Runs the current message loop until |this| has been signaled.
46 // Fails the test if the timeout is reached.
47 void RunAndWait();
49 // Runs the current message loop until |this| has been signaled and asserts
50 // that the |expected| status was received.
52 // Fails the test if the timeout is reached.
53 void RunAndWaitForStatus(PipelineStatus expected);
55 private:
56 void OnCallback(PipelineStatus status);
57 void OnTimeout();
59 base::MessageLoop* message_loop_;
60 bool signaled_;
61 PipelineStatus status_;
63 DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent);
66 // Provides pre-canned VideoDecoderConfig. These types are used for tests that
67 // don't care about detailed parameters of the config.
68 class TestVideoConfig {
69 public:
70 // Returns a configuration that is invalid.
71 static VideoDecoderConfig Invalid();
73 static VideoDecoderConfig Normal();
74 static VideoDecoderConfig NormalEncrypted();
76 // Returns a configuration that is larger in dimensions than Normal().
77 static VideoDecoderConfig Large();
78 static VideoDecoderConfig LargeEncrypted();
80 // Returns coded size for Normal and Large config.
81 static gfx::Size NormalCodedSize();
82 static gfx::Size LargeCodedSize();
84 private:
85 DISALLOW_IMPLICIT_CONSTRUCTORS(TestVideoConfig);
88 // Create an AudioBuffer containing |frames| frames of data, where each sample
89 // is of type T. |start| and |increment| are used to specify the values for the
90 // samples, which are created in channel order. The value for frame and channel
91 // is determined by:
93 // |start| + |channel| * |frames| * |increment| + index * |increment|
95 // E.g., for a stereo buffer the values in channel 0 will be:
96 // start
97 // start + increment
98 // start + 2 * increment, ...
100 // While, values in channel 1 will be:
101 // start + frames * increment
102 // start + (frames + 1) * increment
103 // start + (frames + 2) * increment, ...
105 // |start_time| will be used as the start time for the samples.
106 template <class T>
107 scoped_refptr<AudioBuffer> MakeAudioBuffer(SampleFormat format,
108 ChannelLayout channel_layout,
109 size_t channel_count,
110 int sample_rate,
111 T start,
112 T increment,
113 size_t frames,
114 base::TimeDelta timestamp);
116 // Create a fake video DecoderBuffer for testing purpose. The buffer contains
117 // part of video decoder config info embedded so that the testing code can do
118 // some sanity check.
119 scoped_refptr<DecoderBuffer> CreateFakeVideoBufferForTest(
120 const VideoDecoderConfig& config,
121 base::TimeDelta timestamp,
122 base::TimeDelta duration);
124 // Verify if a fake video DecoderBuffer is valid.
125 bool VerifyFakeVideoBufferForTest(const scoped_refptr<DecoderBuffer>& buffer,
126 const VideoDecoderConfig& config);
128 // Used to verify that the each call to A() is followed by a call to B(),
129 // before the next call to A(). There may be any number of pairs (including 0).
130 class CallbackPairChecker {
131 public:
132 CallbackPairChecker();
133 ~CallbackPairChecker();
134 void RecordACalled();
135 void RecordBCalled();
137 private:
138 bool expecting_b_;
141 } // namespace media
143 #endif // MEDIA_BASE_TEST_HELPERS_H_