summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2010-05-04 15:46:17 -0700
committerGuang Zhu <guangzhu@google.com>2010-05-05 10:48:23 -0700
commit0622f9689d1c3786a11c60cf0014cd517c51c21c (patch)
treee62aaf24c01cfab6d5f7281100a749e0f0ecb03d /tests/src
parent66640a5365b4f20d96f5eda6d54fbcb2fac4e30c (diff)
downloadpackages_apps_Browser-0622f9689d1c3786a11c60cf0014cd517c51c21c.zip
packages_apps_Browser-0622f9689d1c3786a11c60cf0014cd517c51c21c.tar.gz
packages_apps_Browser-0622f9689d1c3786a11c60cf0014cd517c51c21c.tar.bz2
improvement and fixes for bindings test
* the name "testComplete" will cause test runner to actually execute it as a test case, which is not the intention here, changed to "notifyComplete" * the test depends on "/sdcard/bindings_test.html". since the same file is already being carried in the apk as asset, added a setup/teardown step to extract the file. this removes manual setup step for the tests. Change-Id: I45e1e9755ec829086fae6a36885153874f3a94a2
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/browser/JNIBindingsTest.java7
-rw-r--r--tests/src/com/android/browser/JNIBindingsTestApp.java41
2 files changed, 42 insertions, 6 deletions
diff --git a/tests/src/com/android/browser/JNIBindingsTest.java b/tests/src/com/android/browser/JNIBindingsTest.java
index bfa3ac1..ba3c66a 100644
--- a/tests/src/com/android/browser/JNIBindingsTest.java
+++ b/tests/src/com/android/browser/JNIBindingsTest.java
@@ -20,6 +20,7 @@ import android.test.AndroidTestCase;
import android.util.Log;
import java.util.Arrays;
+
import junit.framework.AssertionFailedError;
public class JNIBindingsTest extends AndroidTestCase {
@@ -34,9 +35,9 @@ public class JNIBindingsTest extends AndroidTestCase {
mTestApp = testApp;
}
- public void testComplete() {
+ public void notifyComplete() {
Log.v(LOGTAG, "Completing the test.");
- mTestApp.testComplete();
+ mTestApp.notifyComplete();
}
public void printAssertionFailed(AssertionFailedError e) {
@@ -232,7 +233,7 @@ public class JNIBindingsTest extends AndroidTestCase {
assertEquals(expectedIntParam, intParam);
assertEquals(expectedDoubleParam, doubleParam);
assertEquals(expectedBooleanParam, booleanParam);
- assertEquals(expectedCharParam, charParam);;
+ assertEquals(expectedCharParam, charParam);
// EMULATE_JSC_BINDINGS JSC passes "undefined" for undefined types.
assertEquals(expectedUndefinedParam, undefinedParam);
diff --git a/tests/src/com/android/browser/JNIBindingsTestApp.java b/tests/src/com/android/browser/JNIBindingsTestApp.java
index e01aca2..4f083f6 100644
--- a/tests/src/com/android/browser/JNIBindingsTestApp.java
+++ b/tests/src/com/android/browser/JNIBindingsTestApp.java
@@ -18,7 +18,6 @@ package com.android.browser;
import android.app.Instrumentation;
import android.net.http.SslError;
-import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -29,6 +28,12 @@ import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
/**
* Adds a JavaScript interface to the webview and calls functions on it to verify variables
* are passed from JS to Java correctly.
@@ -37,6 +42,8 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser
private final static String TAG = "JNIBindingsTest";
+ private static final String SDCARD_BINDINGS_TEST_HTML = "/sdcard/bindings_test.html";
+
private static final int MSG_WEBKIT_DATA_READY = 101;
private BrowserActivity mActivity = null;
@@ -67,9 +74,11 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser
mWebView = webView;
}
+ @Override
public void run() {
Looper.prepare();
mHandler = new Handler() {
+ @Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_WEBKIT_DATA_READY: {
@@ -102,6 +111,32 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser
mInst = getInstrumentation();
mInst.waitForIdleSync();
+ extractAsset();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ removeAsset();
+ super.tearDown();
+ }
+
+ protected void extractAsset() throws IOException {
+ InputStream in = getInstrumentation().getContext().getAssets().open("bindings_test.html");
+ OutputStream out = new FileOutputStream(SDCARD_BINDINGS_TEST_HTML);
+
+ byte[] buf = new byte[2048];
+ int len;
+
+ while ((len = in.read(buf)) >= 0 ) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ in.close();
+ }
+
+ protected void removeAsset(){
+ File fileToDelete = new File(SDCARD_BINDINGS_TEST_HTML);
+ fileToDelete.delete();
}
/**
@@ -183,7 +218,7 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser
});
}
- public synchronized void testComplete() {
+ public synchronized void notifyComplete() {
mTestDone = true;
notify();
}
@@ -193,7 +228,7 @@ public class JNIBindingsTestApp extends ActivityInstrumentationTestCase2<Browser
Tab tab = mActivity.getTabControl().getCurrentTab();
WebView webView = tab.getWebView();
- webView.loadUrl("file:///sdcard/bindings_test.html");
+ webView.loadUrl("file://" + SDCARD_BINDINGS_TEST_HTML);
synchronized(this) {
while(!mTestDone) {
try {