OLD | NEW |
(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 // one MessageLoop running on the instantiating thread. If a test truly |
| 11 // needs separate threads, it can do so by passing the apprpriate |
| 12 // combination of RealThreadsMask values during the TestBrowserThreadBundle |
| 13 // construction. |
| 14 // |
| 15 // The TestBrowserThreadBundle will attempt to drain the MessageLoop on |
| 16 // destruction. |
| 17 |
| 18 #ifndef BROWSER_THREAD_TEST_BUNDLE_H_ |
| 19 #define BROWSER_THREAD_TEST_BUNDLE_H_ |
| 20 |
| 21 #include "base/message_loop.h" |
| 22 #include "content/public/test/test_browser_thread.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 |
| 25 namespace content { |
| 26 |
| 27 class TestBrowserThreadBundle { |
| 28 public: |
| 29 // Used to specifying which named BrowserThreads should be backed by a real |
| 30 // thread rather than main main thread. The UI thread is always the main |
| 31 // thread in a unit test so it is left out of this enum. |
| 32 enum RealThreadsMask { |
| 33 NO_REAL_THREAD = 0x0, |
| 34 REAL_DB_THREAD = 0x01, |
| 35 REAL_FILE_THREAD = 0x2, |
| 36 REAL_FILE_USER_BLOCKING_THREAD = 0x4, |
| 37 REAL_IO_THREAD = 0x8 |
| 38 }; |
| 39 |
| 40 TestBrowserThreadBundle(); |
| 41 explicit TestBrowserThreadBundle(int real_threads_mask); |
| 42 |
| 43 ~TestBrowserThreadBundle(); |
| 44 |
| 45 TestBrowserThread* ui_thread() { return &ui_thread_; } |
| 46 TestBrowserThread* db_thread() { return &db_thread_; } |
| 47 TestBrowserThread* file_thread() { return &file_thread_; } |
| 48 TestBrowserThread* file_user_blocking_thread() { |
| 49 return &file_user_blocking_thread_; |
| 50 } |
| 51 TestBrowserThread* io_thread() { return &io_thread_; } |
| 52 |
| 53 private: |
| 54 MessageLoopForUI message_loop_; |
| 55 TestBrowserThread ui_thread_; |
| 56 TestBrowserThread db_thread_; |
| 57 TestBrowserThread file_thread_; |
| 58 TestBrowserThread file_user_blocking_thread_; |
| 59 TestBrowserThread io_thread_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle); |
| 62 }; |
| 63 |
| 64 } // namespace content |
| 65 |
| 66 #endif /* BROWSER_THREAD_TEST_BUNDLE_H_ */ |
OLD | NEW |