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/file_path.h" | 9 #include "base/file_path.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
12 #include "base/message_pump_android.h" | 13 #include "base/message_pump_android.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // The test implementation of AndroidOS stores everything in the following | |
19 // directory. | |
20 const char* kAndroidTestTempDirectory = "/data/local/tmp"; | |
21 | |
22 struct RunState { | 19 struct RunState { |
23 RunState(base::MessagePump::Delegate* delegate, int run_depth) | 20 RunState(base::MessagePump::Delegate* delegate, int run_depth) |
24 : delegate(delegate), | 21 : delegate(delegate), |
25 run_depth(run_depth), | 22 run_depth(run_depth), |
26 should_quit(false) { | 23 should_quit(false) { |
27 } | 24 } |
28 | 25 |
29 base::MessagePump::Delegate* delegate; | 26 base::MessagePump::Delegate* delegate; |
30 | 27 |
31 // Used to count how many Run() invocations are on the stack. | 28 // Used to count how many Run() invocations are on the stack. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 } | 131 } |
135 | 132 |
136 protected: | 133 protected: |
137 virtual ~MessagePumpForUIStub() {} | 134 virtual ~MessagePumpForUIStub() {} |
138 }; | 135 }; |
139 | 136 |
140 base::MessagePump* CreateMessagePumpForUIStub() { | 137 base::MessagePump* CreateMessagePumpForUIStub() { |
141 return new MessagePumpForUIStub(); | 138 return new MessagePumpForUIStub(); |
142 }; | 139 }; |
143 | 140 |
144 // Provides the test path for DIR_MODULE, DIR_CACHE and DIR_ANDROID_APP_DATA. | 141 // Provides the test path for DIR_MODULE and DIR_ANDROID_APP_DATA. |
145 bool GetTestProviderPath(int key, FilePath* result) { | 142 bool GetTestProviderPath(int key, FilePath* result) { |
146 switch (key) { | 143 switch (key) { |
147 case base::DIR_MODULE: { | 144 case base::DIR_MODULE: { |
148 *result = FilePath(kAndroidTestTempDirectory); | 145 *result = FilePath(base::android::GetExternalStorageDirectory()); |
149 return true; | 146 return true; |
150 } | 147 } |
151 case base::DIR_ANDROID_APP_DATA: { | 148 case base::DIR_ANDROID_APP_DATA: { |
152 *result = FilePath(kAndroidTestTempDirectory); | 149 // For tests, app data is put in external storage. |
| 150 *result = FilePath(base::android::GetExternalStorageDirectory()); |
153 return true; | 151 return true; |
154 } | 152 } |
155 default: | 153 default: |
156 return false; | 154 return false; |
157 } | 155 } |
158 } | 156 } |
159 | 157 |
160 void InitPathProvider(int key) { | 158 void InitPathProvider(int key) { |
161 FilePath path; | 159 FilePath path; |
162 // If failed to override the key, that means the way has not been registered. | 160 // If failed to override the key, that means the way has not been registered. |
(...skipping 13 matching lines...) Expand all Loading... |
176 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 174 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
177 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 175 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
178 logging::SetLogItems(false, // Process ID | 176 logging::SetLogItems(false, // Process ID |
179 false, // Thread ID | 177 false, // Thread ID |
180 false, // Timestamp | 178 false, // Timestamp |
181 false); // Tick count | 179 false); // Tick count |
182 } | 180 } |
183 | 181 |
184 void InitAndroidTestPaths() { | 182 void InitAndroidTestPaths() { |
185 InitPathProvider(DIR_MODULE); | 183 InitPathProvider(DIR_MODULE); |
186 InitPathProvider(DIR_CACHE); | |
187 InitPathProvider(DIR_ANDROID_APP_DATA); | 184 InitPathProvider(DIR_ANDROID_APP_DATA); |
188 } | 185 } |
189 | 186 |
190 void InitAndroidTestMessageLoop() { | 187 void InitAndroidTestMessageLoop() { |
191 MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub); | 188 MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub); |
192 } | 189 } |
193 | 190 |
194 void InitAndroidTest() { | 191 void InitAndroidTest() { |
195 InitAndroidTestLogging(); | 192 InitAndroidTestLogging(); |
196 InitAndroidTestPaths(); | 193 InitAndroidTestPaths(); |
197 InitAndroidTestMessageLoop(); | 194 InitAndroidTestMessageLoop(); |
198 } | 195 } |
199 } // namespace base | 196 } // namespace base |
OLD | NEW |