| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.native_test; | 5 package org.chromium.native_test; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.os.Environment; |
| 10 import android.os.Handler; | 11 import android.os.Handler; |
| 11 import android.util.Log; | 12 import android.util.Log; |
| 12 | 13 |
| 13 import org.chromium.base.CommandLine; | 14 import org.chromium.base.CommandLine; |
| 14 import org.chromium.base.PathUtils; | 15 import org.chromium.base.PathUtils; |
| 15 import org.chromium.base.PowerMonitor; | 16 import org.chromium.base.PowerMonitor; |
| 16 import org.chromium.base.ResourceExtractor; | 17 import org.chromium.base.ResourceExtractor; |
| 17 import org.chromium.base.library_loader.NativeLibraries; | 18 import org.chromium.base.library_loader.NativeLibraries; |
| 18 | 19 |
| 20 import java.io.File; |
| 21 |
| 19 /** | 22 /** |
| 20 * Android's NativeActivity is mostly useful for pure-native code. | 23 * Android's NativeActivity is mostly useful for pure-native code. |
| 21 * Our tests need to go up to our own java classes, which is not possible using | 24 * Our tests need to go up to our own java classes, which is not possible using |
| 22 * the native activity class loader. | 25 * the native activity class loader. |
| 23 */ | 26 */ |
| 24 public class ChromeNativeTestActivity extends Activity { | 27 public class ChromeNativeTestActivity extends Activity { |
| 25 public static final String EXTRA_COMMAND_LINE_FILE = | 28 public static final String EXTRA_COMMAND_LINE_FILE = |
| 26 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile"; | 29 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile"; |
| 27 public static final String EXTRA_COMMAND_LINE_FLAGS = | 30 public static final String EXTRA_COMMAND_LINE_FLAGS = |
| 28 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags"
; | 31 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags"
; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 71 } |
| 69 }, RUN_TESTS_DELAY_IN_MS); | 72 }, RUN_TESTS_DELAY_IN_MS); |
| 70 } | 73 } |
| 71 } | 74 } |
| 72 | 75 |
| 73 private void runTests() { | 76 private void runTests() { |
| 74 String commandLineFlags = getIntent().getStringExtra(EXTRA_COMMAND_LINE_
FLAGS); | 77 String commandLineFlags = getIntent().getStringExtra(EXTRA_COMMAND_LINE_
FLAGS); |
| 75 if (commandLineFlags == null) commandLineFlags = ""; | 78 if (commandLineFlags == null) commandLineFlags = ""; |
| 76 | 79 |
| 77 String commandLineFilePath = getIntent().getStringExtra(EXTRA_COMMAND_LI
NE_FILE); | 80 String commandLineFilePath = getIntent().getStringExtra(EXTRA_COMMAND_LI
NE_FILE); |
| 78 if (commandLineFilePath == null) commandLineFilePath = ""; | 81 if (commandLineFilePath == null) { |
| 82 commandLineFilePath = ""; |
| 83 } else { |
| 84 File commandLineFile = new File(commandLineFilePath); |
| 85 if (!commandLineFile.isAbsolute()) { |
| 86 commandLineFilePath = Environment.getExternalStorageDirectory()
+ "/" |
| 87 + commandLineFilePath; |
| 88 } |
| 89 Log.i(TAG, "command line file path: " + commandLineFilePath); |
| 90 } |
| 79 | 91 |
| 80 // This directory is used by build/android/pylib/test_package_apk.py. | 92 // This directory is used by build/android/pylib/test_package_apk.py. |
| 81 nativeRunTests(commandLineFlags, commandLineFilePath, getFilesDir().getA
bsolutePath(), | 93 nativeRunTests(commandLineFlags, commandLineFilePath, getFilesDir().getA
bsolutePath(), |
| 82 getApplicationContext()); | 94 getApplicationContext()); |
| 83 } | 95 } |
| 84 | 96 |
| 85 // Signal a failure of the native test loader to python scripts | 97 // Signal a failure of the native test loader to python scripts |
| 86 // which run tests. For example, we look for | 98 // which run tests. For example, we look for |
| 87 // RUNNER_FAILED build/android/test_package.py. | 99 // RUNNER_FAILED build/android/test_package.py. |
| 88 private void nativeTestFailed() { | 100 private void nativeTestFailed() { |
| 89 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); | 101 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); |
| 90 } | 102 } |
| 91 | 103 |
| 92 private void loadLibraries() { | 104 private void loadLibraries() { |
| 93 for (String library : NativeLibraries.LIBRARIES) { | 105 for (String library : NativeLibraries.LIBRARIES) { |
| 94 Log.i(TAG, "loading: " + library); | 106 Log.i(TAG, "loading: " + library); |
| 95 System.loadLibrary(library); | 107 System.loadLibrary(library); |
| 96 Log.i(TAG, "loaded: " + library); | 108 Log.i(TAG, "loaded: " + library); |
| 97 } | 109 } |
| 98 } | 110 } |
| 99 | 111 |
| 100 private native void nativeRunTests(String commandLineFlags, String commandLi
neFilePath, | 112 private native void nativeRunTests(String commandLineFlags, String commandLi
neFilePath, |
| 101 String filesDir, Context appContext); | 113 String filesDir, Context appContext); |
| 102 } | 114 } |
| OLD | NEW |