| 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.Handler; | 10 import android.os.Handler; |
| 11 import android.util.Log; | 11 import android.util.Log; |
| 12 | 12 |
| 13 import org.chromium.base.CommandLine; | 13 import org.chromium.base.CommandLine; |
| 14 import org.chromium.base.PathUtils; | 14 import org.chromium.base.PathUtils; |
| 15 import org.chromium.base.PowerMonitor; | 15 import org.chromium.base.PowerMonitor; |
| 16 import org.chromium.base.ResourceExtractor; | 16 import org.chromium.base.ResourceExtractor; |
| 17 import org.chromium.base.library_loader.NativeLibraries; | 17 import org.chromium.base.library_loader.NativeLibraries; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Android's NativeActivity is mostly useful for pure-native code. | 20 * 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 | 21 * Our tests need to go up to our own java classes, which is not possible using |
| 22 * the native activity class loader. | 22 * the native activity class loader. |
| 23 */ | 23 */ |
| 24 public class ChromeNativeTestActivity extends Activity { | 24 public class ChromeNativeTestActivity extends Activity { |
| 25 public static final String EXTRA_COMMAND_LINE_FILE = |
| 26 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile"; |
| 27 public static final String EXTRA_COMMAND_LINE_FLAGS = |
| 28 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags"
; |
| 29 |
| 25 private static final String TAG = "ChromeNativeTestActivity"; | 30 private static final String TAG = "ChromeNativeTestActivity"; |
| 26 private static final String EXTRA_RUN_IN_SUB_THREAD = "RunInSubThread"; | 31 private static final String EXTRA_RUN_IN_SUB_THREAD = "RunInSubThread"; |
| 27 // We post a delayed task to run tests so that we do not block onCreate(). | 32 // We post a delayed task to run tests so that we do not block onCreate(). |
| 28 private static final long RUN_TESTS_DELAY_IN_MS = 300; | 33 private static final long RUN_TESTS_DELAY_IN_MS = 300; |
| 29 | 34 |
| 30 @Override | 35 @Override |
| 31 public void onCreate(Bundle savedInstanceState) { | 36 public void onCreate(Bundle savedInstanceState) { |
| 32 super.onCreate(savedInstanceState); | 37 super.onCreate(savedInstanceState); |
| 33 CommandLine.init(new String[]{}); | 38 CommandLine.init(new String[]{}); |
| 34 | 39 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 new Handler().postDelayed(new Runnable() { | 64 new Handler().postDelayed(new Runnable() { |
| 60 @Override | 65 @Override |
| 61 public void run() { | 66 public void run() { |
| 62 runTests(); | 67 runTests(); |
| 63 } | 68 } |
| 64 }, RUN_TESTS_DELAY_IN_MS); | 69 }, RUN_TESTS_DELAY_IN_MS); |
| 65 } | 70 } |
| 66 } | 71 } |
| 67 | 72 |
| 68 private void runTests() { | 73 private void runTests() { |
| 74 String commandLineFlags = getIntent().getStringExtra(EXTRA_COMMAND_LINE_
FLAGS); |
| 75 if (commandLineFlags == null) commandLineFlags = ""; |
| 76 |
| 77 String commandLineFilePath = getIntent().getStringExtra(EXTRA_COMMAND_LI
NE_FILE); |
| 78 if (commandLineFilePath == null) commandLineFilePath = ""; |
| 79 |
| 69 // This directory is used by build/android/pylib/test_package_apk.py. | 80 // This directory is used by build/android/pylib/test_package_apk.py. |
| 70 nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext())
; | 81 nativeRunTests(commandLineFlags, commandLineFilePath, getFilesDir().getA
bsolutePath(), |
| 82 getApplicationContext()); |
| 71 } | 83 } |
| 72 | 84 |
| 73 // Signal a failure of the native test loader to python scripts | 85 // Signal a failure of the native test loader to python scripts |
| 74 // which run tests. For example, we look for | 86 // which run tests. For example, we look for |
| 75 // RUNNER_FAILED build/android/test_package.py. | 87 // RUNNER_FAILED build/android/test_package.py. |
| 76 private void nativeTestFailed() { | 88 private void nativeTestFailed() { |
| 77 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); | 89 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); |
| 78 } | 90 } |
| 79 | 91 |
| 80 private void loadLibraries() { | 92 private void loadLibraries() { |
| 81 for (String library : NativeLibraries.LIBRARIES) { | 93 for (String library : NativeLibraries.LIBRARIES) { |
| 82 Log.i(TAG, "loading: " + library); | 94 Log.i(TAG, "loading: " + library); |
| 83 System.loadLibrary(library); | 95 System.loadLibrary(library); |
| 84 Log.i(TAG, "loaded: " + library); | 96 Log.i(TAG, "loaded: " + library); |
| 85 } | 97 } |
| 86 } | 98 } |
| 87 | 99 |
| 88 private native void nativeRunTests(String filesDir, Context appContext); | 100 private native void nativeRunTests(String commandLineFlags, String commandLi
neFilePath, |
| 101 String filesDir, Context appContext); |
| 89 } | 102 } |
| OLD | NEW |