OLD | NEW |
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 #include "content/public/test/test_browser_thread_bundle.h" | 5 #include "content/public/test/test_browser_thread_bundle.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/task_scheduler/task_scheduler.h" | 11 #include "base/task_scheduler/task_scheduler.h" |
12 #include "base/test/scoped_async_task_scheduler.h" | 12 #include "base/test/scoped_async_task_scheduler.h" |
13 #include "base/threading/sequenced_worker_pool.h" | |
14 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread.h" |
17 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 TestBrowserThreadBundle::TestBrowserThreadBundle() | 20 TestBrowserThreadBundle::TestBrowserThreadBundle() |
22 : TestBrowserThreadBundle(DEFAULT) {} | 21 : TestBrowserThreadBundle(DEFAULT) {} |
23 | 22 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // by flushing we guarantee it will blow up). | 71 // by flushing we guarantee it will blow up). |
73 RunAllBlockingPoolTasksUntilIdle(); | 72 RunAllBlockingPoolTasksUntilIdle(); |
74 | 73 |
75 scoped_async_task_scheduler_.reset(); | 74 scoped_async_task_scheduler_.reset(); |
76 CHECK(base::MessageLoop::current()->IsIdleForTesting()); | 75 CHECK(base::MessageLoop::current()->IsIdleForTesting()); |
77 | 76 |
78 // |message_loop_| needs to explicitly go away before fake threads in order | 77 // |message_loop_| needs to explicitly go away before fake threads in order |
79 // for DestructionObservers hooked to |message_loop_| to be able to invoke | 78 // for DestructionObservers hooked to |message_loop_| to be able to invoke |
80 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). | 79 // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). |
81 message_loop_.reset(); | 80 message_loop_.reset(); |
82 | |
83 // Disable redirection of SequencedWorkerPools to TaskScheduler. This is | |
84 // required in order to reset global state so that tests following this one in | |
85 // this process can still manage their own SequencedWorkerPool without using | |
86 // TestBrowserThreadBundle. | |
87 base::SequencedWorkerPool::EnableForProcess(); | |
88 } | 81 } |
89 | 82 |
90 void TestBrowserThreadBundle::Init() { | 83 void TestBrowserThreadBundle::Init() { |
91 // Check that the UI thread hasn't already been initialized. This will fail if | 84 // Check that the UI thread hasn't already been initialized. This will fail if |
92 // multiple TestBrowserThreadBundles are initialized in the same scope. | 85 // multiple TestBrowserThreadBundles are initialized in the same scope. |
93 CHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI)); | 86 CHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
94 | 87 |
95 // Check for conflicting options can't have two IO threads. | 88 // Check for conflicting options can't have two IO threads. |
96 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); | 89 CHECK(!(options_ & IO_MAINLOOP) || !(options_ & REAL_IO_THREAD)); |
97 // There must be a thread to start to use DONT_CREATE_THREADS | 90 // There must be a thread to start to use DONT_CREATE_THREADS |
(...skipping 25 matching lines...) Expand all Loading... |
123 // TaskScheduler can sometimes be externally provided by a | 116 // TaskScheduler can sometimes be externally provided by a |
124 // base::test::ScopedTaskEnvironment in a parent fixture. In that case it's | 117 // base::test::ScopedTaskEnvironment in a parent fixture. In that case it's |
125 // expected to have provided the MessageLoop as well (in which case | 118 // expected to have provided the MessageLoop as well (in which case |
126 // |message_loop_| remains null in Init()). | 119 // |message_loop_| remains null in Init()). |
127 CHECK(!base::TaskScheduler::GetInstance() || !message_loop_); | 120 CHECK(!base::TaskScheduler::GetInstance() || !message_loop_); |
128 if (!base::TaskScheduler::GetInstance()) { | 121 if (!base::TaskScheduler::GetInstance()) { |
129 scoped_async_task_scheduler_ = | 122 scoped_async_task_scheduler_ = |
130 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); | 123 base::MakeUnique<base::test::ScopedAsyncTaskScheduler>(); |
131 } | 124 } |
132 | 125 |
133 // Enable redirection of SequencedWorkerPools to TaskScheduler. | |
134 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | |
135 | |
136 if (options_ & REAL_DB_THREAD) { | 126 if (options_ & REAL_DB_THREAD) { |
137 db_thread_ = base::MakeUnique<TestBrowserThread>(BrowserThread::DB); | 127 db_thread_ = base::MakeUnique<TestBrowserThread>(BrowserThread::DB); |
138 db_thread_->Start(); | 128 db_thread_->Start(); |
139 } else { | 129 } else { |
140 db_thread_ = base::MakeUnique<TestBrowserThread>( | 130 db_thread_ = base::MakeUnique<TestBrowserThread>( |
141 BrowserThread::DB, base::MessageLoop::current()); | 131 BrowserThread::DB, base::MessageLoop::current()); |
142 } | 132 } |
143 | 133 |
144 if (options_ & REAL_FILE_THREAD) { | 134 if (options_ & REAL_FILE_THREAD) { |
145 file_thread_ = base::MakeUnique<TestBrowserThread>(BrowserThread::FILE); | 135 file_thread_ = base::MakeUnique<TestBrowserThread>(BrowserThread::FILE); |
(...skipping 15 matching lines...) Expand all Loading... |
161 io_thread_->StartIOThread(); | 151 io_thread_->StartIOThread(); |
162 } else { | 152 } else { |
163 io_thread_ = base::MakeUnique<TestBrowserThread>( | 153 io_thread_ = base::MakeUnique<TestBrowserThread>( |
164 BrowserThread::IO, base::MessageLoop::current()); | 154 BrowserThread::IO, base::MessageLoop::current()); |
165 } | 155 } |
166 | 156 |
167 threads_created_ = true; | 157 threads_created_ = true; |
168 } | 158 } |
169 | 159 |
170 } // namespace content | 160 } // namespace content |
OLD | NEW |