OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef MEDIA_BASE_TEST_HELPERS_H_ |
| 6 #define MEDIA_BASE_TEST_HELPERS_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "media/base/pipeline_status.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 |
| 12 class MessageLoop; |
| 13 |
| 14 namespace media { |
| 15 |
| 16 // Return a callback that expects to be run once. |
| 17 base::Closure NewExpectedClosure(); |
| 18 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status); |
| 19 |
| 20 // Helper class for running a message loop until a callback has run. Useful for |
| 21 // testing classes that run on more than a single thread. |
| 22 // |
| 23 // Events are intended for single use and cannot be reset. |
| 24 class WaitableMessageLoopEvent { |
| 25 public: |
| 26 WaitableMessageLoopEvent(); |
| 27 ~WaitableMessageLoopEvent(); |
| 28 |
| 29 // Returns a thread-safe closure that will signal |this| when executed. |
| 30 base::Closure GetClosure(); |
| 31 PipelineStatusCB GetPipelineStatusCB(); |
| 32 |
| 33 // Runs the current message loop until |this| has been signaled. |
| 34 // |
| 35 // Fails the test if the timeout is reached. |
| 36 void RunAndWait(); |
| 37 |
| 38 // Runs the current message loop until |this| has been signaled and asserts |
| 39 // that the |expected| status was received. |
| 40 // |
| 41 // Fails the test if the timeout is reached. |
| 42 void RunAndWaitForStatus(PipelineStatus expected); |
| 43 |
| 44 private: |
| 45 void OnCallback(PipelineStatus status); |
| 46 void OnTimeout(); |
| 47 |
| 48 MessageLoop* message_loop_; |
| 49 bool signaled_; |
| 50 PipelineStatus status_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent); |
| 53 }; |
| 54 |
| 55 } // namespace media |
| 56 |
| 57 #endif // MEDIA_BASE_TEST_HELPERS_H_ |
OLD | NEW |