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

Unified Diff: ios/web/public/test/test_web_thread_bundle.h

Issue 814533002: Introduce web::TestWebThreadBundle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@includes
Patch Set: Address comments Created 6 years 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 | « ios/web/ios_web.gyp ('k') | ios/web/test/test_web_thread_bundle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/public/test/test_web_thread_bundle.h
diff --git a/ios/web/public/test/test_web_thread_bundle.h b/ios/web/public/test/test_web_thread_bundle.h
new file mode 100644
index 0000000000000000000000000000000000000000..425cc51b1303d8b71ce04dff2ff45e0d46c4ce6a
--- /dev/null
+++ b/ios/web/public/test/test_web_thread_bundle.h
@@ -0,0 +1,68 @@
+// Copyright 2014 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.
+
+#ifndef IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
+#define IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
+
+// TestWebThreadBundle is a convenience class for creating a set of
+// TestWebThreads in unit tests. For most tests, it is sufficient to
+// just instantiate the TestWebThreadBundle as a member variable.
+//
+// By default, all of the created TestWebThreads 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 TestWebThreadBundle construction.
+//
+// The TestWebThreadBundle will attempt to drain the MessageLoop on
+// destruction. Sometimes a test needs to drain currently enqueued tasks
+// mid-test.
+//
+// The TestWebThreadBundle will also flush the blocking pool on destruction.
+// We do this to avoid memory leaks, particularly in the case of threads posting
+// tasks to the blocking pool via PostTaskAndReply. By ensuring that the tasks
+// are run while the originating TestBroswserThreads still exist, we prevent
+// leakage of PostTaskAndReplyRelay objects. We also flush the blocking pool
+// again at the point where it would normally be shut down, to better simulate
+// the normal thread shutdown process.
+//
+// Some tests using the IO thread expect a MessageLoopForIO. Passing
+// IO_MAINLOOP will use a MessageLoopForIO for the main MessageLoop.
+// Most of the time, this avoids needing to use a REAL_IO_THREAD.
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace web {
+
+class TestWebThreadBundleImpl;
+
+class TestWebThreadBundle {
+ public:
+ // Used to specify the type of MessageLoop that backs the UI thread, and
+ // which of the named WebThreads 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_FILE_THREAD = 0x08,
+ REAL_FILE_USER_BLOCKING_THREAD = 0x10,
+ REAL_CACHE_THREAD = 0x20,
+ REAL_IO_THREAD = 0x40,
+ };
+
+ TestWebThreadBundle();
+ explicit TestWebThreadBundle(int options);
+
+ ~TestWebThreadBundle();
+
+ private:
+ scoped_ptr<TestWebThreadBundleImpl> impl_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWebThreadBundle);
+};
+
+} // namespace web
+
+#endif // IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
« no previous file with comments | « ios/web/ios_web.gyp ('k') | ios/web/test/test_web_thread_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698