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

Side by Side 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: merge to head, address jyasskin's comments. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 // TestBrowserThreadBundle is a convenience class for creating a set of
6 // TestBrowserThreads in unit tests. For most tests, it is sufficient to
7 // just instantiate the TestBrowserThreadBundle as a member variable.
8 //
9 // By default, each of the created TestBrowserThreads will be backed by
10 // all of the created TestBrowserThreads will be backed by a single
jam 2013/05/31 17:29:25 nit: fix comment
awong 2013/05/31 20:57:17 Done.
11 // shared MessageLoop. If a test truly needs separate threads, it can do
12 // so by passing the apprpriate combination of RealThreadsMask values during
jam 2013/05/31 17:29:25 nit: spelling
awong 2013/05/31 20:57:17 Done.
13 // the TestBrowserThreadBundle construction.
14 //
15 // The TestBrowserThreadBundle will attempt to drain the MessageLoop on
16 // destruction. If a test needs to drain currently enqueued tasks, the best
17 // pattern is to instantiate base::RunLoop and call the appropriate methods
18 // the RunLoop (eg., base::RunLoop().RunUntilIdle()). Very rarely should a
jam 2013/05/31 17:29:25 can you elaborate more on this? my first impressio
awong 2013/05/31 20:57:17 Hmm...I added this to try and get more defined beh
Jeffrey Yasskin 2013/05/31 21:11:33 To elaborate a bit more about the non-destruction
jam 2013/05/31 22:53:04 I think if someone changes code such that posting
awong 2013/06/05 00:18:48 I've updated the comment to also reference content
19 // test talk directly to the underlying MessageLoop.
20 //
21 // Some tests using the IO thread expect a MessageLoopForIO. Currently, the
22 // best workaround is to create a REAL_IO_THREAD to get the appropriate mesasge
23 // loop. This class could conceivably create a MessageLoopForIO instead of
24 // a MessageLoopForUI as the main loop, but there are not enough cases to
25 // make it work the API complexity.
26
27 #ifndef BROWSER_THREAD_TEST_BUNDLE_H_
jam 2013/05/31 17:29:25 nit: fix guard (i.e. add CONTENT_PUBLIC_TEST_)
awong 2013/05/31 20:57:17 Done.
28 #define BROWSER_THREAD_TEST_BUNDLE_H_
29
30 #include "base/message_loop.h"
31 #include "content/public/test/test_browser_thread.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33
34 namespace content {
35
36 class TestBrowserThreadBundle {
37 public:
38 // Used to specifying which named BrowserThreads should be backed by a real
39 // thread rather than main main thread. The UI thread is always the main
40 // thread in a unit test so it is left out of this enum.
41 enum RealThreadsMask {
42 NO_REAL_THREAD = 0x0,
jam 2013/05/31 17:29:25 nit: i believe you're adding this for the convenie
awong 2013/05/31 20:57:17 I could removed this enum and add a DCHECK for a m
jam 2013/05/31 22:53:04 ok, since this is personal style, I'll defer to yo
43 REAL_DB_THREAD = 0x01,
44 REAL_FILE_THREAD = 0x2,
45 REAL_FILE_USER_BLOCKING_THREAD = 0x4,
46 REAL_IO_THREAD = 0x8
47 };
48
49 TestBrowserThreadBundle();
50 explicit TestBrowserThreadBundle(int real_threads_mask);
51
52 ~TestBrowserThreadBundle();
53
54 TestBrowserThread* ui_thread() { return &ui_thread_; }
55 TestBrowserThread* db_thread() { return &db_thread_; }
56 TestBrowserThread* file_thread() { return &file_thread_; }
57 TestBrowserThread* file_user_blocking_thread() {
58 return &file_user_blocking_thread_;
59 }
60 TestBrowserThread* io_thread() { return &io_thread_; }
61
62 private:
63 MessageLoopForUI message_loop_;
64 TestBrowserThread ui_thread_;
65 TestBrowserThread db_thread_;
66 TestBrowserThread file_thread_;
67 TestBrowserThread file_user_blocking_thread_;
68 TestBrowserThread io_thread_;
69
70 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle);
71 };
72
73 } // namespace content
74
75 #endif /* BROWSER_THREAD_TEST_BUNDLE_H_ */
jam 2013/05/31 17:29:25 nit: please follow the convention for this line
awong 2013/05/31 20:57:17 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698