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

Side by Side 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 5 years, 12 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
6 #define IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
7
8 // TestWebThreadBundle is a convenience class for creating a set of
9 // TestWebThreads in unit tests. For most tests, it is sufficient to
10 // just instantiate the TestWebThreadBundle as a member variable.
11 //
12 // By default, all of the created TestWebThreads will be backed by a single
13 // shared MessageLoop. If a test truly needs separate threads, it can do
14 // so by passing the appropriate combination of RealThreadsMask values during
15 // the TestWebThreadBundle construction.
16 //
17 // The TestWebThreadBundle will attempt to drain the MessageLoop on
18 // destruction. Sometimes a test needs to drain currently enqueued tasks
19 // mid-test.
20 //
21 // The TestWebThreadBundle will also flush the blocking pool on destruction.
22 // We do this to avoid memory leaks, particularly in the case of threads posting
23 // tasks to the blocking pool via PostTaskAndReply. By ensuring that the tasks
24 // are run while the originating TestBroswserThreads still exist, we prevent
25 // leakage of PostTaskAndReplyRelay objects. We also flush the blocking pool
26 // again at the point where it would normally be shut down, to better simulate
27 // the normal thread shutdown process.
28 //
29 // Some tests using the IO thread expect a MessageLoopForIO. Passing
30 // IO_MAINLOOP will use a MessageLoopForIO for the main MessageLoop.
31 // Most of the time, this avoids needing to use a REAL_IO_THREAD.
32
33 #include "base/macros.h"
34 #include "base/memory/scoped_ptr.h"
35
36 namespace web {
37
38 class TestWebThreadBundleImpl;
39
40 class TestWebThreadBundle {
41 public:
42 // Used to specify the type of MessageLoop that backs the UI thread, and
43 // which of the named WebThreads should be backed by a real
44 // threads. The UI thread is always the main thread in a unit test.
45 enum Options {
46 DEFAULT = 0x00,
47 IO_MAINLOOP = 0x01,
48 REAL_DB_THREAD = 0x02,
49 REAL_FILE_THREAD = 0x08,
50 REAL_FILE_USER_BLOCKING_THREAD = 0x10,
51 REAL_CACHE_THREAD = 0x20,
52 REAL_IO_THREAD = 0x40,
53 };
54
55 TestWebThreadBundle();
56 explicit TestWebThreadBundle(int options);
57
58 ~TestWebThreadBundle();
59
60 private:
61 scoped_ptr<TestWebThreadBundleImpl> impl_;
62
63 DISALLOW_COPY_AND_ASSIGN(TestWebThreadBundle);
64 };
65
66 } // namespace web
67
68 #endif // IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
OLDNEW
« 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