Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Unified Diff: content/public/test/test_browser_thread_bundle.h

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile fixes. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/test/test_browser_thread_bundle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..30f9bda4b87781e218b7ed7676305d274bfcf629
--- /dev/null
+++ b/content/public/test/test_browser_thread_bundle.h
@@ -0,0 +1,77 @@
+// 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, 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 appropriate 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 mid-test,
+// it should call content::RunAllPendingInMessageLoop() or use base::RunLoop
+// (eg., base::RunLoop().RunUntilIdle()) as appropriate.
jam 2013/06/05 17:01:39 I think saying "as appropriate" won't be clear. i.
awong 2013/06/05 17:54:38 My confusion is as follows: - This CL uses base:
awong 2013/06/05 21:16:56 Comment amended say RunLoop for unit tests and con
+//
+// Some tests using the IO thread expect a MessageLoopForIO. Passing
+// USE_IO_LOOP_FOR_UI will use a MessageLoopForIO for the main MessageLoop.
+// Most of the time, this avoids needing to use a REAL_IO_THREAD.
+
+#ifndef CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_
+#define CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+class MessageLoop;
+} // namespace base
+
+namespace content {
+
+class TestBrowserThread;
+
+class TestBrowserThreadBundle {
+ public:
+ // Used to specify the type of MessageLoop that backs the UI thread, and
+ // which of the named BrowserThreads should be backed by a real
+ // threads. The UI thread is always the main thread in a unit test.
+ enum Options {
+ DEFAULT = 0x00,
+ IO_MAINLOOP = 0x01,
+ REAL_DB_THREAD = 0x02,
+ REAL_WEBKIT_DEPRECATED_THREAD = 0x04,
+ REAL_FILE_THREAD = 0x08,
+ REAL_FILE_USER_BLOCKING_THREAD = 0x10,
+ REAL_PROCESS_LAUNCHER_THREAD = 0x20,
+ REAL_CACHE_THREAD = 0x40,
+ REAL_IO_THREAD = 0x80,
+ };
+
+ TestBrowserThreadBundle();
+ explicit TestBrowserThreadBundle(int options);
+
+ ~TestBrowserThreadBundle();
+
+ private:
+ void Init(int options);
+
+ scoped_ptr<base::MessageLoop> message_loop_;
+ scoped_ptr<TestBrowserThread> ui_thread_;
+ scoped_ptr<TestBrowserThread> db_thread_;
+ scoped_ptr<TestBrowserThread> webkit_deprecated_thread_;
+ scoped_ptr<TestBrowserThread> file_thread_;
+ scoped_ptr<TestBrowserThread> file_user_blocking_thread_;
+ scoped_ptr<TestBrowserThread> process_launcher_thread_;
+ scoped_ptr<TestBrowserThread> cache_thread_;
+ scoped_ptr<TestBrowserThread> io_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle);
+};
+
+} // namespace content
+
+#endif /* CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ */
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/test/test_browser_thread_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698