test_browser_thread.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_H_
6#define CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_H_
7
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "content/public/browser/browser_thread.h"
11
12class MessageLoop;
13
14namespace base {
15class Thread;
16}
17
18namespace content {
19
20class TestBrowserThreadImpl;
21
22// A BrowserThread for unit tests; this lets unit tests in chrome/ create
23// BrowserThread instances.
24class TestBrowserThread {
25 public:
26  explicit TestBrowserThread(BrowserThread::ID identifier);
27  TestBrowserThread(BrowserThread::ID identifier, MessageLoop* message_loop);
28  ~TestBrowserThread();
29
30  // We provide a subset of the capabilities of the Thread interface
31  // to enable certain unit tests.  To avoid a stronger dependency of
32  // the internals of BrowserThread, we do not provide the full Thread
33  // interface.
34
35  // Starts the thread with a generic message loop.
36  bool Start();
37
38  // Starts the thread with an IOThread message loop.
39  bool StartIOThread();
40
41  // Stops the thread.
42  void Stop();
43
44  // Returns true if the thread is running.
45  bool IsRunning();
46
47  // Returns a Thread pointer for the thread. This should not be used
48  // in new tests.
49  base::Thread* DeprecatedGetThreadObject();
50
51 private:
52  scoped_ptr<TestBrowserThreadImpl> impl_;
53
54  DISALLOW_COPY_AND_ASSIGN(TestBrowserThread);
55};
56
57}  // namespace content
58
59#endif  // CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_H_
60