Chromium Code Reviews| Index: content/public/test/test_browser_thread_bundle.h |
| diff --git a/content/public/test/test_browser_thread_bundle.h b/content/public/test/test_browser_thread_bundle.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..31927fe2e3d478857138289cd237452a9c79e205 |
| --- /dev/null |
| +++ b/content/public/test/test_browser_thread_bundle.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright (c) 2013 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. |
| + |
| +// TestBrowserThreadBundle is a convenience class for creating a set of |
| +// TestBrowserThreads in unit tests. For most tests, it is sufficient to |
| +// just instantiate the TestBrowserThreadBundle as a member variable. |
| +// |
| +// By default, each of the created TestBrowserThreads will be backed by |
| +// 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.
|
| +// shared MessageLoop. If a test truly needs separate threads, it can do |
| +// 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.
|
| +// the TestBrowserThreadBundle construction. |
| +// |
| +// The TestBrowserThreadBundle will attempt to drain the MessageLoop on |
| +// destruction. If a test needs to drain currently enqueued tasks, the best |
| +// pattern is to instantiate base::RunLoop and call the appropriate methods |
| +// 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
|
| +// test talk directly to the underlying MessageLoop. |
| +// |
| +// Some tests using the IO thread expect a MessageLoopForIO. Currently, the |
| +// best workaround is to create a REAL_IO_THREAD to get the appropriate mesasge |
| +// loop. This class could conceivably create a MessageLoopForIO instead of |
| +// a MessageLoopForUI as the main loop, but there are not enough cases to |
| +// make it work the API complexity. |
| + |
| +#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.
|
| +#define BROWSER_THREAD_TEST_BUNDLE_H_ |
| + |
| +#include "base/message_loop.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace content { |
| + |
| +class TestBrowserThreadBundle { |
| + public: |
| + // Used to specifying which named BrowserThreads should be backed by a real |
| + // thread rather than main main thread. The UI thread is always the main |
| + // thread in a unit test so it is left out of this enum. |
| + enum RealThreadsMask { |
| + 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
|
| + REAL_DB_THREAD = 0x01, |
| + REAL_FILE_THREAD = 0x2, |
| + REAL_FILE_USER_BLOCKING_THREAD = 0x4, |
| + REAL_IO_THREAD = 0x8 |
| + }; |
| + |
| + TestBrowserThreadBundle(); |
| + explicit TestBrowserThreadBundle(int real_threads_mask); |
| + |
| + ~TestBrowserThreadBundle(); |
| + |
| + TestBrowserThread* ui_thread() { return &ui_thread_; } |
| + TestBrowserThread* db_thread() { return &db_thread_; } |
| + TestBrowserThread* file_thread() { return &file_thread_; } |
| + TestBrowserThread* file_user_blocking_thread() { |
| + return &file_user_blocking_thread_; |
| + } |
| + TestBrowserThread* io_thread() { return &io_thread_; } |
| + |
| + private: |
| + MessageLoopForUI message_loop_; |
| + TestBrowserThread ui_thread_; |
| + TestBrowserThread db_thread_; |
| + TestBrowserThread file_thread_; |
| + TestBrowserThread file_user_blocking_thread_; |
| + TestBrowserThread io_thread_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#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.
|