Let MetricsService know about some Android Activities
[chromium-blink-merge.git] / base / test / thread_test_helper.h
blob9521de60bfa774affd31ce3f3f478e21860c120c
1 // Copyright (c) 2011 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 BASE_TEST_THREAD_TEST_HELPER_H_
6 #define BASE_TEST_THREAD_TEST_HELPER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/synchronization/waitable_event.h"
13 namespace base {
15 // Helper class that executes code on a given thread while blocking on the
16 // invoking thread. To use, derive from this class and overwrite RunTest. An
17 // alternative use of this class is to use it directly. It will then block
18 // until all pending tasks on a given thread have been executed.
19 class ThreadTestHelper : public RefCountedThreadSafe<ThreadTestHelper> {
20 public:
21 explicit ThreadTestHelper(MessageLoopProxy* target_thread);
23 // True if RunTest() was successfully executed on the target thread.
24 bool Run() WARN_UNUSED_RESULT;
26 virtual void RunTest();
28 protected:
29 friend class RefCountedThreadSafe<ThreadTestHelper>;
31 virtual ~ThreadTestHelper();
33 // Use this method to store the result of RunTest().
34 void set_test_result(bool test_result) { test_result_ = test_result; }
36 private:
37 void RunInThread();
39 bool test_result_;
40 scoped_refptr<MessageLoopProxy> target_thread_;
41 WaitableEvent done_event_;
43 DISALLOW_COPY_AND_ASSIGN(ThreadTestHelper);
46 } // namespace base
48 #endif // BASE_TEST_THREAD_TEST_HELPER_H_