| Index: content/public/test/test_browser_thread_bundle.h
|
| diff --git a/content/public/test/test_browser_thread_bundle.h b/content/public/test/test_browser_thread_bundle.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..31927fe2e3d478857138289cd237452a9c79e205
|
| --- /dev/null
|
| +++ b/content/public/test/test_browser_thread_bundle.h
|
| @@ -0,0 +1,75 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// TestBrowserThreadBundle is a convenience class for creating a set of
|
| +// TestBrowserThreads in unit tests. For most tests, it is sufficient to
|
| +// just instantiate the TestBrowserThreadBundle as a member variable.
|
| +//
|
| +// By default, each of the created TestBrowserThreads will be backed by
|
| +// all of the created TestBrowserThreads will be backed by a single
|
| +// shared MessageLoop. If a test truly needs separate threads, it can do
|
| +// so by passing the apprpriate combination of RealThreadsMask values during
|
| +// the TestBrowserThreadBundle construction.
|
| +//
|
| +// The TestBrowserThreadBundle will attempt to drain the MessageLoop on
|
| +// destruction. If a test needs to drain currently enqueued tasks, the best
|
| +// pattern is to instantiate base::RunLoop and call the appropriate methods
|
| +// the RunLoop (eg., base::RunLoop().RunUntilIdle()). Very rarely should a
|
| +// test talk directly to the underlying MessageLoop.
|
| +//
|
| +// Some tests using the IO thread expect a MessageLoopForIO. Currently, the
|
| +// best workaround is to create a REAL_IO_THREAD to get the appropriate mesasge
|
| +// loop. This class could conceivably create a MessageLoopForIO instead of
|
| +// a MessageLoopForUI as the main loop, but there are not enough cases to
|
| +// make it work the API complexity.
|
| +
|
| +#ifndef BROWSER_THREAD_TEST_BUNDLE_H_
|
| +#define BROWSER_THREAD_TEST_BUNDLE_H_
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "content/public/test/test_browser_thread.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace content {
|
| +
|
| +class TestBrowserThreadBundle {
|
| + public:
|
| + // Used to specifying which named BrowserThreads should be backed by a real
|
| + // thread rather than main main thread. The UI thread is always the main
|
| + // thread in a unit test so it is left out of this enum.
|
| + enum RealThreadsMask {
|
| + NO_REAL_THREAD = 0x0,
|
| + REAL_DB_THREAD = 0x01,
|
| + REAL_FILE_THREAD = 0x2,
|
| + REAL_FILE_USER_BLOCKING_THREAD = 0x4,
|
| + REAL_IO_THREAD = 0x8
|
| + };
|
| +
|
| + TestBrowserThreadBundle();
|
| + explicit TestBrowserThreadBundle(int real_threads_mask);
|
| +
|
| + ~TestBrowserThreadBundle();
|
| +
|
| + TestBrowserThread* ui_thread() { return &ui_thread_; }
|
| + TestBrowserThread* db_thread() { return &db_thread_; }
|
| + TestBrowserThread* file_thread() { return &file_thread_; }
|
| + TestBrowserThread* file_user_blocking_thread() {
|
| + return &file_user_blocking_thread_;
|
| + }
|
| + TestBrowserThread* io_thread() { return &io_thread_; }
|
| +
|
| + private:
|
| + MessageLoopForUI message_loop_;
|
| + TestBrowserThread ui_thread_;
|
| + TestBrowserThread db_thread_;
|
| + TestBrowserThread file_thread_;
|
| + TestBrowserThread file_user_blocking_thread_;
|
| + TestBrowserThread io_thread_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif /* BROWSER_THREAD_TEST_BUNDLE_H_ */
|
|
|