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 12namespace base { 13class MessageLoop; 14class Thread; 15} 16 17namespace content { 18 19class TestBrowserThreadImpl; 20 21// A BrowserThread for unit tests; this lets unit tests in chrome/ create 22// BrowserThread instances. 23class TestBrowserThread { 24 public: 25 explicit TestBrowserThread(BrowserThread::ID identifier); 26 TestBrowserThread(BrowserThread::ID identifier, 27 base::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