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

Side by Side Diff: media/base/test_helpers.h

Issue 2076423004: Remove calls to MessageLoop::current() in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review Created 4 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_TEST_HELPERS_H_ 5 #ifndef MEDIA_BASE_TEST_HELPERS_H_
6 #define MEDIA_BASE_TEST_HELPERS_H_ 6 #define MEDIA_BASE_TEST_HELPERS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/non_thread_safe.h"
13 #include "media/base/audio_parameters.h" 15 #include "media/base/audio_parameters.h"
14 #include "media/base/channel_layout.h" 16 #include "media/base/channel_layout.h"
15 #include "media/base/media_log.h" 17 #include "media/base/media_log.h"
16 #include "media/base/pipeline_status.h" 18 #include "media/base/pipeline_status.h"
17 #include "media/base/sample_format.h" 19 #include "media/base/sample_format.h"
18 #include "media/base/video_decoder_config.h" 20 #include "media/base/video_decoder_config.h"
19 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
21 23
22 namespace base { 24 namespace base {
23 class MessageLoop;
24 class RunLoop; 25 class RunLoop;
25 class TimeDelta; 26 class TimeDelta;
26 } 27 }
27 28
28 namespace media { 29 namespace media {
29 30
30 class AudioBuffer; 31 class AudioBuffer;
31 class DecoderBuffer; 32 class DecoderBuffer;
32 33
33 // Return a callback that expects to be run once. 34 // Return a callback that expects to be run once.
34 base::Closure NewExpectedClosure(); 35 base::Closure NewExpectedClosure();
35 base::Callback<void(bool)> NewExpectedBoolCB(bool success); 36 base::Callback<void(bool)> NewExpectedBoolCB(bool success);
36 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status); 37 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status);
37 38
38 // Helper class for running a message loop until a callback has run. Useful for 39 // Helper class for running a message loop until a callback has run. Useful for
39 // testing classes that run on more than a single thread. 40 // testing classes that run on more than a single thread.
40 // 41 //
41 // Events are intended for single use and cannot be reset. 42 // Events are intended for single use and cannot be reset.
42 class WaitableMessageLoopEvent { 43 class WaitableMessageLoopEvent : public base::NonThreadSafe {
43 public: 44 public:
44 WaitableMessageLoopEvent(); 45 WaitableMessageLoopEvent();
45 explicit WaitableMessageLoopEvent(base::TimeDelta timeout); 46 explicit WaitableMessageLoopEvent(base::TimeDelta timeout);
46 ~WaitableMessageLoopEvent(); 47 ~WaitableMessageLoopEvent();
47 48
48 // Returns a thread-safe closure that will signal |this| when executed. 49 // Returns a thread-safe closure that will signal |this| when executed.
49 base::Closure GetClosure(); 50 base::Closure GetClosure();
50 PipelineStatusCB GetPipelineStatusCB(); 51 PipelineStatusCB GetPipelineStatusCB();
51 52
52 // Runs the current message loop until |this| has been signaled. 53 // Runs the current message loop until |this| has been signaled.
53 // 54 //
54 // Fails the test if the timeout is reached. 55 // Fails the test if the timeout is reached.
55 void RunAndWait(); 56 void RunAndWait();
56 57
57 // Runs the current message loop until |this| has been signaled and asserts 58 // Runs the current message loop until |this| has been signaled and asserts
58 // that the |expected| status was received. 59 // that the |expected| status was received.
59 // 60 //
60 // Fails the test if the timeout is reached. 61 // Fails the test if the timeout is reached.
61 void RunAndWaitForStatus(PipelineStatus expected); 62 void RunAndWaitForStatus(PipelineStatus expected);
62 63
63 bool is_signaled() const { return signaled_; } 64 bool is_signaled() const { return signaled_; }
64 65
65 private: 66 private:
66 void OnCallback(PipelineStatus status); 67 void OnCallback(PipelineStatus status);
67 void OnTimeout(); 68 void OnTimeout();
68 69
69 base::MessageLoop* message_loop_;
70 bool signaled_; 70 bool signaled_;
71 PipelineStatus status_; 71 PipelineStatus status_;
72 std::unique_ptr<base::RunLoop> run_loop_; 72 std::unique_ptr<base::RunLoop> run_loop_;
73 const base::TimeDelta timeout_; 73 const base::TimeDelta timeout_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent); 75 DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent);
76 }; 76 };
77 77
78 // Provides pre-canned VideoDecoderConfig. These types are used for tests that 78 // Provides pre-canned VideoDecoderConfig. These types are used for tests that
79 // don't care about detailed parameters of the config. 79 // don't care about detailed parameters of the config.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 base::TimeDelta timestamp, 142 base::TimeDelta timestamp,
143 base::TimeDelta duration); 143 base::TimeDelta duration);
144 144
145 // Verify if a fake video DecoderBuffer is valid. 145 // Verify if a fake video DecoderBuffer is valid.
146 bool VerifyFakeVideoBufferForTest(const scoped_refptr<DecoderBuffer>& buffer, 146 bool VerifyFakeVideoBufferForTest(const scoped_refptr<DecoderBuffer>& buffer,
147 const VideoDecoderConfig& config); 147 const VideoDecoderConfig& config);
148 148
149 } // namespace media 149 } // namespace media
150 150
151 #endif // MEDIA_BASE_TEST_HELPERS_H_ 151 #endif // MEDIA_BASE_TEST_HELPERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698