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

Side by Side Diff: content/public/test/test_browser_thread_bundle.h

Issue 22799005: Flush the blocking pool in TestBrowserThreadBundle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added documentation Created 7 years, 4 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TestBrowserThreadBundle is a convenience class for creating a set of 5 // TestBrowserThreadBundle is a convenience class for creating a set of
6 // TestBrowserThreads in unit tests. For most tests, it is sufficient to 6 // TestBrowserThreads in unit tests. For most tests, it is sufficient to
7 // just instantiate the TestBrowserThreadBundle as a member variable. 7 // just instantiate the TestBrowserThreadBundle as a member variable.
8 // 8 //
9 // By default, all of the created TestBrowserThreads will be backed by a single 9 // By default, all of the created TestBrowserThreads will be backed by a single
10 // shared MessageLoop. If a test truly needs separate threads, it can do 10 // shared MessageLoop. If a test truly needs separate threads, it can do
11 // so by passing the appropriate combination of RealThreadsMask values during 11 // so by passing the appropriate combination of RealThreadsMask values during
12 // the TestBrowserThreadBundle construction. 12 // the TestBrowserThreadBundle construction.
13 // 13 //
14 // The TestBrowserThreadBundle will attempt to drain the MessageLoop on 14 // The TestBrowserThreadBundle will attempt to drain the MessageLoop on
15 // destruction. Sometimes a test needs to drain currently enqueued tasks 15 // destruction. Sometimes a test needs to drain currently enqueued tasks
16 // mid-test. Browser tests should call content::RunAllPendingInMessageLoop(). 16 // mid-test. Browser tests should call content::RunAllPendingInMessageLoop().
17 // Unit tests should use base::RunLoop (e.g., base::RunLoop().RunUntilIdle()). 17 // Unit tests should use base::RunLoop (e.g., base::RunLoop().RunUntilIdle()).
18 // TODO(phajdan.jr): Revise this comment after switch to Aura. 18 // TODO(phajdan.jr): Revise this comment after switch to Aura.
19 // 19 //
20 // The TestBrowserThreadBundle will also flush the blocking pool on destruction.
21 // We do this to avoid memory leaks, particularly in the case of threads posting
22 // tasks to the blocking pool via PostTaskAndReply. By ensuring that the tasks
23 // are run while the originating TestBroswserThreads still exist, we prevent
24 // leakage of PostTaskAndReplyRelay objects. We also flush the blocking pool
25 // again at the point where it would normally be shut down, to better simulate
26 // the normal thread shutdown process.
27 //
20 // Some tests using the IO thread expect a MessageLoopForIO. Passing 28 // Some tests using the IO thread expect a MessageLoopForIO. Passing
21 // IO_MAINLOOP will use a MessageLoopForIO for the main MessageLoop. 29 // IO_MAINLOOP will use a MessageLoopForIO for the main MessageLoop.
22 // Most of the time, this avoids needing to use a REAL_IO_THREAD. 30 // Most of the time, this avoids needing to use a REAL_IO_THREAD.
23 31
24 #ifndef CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ 32 #ifndef CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_
25 #define CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ 33 #define CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_
26 34
27 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
28 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
29 37
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 scoped_ptr<TestBrowserThread> process_launcher_thread_; 75 scoped_ptr<TestBrowserThread> process_launcher_thread_;
68 scoped_ptr<TestBrowserThread> cache_thread_; 76 scoped_ptr<TestBrowserThread> cache_thread_;
69 scoped_ptr<TestBrowserThread> io_thread_; 77 scoped_ptr<TestBrowserThread> io_thread_;
70 78
71 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle); 79 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle);
72 }; 80 };
73 81
74 } // namespace content 82 } // namespace content
75 83
76 #endif /* CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ */ 84 #endif /* CONTENT_PUBLIC_TEST_TEST_BROWSER_THREAD_TEST_BUNDLE_H_ */
OLDNEW
« no previous file with comments | « content/browser/browser_thread_impl.h ('k') | content/public/test/test_browser_thread_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698