OLD | NEW |
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/task_scheduler/scheduler_worker.h" | 5 #include "base/task_scheduler/scheduler_worker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
24 #include "base/threading/platform_thread.h" | 24 #include "base/threading/platform_thread.h" |
25 #include "base/threading/simple_thread.h" | 25 #include "base/threading/simple_thread.h" |
26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
32 #include <objbase.h> | 32 #include <objbase.h> |
| 33 |
| 34 #include "base/win/com_init_check_hook.h" |
33 #endif | 35 #endif |
34 | 36 |
35 using testing::_; | 37 using testing::_; |
36 using testing::Mock; | 38 using testing::Mock; |
37 using testing::Ne; | 39 using testing::Ne; |
38 using testing::StrictMock; | 40 using testing::StrictMock; |
39 | 41 |
40 namespace base { | 42 namespace base { |
41 namespace internal { | 43 namespace internal { |
42 namespace { | 44 namespace { |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 // until GetWork() returns. | 926 // until GetWork() returns. |
925 auto worker = make_scoped_refptr(new SchedulerWorker( | 927 auto worker = make_scoped_refptr(new SchedulerWorker( |
926 ThreadPriority::NORMAL, std::move(delegate), &task_tracker, nullptr, | 928 ThreadPriority::NORMAL, std::move(delegate), &task_tracker, nullptr, |
927 SchedulerBackwardCompatibility::INIT_COM_STA)); | 929 SchedulerBackwardCompatibility::INIT_COM_STA)); |
928 worker->Start(); | 930 worker->Start(); |
929 worker->WakeUp(); | 931 worker->WakeUp(); |
930 delegate_raw->WaitUntilGetWorkReturned(); | 932 delegate_raw->WaitUntilGetWorkReturned(); |
931 | 933 |
932 // The call to CoInitializeEx() should have returned S_FALSE to indicate that | 934 // The call to CoInitializeEx() should have returned S_FALSE to indicate that |
933 // the COM library was already initialized on the thread. | 935 // the COM library was already initialized on the thread. |
| 936 // See SchedulerWorker::Thread::ThreadMain for why we expect two different |
| 937 // results here. |
| 938 #if defined(COM_INIT_CHECK_HOOK_ENABLED) |
| 939 EXPECT_EQ(S_OK, delegate_raw->coinitialize_hresult()); |
| 940 #else |
934 EXPECT_EQ(S_FALSE, delegate_raw->coinitialize_hresult()); | 941 EXPECT_EQ(S_FALSE, delegate_raw->coinitialize_hresult()); |
| 942 #endif |
935 | 943 |
936 worker->JoinForTesting(); | 944 worker->JoinForTesting(); |
937 } | 945 } |
938 | 946 |
939 TEST(TaskSchedulerWorkerTest, BackwardCompatibilityDisabled) { | 947 TEST(TaskSchedulerWorkerTest, BackwardCompatibilityDisabled) { |
940 TaskTracker task_tracker; | 948 TaskTracker task_tracker; |
941 auto delegate = MakeUnique<CoInitializeDelegate>(); | 949 auto delegate = MakeUnique<CoInitializeDelegate>(); |
942 CoInitializeDelegate* const delegate_raw = delegate.get(); | 950 CoInitializeDelegate* const delegate_raw = delegate.get(); |
943 | 951 |
944 // Create a worker with backward compatibility DISABLED. Wake it up and wait | 952 // Create a worker with backward compatibility DISABLED. Wake it up and wait |
945 // until GetWork() returns. | 953 // until GetWork() returns. |
946 auto worker = make_scoped_refptr(new SchedulerWorker( | 954 auto worker = make_scoped_refptr(new SchedulerWorker( |
947 ThreadPriority::NORMAL, std::move(delegate), &task_tracker, nullptr, | 955 ThreadPriority::NORMAL, std::move(delegate), &task_tracker, nullptr, |
948 SchedulerBackwardCompatibility::DISABLED)); | 956 SchedulerBackwardCompatibility::DISABLED)); |
949 worker->Start(); | 957 worker->Start(); |
950 worker->WakeUp(); | 958 worker->WakeUp(); |
951 delegate_raw->WaitUntilGetWorkReturned(); | 959 delegate_raw->WaitUntilGetWorkReturned(); |
952 | 960 |
953 // The call to CoInitializeEx() should have returned S_OK to indicate that the | 961 // The call to CoInitializeEx() should have returned S_OK to indicate that the |
954 // COM library wasn't already initialized on the thread. | 962 // COM library wasn't already initialized on the thread. |
955 EXPECT_EQ(S_OK, delegate_raw->coinitialize_hresult()); | 963 EXPECT_EQ(S_OK, delegate_raw->coinitialize_hresult()); |
956 | 964 |
957 worker->JoinForTesting(); | 965 worker->JoinForTesting(); |
958 } | 966 } |
959 | 967 |
960 #endif // defined(OS_WIN) | 968 #endif // defined(OS_WIN) |
961 | 969 |
962 } // namespace internal | 970 } // namespace internal |
963 } // namespace base | 971 } // namespace base |
OLD | NEW |