OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdarg.h> | 5 #include <stdarg.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "base/android/path_utils.h" | 8 #include "base/android/path_utils.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_pump_android.h" | 14 #include "base/message_loop/message_pump_android.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/test/multiprocess_test.h" | 17 #include "base/test/multiprocess_test.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 base::FilePath* g_test_data_dir = nullptr; | |
22 | |
23 struct RunState { | 21 struct RunState { |
24 RunState(base::MessagePump::Delegate* delegate, int run_depth) | 22 RunState(base::MessagePump::Delegate* delegate, int run_depth) |
25 : delegate(delegate), | 23 : delegate(delegate), |
26 run_depth(run_depth), | 24 run_depth(run_depth), |
27 should_quit(false) { | 25 should_quit(false) { |
28 } | 26 } |
29 | 27 |
30 base::MessagePump::Delegate* delegate; | 28 base::MessagePump::Delegate* delegate; |
31 | 29 |
32 // Used to count how many Run() invocations are on the stack. | 30 // Used to count how many Run() invocations are on the stack. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 125 |
128 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override { | 126 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override { |
129 Waitable::GetInstance()->Signal(); | 127 Waitable::GetInstance()->Signal(); |
130 } | 128 } |
131 }; | 129 }; |
132 | 130 |
133 std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() { | 131 std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() { |
134 return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub()); | 132 return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub()); |
135 }; | 133 }; |
136 | 134 |
137 // Provides the test path for DIR_SOURCE_ROOT and DIR_ANDROID_APP_DATA. | 135 // Provides the test path for DIR_MODULE and DIR_ANDROID_APP_DATA. |
138 bool GetTestProviderPath(int key, base::FilePath* result) { | 136 bool GetTestProviderPath(int key, base::FilePath* result) { |
139 switch (key) { | 137 switch (key) { |
140 case base::DIR_ANDROID_APP_DATA: | 138 case base::DIR_ANDROID_APP_DATA: { |
141 case base::DIR_SOURCE_ROOT: | 139 // For tests, app data is put in external storage. |
142 CHECK(g_test_data_dir != nullptr); | 140 return base::android::GetExternalStorageDirectory(result); |
143 *result = *g_test_data_dir; | 141 } |
144 return true; | |
145 default: | 142 default: |
146 return false; | 143 return false; |
147 } | 144 } |
148 } | 145 } |
149 | 146 |
150 void InitPathProvider(int key) { | 147 void InitPathProvider(int key) { |
151 base::FilePath path; | 148 base::FilePath path; |
152 // If failed to override the key, that means the way has not been registered. | 149 // If failed to override the key, that means the way has not been registered. |
153 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path)) | 150 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path)) |
154 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1); | 151 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1); |
155 } | 152 } |
156 | 153 |
157 } // namespace | 154 } // namespace |
158 | 155 |
159 namespace base { | 156 namespace base { |
160 | 157 |
161 void InitAndroidTestLogging() { | 158 void InitAndroidTestLogging() { |
162 logging::LoggingSettings settings; | 159 logging::LoggingSettings settings; |
163 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 160 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
164 logging::InitLogging(settings); | 161 logging::InitLogging(settings); |
165 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 162 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
166 logging::SetLogItems(false, // Process ID | 163 logging::SetLogItems(false, // Process ID |
167 false, // Thread ID | 164 false, // Thread ID |
168 false, // Timestamp | 165 false, // Timestamp |
169 false); // Tick count | 166 false); // Tick count |
170 } | 167 } |
171 | 168 |
172 void InitAndroidTestPaths(const FilePath& test_data_dir) { | 169 void InitAndroidTestPaths() { |
173 if (g_test_data_dir) { | 170 InitPathProvider(DIR_MODULE); |
174 CHECK(test_data_dir == *g_test_data_dir); | |
175 return; | |
176 } | |
177 g_test_data_dir = new FilePath(test_data_dir); | |
178 InitPathProvider(DIR_SOURCE_ROOT); | |
179 InitPathProvider(DIR_ANDROID_APP_DATA); | 171 InitPathProvider(DIR_ANDROID_APP_DATA); |
180 } | 172 } |
181 | 173 |
182 void InitAndroidTestMessageLoop() { | 174 void InitAndroidTestMessageLoop() { |
183 if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub)) | 175 if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub)) |
184 LOG(INFO) << "MessagePumpForUIFactory already set, unable to override."; | 176 LOG(INFO) << "MessagePumpForUIFactory already set, unable to override."; |
185 } | 177 } |
186 | 178 |
187 void InitAndroidTest() { | 179 void InitAndroidTest() { |
188 if (!base::AndroidIsChildProcess()) { | 180 if (!base::AndroidIsChildProcess()) { |
189 InitAndroidTestLogging(); | 181 InitAndroidTestLogging(); |
| 182 InitAndroidTestPaths(); |
190 } | 183 } |
191 InitAndroidTestMessageLoop(); | 184 InitAndroidTestMessageLoop(); |
192 } | 185 } |
193 } // namespace base | 186 } // namespace base |
OLD | NEW |