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

Side by Side Diff: base/test/scoped_task_scheduler_unittest.cc

Issue 2768873007: Add Support to Get a COM STA Task Runner from the Task Scheduler API (Closed)
Patch Set: Simplify COM Init for ScopedTaskScheduler Created 3 years, 8 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
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/test/scoped_task_scheduler.h" 5 #include "base/test/scoped_task_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/sequence_checker.h" 11 #include "base/sequence_checker.h"
12 #include "base/task_scheduler/post_task.h" 12 #include "base/task_scheduler/post_task.h"
13 #include "base/task_scheduler/task_scheduler.h" 13 #include "base/task_scheduler/task_scheduler.h"
14 #include "base/task_scheduler/test_utils.h" 14 #include "base/task_scheduler/test_utils.h"
15 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 15 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
16 #include "base/threading/sequenced_task_runner_handle.h" 16 #include "base/threading/sequenced_task_runner_handle.h"
17 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 #if defined(OS_WIN)
24 #include <objbase.h>
25 #endif // defined(OS_WIN)
26
23 namespace base { 27 namespace base {
24 namespace test { 28 namespace test {
25 29
26 TEST(ScopedTaskSchedulerTest, PostTask) { 30 TEST(ScopedTaskSchedulerTest, PostTask) {
27 ScopedTaskScheduler scoped_task_scheduler; 31 ScopedTaskScheduler scoped_task_scheduler;
28 32
29 bool first_task_ran = false; 33 bool first_task_ran = false;
30 bool second_task_ran = false; 34 bool second_task_ran = false;
31 35
32 SequenceCheckerImpl sequence_checker; 36 SequenceCheckerImpl sequence_checker;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 }, 221 },
218 Unretained(&sequence_checker), Unretained(&thread_checker), 222 Unretained(&sequence_checker), Unretained(&thread_checker),
219 Unretained(&second_task_ran))); 223 Unretained(&second_task_ran)));
220 224
221 RunLoop().RunUntilIdle(); 225 RunLoop().RunUntilIdle();
222 226
223 EXPECT_TRUE(first_task_ran); 227 EXPECT_TRUE(first_task_ran);
224 EXPECT_TRUE(second_task_ran); 228 EXPECT_TRUE(second_task_ran);
225 } 229 }
226 230
231 #if defined(OS_WIN)
232 // Verify that COM STAs work correctly from the ScopedTaskScheduler.
233 TEST(ScopedTaskSchedulerTest, COMSTAAvailable) {
234 ScopedTaskScheduler scoped_task_scheduler;
235 auto com_task_runner = CreateCOMSTATaskRunnerWithTraits(TaskTraits());
236
237 bool com_task_ran = false;
238 com_task_runner->PostTask(
239 FROM_HERE,
240 Bind(
241 [](bool* com_task_ran) {
242 *com_task_ran = true;
243 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
244 if (SUCCEEDED(hr)) {
245 ADD_FAILURE() << "COM STA was not initialized on this thread";
246 CoUninitialize();
247 }
248 },
249 &com_task_ran));
250
251 RunLoop().RunUntilIdle();
252
253 EXPECT_TRUE(com_task_ran);
254 }
255 #endif // defined(OS_WIN)
256
227 TEST(ScopedTaskSchedulerTest, NonBlockShutdownTasksPostedAfterShutdownDontRun) { 257 TEST(ScopedTaskSchedulerTest, NonBlockShutdownTasksPostedAfterShutdownDontRun) {
228 ScopedTaskScheduler scoped_task_scheduler; 258 ScopedTaskScheduler scoped_task_scheduler;
229 TaskScheduler::GetInstance()->Shutdown(); 259 TaskScheduler::GetInstance()->Shutdown();
230 PostTaskWithTraits(FROM_HERE, TaskTraits().WithShutdownBehavior( 260 PostTaskWithTraits(FROM_HERE, TaskTraits().WithShutdownBehavior(
231 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), 261 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
232 Bind([]() { 262 Bind([]() {
233 ADD_FAILURE() 263 ADD_FAILURE()
234 << "CONTINUE_ON_SHUTDOWN task should not run"; 264 << "CONTINUE_ON_SHUTDOWN task should not run";
235 })); 265 }));
236 PostTaskWithTraits( 266 PostTaskWithTraits(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 Bind([](bool* task_ran) { *task_ran = true; }, 338 Bind([](bool* task_ran) { *task_ran = true; },
309 Unretained(task_ran))); 339 Unretained(task_ran)));
310 }, 340 },
311 Unretained(&task_ran))); 341 Unretained(&task_ran)));
312 RunLoop().RunUntilIdle(); 342 RunLoop().RunUntilIdle();
313 EXPECT_TRUE(task_ran); 343 EXPECT_TRUE(task_ran);
314 } 344 }
315 345
316 } // namespace test 346 } // namespace test
317 } // namespace base 347 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_task_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698