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

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: Fix DEPS 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 unified diff | Download patch
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/memory/scoped_ptr.h"
34
35 namespace web {
36
37 class TestWebThreadBundleImpl;
38
39 class TestWebThreadBundle {
40 public:
41 // Used to specify the type of MessageLoop that backs the UI thread, and
42 // which of the named WebThreads should be backed by a real
43 // threads. The UI thread is always the main thread in a unit test.
44 enum Options {
45 DEFAULT = 0x00,
46 IO_MAINLOOP = 0x01,
47 REAL_DB_THREAD = 0x02,
48 REAL_FILE_THREAD = 0x08,
49 REAL_FILE_USER_BLOCKING_THREAD = 0x10,
50 REAL_CACHE_THREAD = 0x20,
51 REAL_IO_THREAD = 0x40,
52 };
53
54 TestWebThreadBundle();
55 explicit TestWebThreadBundle(int options);
56
57 ~TestWebThreadBundle();
58
59 private:
60 scoped_ptr<TestWebThreadBundleImpl> impl_;
61
62 DISALLOW_COPY_AND_ASSIGN(TestWebThreadBundle);
63 };
64
65 } // namespace web
66
67 #endif // IOS_WEB_PUBLIC_TEST_TEST_WEB_THREAD_BUNDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698