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

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

Issue 2018663002: 👔 Reland of Move side-loaded test data /sdcard -> /sdcard/gtestdata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
OLDNEW
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
21 struct RunState { 23 struct RunState {
22 RunState(base::MessagePump::Delegate* delegate, int run_depth) 24 RunState(base::MessagePump::Delegate* delegate, int run_depth)
23 : delegate(delegate), 25 : delegate(delegate),
24 run_depth(run_depth), 26 run_depth(run_depth),
25 should_quit(false) { 27 should_quit(false) {
26 } 28 }
27 29
28 base::MessagePump::Delegate* delegate; 30 base::MessagePump::Delegate* delegate;
29 31
30 // Used to count how many Run() invocations are on the stack. 32 // Used to count how many Run() invocations are on the stack.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 127
126 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override { 128 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override {
127 Waitable::GetInstance()->Signal(); 129 Waitable::GetInstance()->Signal();
128 } 130 }
129 }; 131 };
130 132
131 std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() { 133 std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() {
132 return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub()); 134 return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub());
133 }; 135 };
134 136
135 // Provides the test path for DIR_MODULE and DIR_ANDROID_APP_DATA. 137 // Provides the test path for DIR_SOURCE_ROOT and DIR_ANDROID_APP_DATA.
136 bool GetTestProviderPath(int key, base::FilePath* result) { 138 bool GetTestProviderPath(int key, base::FilePath* result) {
137 switch (key) { 139 switch (key) {
138 case base::DIR_ANDROID_APP_DATA: { 140 case base::DIR_ANDROID_APP_DATA:
139 // For tests, app data is put in external storage. 141 case base::DIR_SOURCE_ROOT:
140 return base::android::GetExternalStorageDirectory(result); 142 CHECK(g_test_data_dir != nullptr);
141 } 143 *result = *g_test_data_dir;
144 return true;
142 default: 145 default:
143 return false; 146 return false;
144 } 147 }
145 } 148 }
146 149
147 void InitPathProvider(int key) { 150 void InitPathProvider(int key) {
148 base::FilePath path; 151 base::FilePath path;
149 // If failed to override the key, that means the way has not been registered. 152 // If failed to override the key, that means the way has not been registered.
150 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path)) 153 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path))
151 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1); 154 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1);
152 } 155 }
153 156
154 } // namespace 157 } // namespace
155 158
156 namespace base { 159 namespace base {
157 160
158 void InitAndroidTestLogging() { 161 void InitAndroidTestLogging() {
159 logging::LoggingSettings settings; 162 logging::LoggingSettings settings;
160 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 163 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
161 logging::InitLogging(settings); 164 logging::InitLogging(settings);
162 // To view log output with IDs and timestamps use "adb logcat -v threadtime". 165 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
163 logging::SetLogItems(false, // Process ID 166 logging::SetLogItems(false, // Process ID
164 false, // Thread ID 167 false, // Thread ID
165 false, // Timestamp 168 false, // Timestamp
166 false); // Tick count 169 false); // Tick count
167 } 170 }
168 171
169 void InitAndroidTestPaths() { 172 void InitAndroidTestPaths(const FilePath& test_data_dir) {
170 InitPathProvider(DIR_MODULE); 173 if (g_test_data_dir) {
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);
171 InitPathProvider(DIR_ANDROID_APP_DATA); 179 InitPathProvider(DIR_ANDROID_APP_DATA);
172 } 180 }
173 181
174 void InitAndroidTestMessageLoop() { 182 void InitAndroidTestMessageLoop() {
175 if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub)) 183 if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub))
176 LOG(INFO) << "MessagePumpForUIFactory already set, unable to override."; 184 LOG(INFO) << "MessagePumpForUIFactory already set, unable to override.";
177 } 185 }
178 186
179 void InitAndroidTest() { 187 void InitAndroidTest() {
180 if (!base::AndroidIsChildProcess()) { 188 if (!base::AndroidIsChildProcess()) {
181 InitAndroidTestLogging(); 189 InitAndroidTestLogging();
182 InitAndroidTestPaths();
183 } 190 }
184 InitAndroidTestMessageLoop(); 191 InitAndroidTestMessageLoop();
185 } 192 }
186 } // namespace base 193 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_support_android.h ('k') | build/android/pylib/local/device/local_device_gtest_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698