mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 09:02:50 +08:00
Updating tests to KitKat, and making the tests more thread-safe
This commit is contained in:
parent
4638331cb4
commit
41cace9a96
@ -45,7 +45,7 @@
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
|
||||
|
||||
<instrumentation
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
|
@ -15,6 +15,9 @@
|
||||
<feature name="Activity">
|
||||
<param name="android-package" value="org.apache.cordova.test.ActivityPlugin" />
|
||||
</feature>
|
||||
<feature name="PluginStub">
|
||||
<param name="android-package" value="org.apache.cordova.pluginApi.pluginStub" />
|
||||
</feature>
|
||||
<feature name="App">
|
||||
<param name="android-package" value="org.apache.cordova.App" />
|
||||
</feature>
|
||||
|
39
test/src/org/apache/cordova/pluginApi/pluginStub.java
Normal file
39
test/src/org/apache/cordova/pluginApi/pluginStub.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This plugin is a test of all the message callbacks and actions available to plugins
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.cordova.pluginApi;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
|
||||
public class pluginStub extends CordovaPlugin {
|
||||
|
||||
public String id;
|
||||
public Object data;
|
||||
|
||||
public Object onMessage(String id, Object input)
|
||||
{
|
||||
this.data = input;
|
||||
return input;
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.test.backbuttonmultipage;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.UiThreadTest;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.BaseInputConnection;
|
||||
import android.widget.FrameLayout;
|
||||
@ -43,6 +44,7 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
||||
super(backbuttonmultipage.class);
|
||||
}
|
||||
|
||||
@UiThreadTest
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
testActivity = this.getActivity();
|
||||
@ -53,6 +55,7 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
||||
sleep();
|
||||
}
|
||||
|
||||
@UiThreadTest
|
||||
public void testPreconditions(){
|
||||
assertNotNull(innerContainer);
|
||||
assertNotNull(testView);
|
||||
@ -60,96 +63,202 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
|
||||
public void testViaHref() {
|
||||
testView.sendJavascript("window.location = 'sample2.html';");
|
||||
public void testViaHref() throws Throwable {
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.sendJavascript("window.location = 'sample2.html';");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.sendJavascript("window.location = 'sample3.html';");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.sendJavascript("window.location = 'sample3.html';"); }
|
||||
});
|
||||
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
boolean didGoBack = testView.backHistory();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
testView.backHistory();
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
assertTrue(didGoBack);
|
||||
didGoBack = testView.backHistory();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.backHistory();
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
assertTrue(didGoBack);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testViaLoadUrl() {
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||
public void testViaLoadUrl() throws Throwable {
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
boolean didGoBack = testView.backHistory();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
testView.backHistory();
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
assertTrue(didGoBack);
|
||||
didGoBack = testView.backHistory();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.backHistory();
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
assertTrue(didGoBack);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
testView.backHistory();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testViaBackButtonOnView() {
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||
public void testViaBackButtonOnView() throws Throwable {
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void testViaBackButtonOnLayout() {
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||
public void testViaBackButtonOnLayout() throws Throwable {
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample3.html"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@UiThreadTest
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(TIMEOUT);
|
||||
|
@ -70,14 +70,29 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
|
||||
}
|
||||
|
||||
|
||||
public void testPauseAndResume()
|
||||
public void testPauseAndResume() throws Throwable
|
||||
{
|
||||
mInstr.callActivityOnPause(testActivity);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
mInstr.callActivityOnPause(testActivity);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
assertTrue(testView.isPaused());
|
||||
mInstr.callActivityOnResume(testActivity);
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
assertTrue(testView.isPaused());
|
||||
mInstr.callActivityOnResume(testActivity);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
assertFalse(testView.isPaused());
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
assertFalse(testView.isPaused());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
|
@ -54,13 +54,19 @@ public class ErrorUrlTest extends ActivityInstrumentationTestCase2<errorurl> {
|
||||
assertNotNull(testView);
|
||||
}
|
||||
|
||||
public void testUrl()
|
||||
public void testUrl() throws Throwable
|
||||
{
|
||||
sleep();
|
||||
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
||||
String url = testView.getUrl();
|
||||
assertNotNull(url);
|
||||
assertTrue(url.equals(good_url));
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
||||
String url = testView.getUrl();
|
||||
assertNotNull(url);
|
||||
assertTrue(url.equals(good_url));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,13 +54,19 @@ public class HtmlNotFoundTest extends ActivityInstrumentationTestCase2<htmlnotfo
|
||||
assertNotNull(testView);
|
||||
}
|
||||
|
||||
public void testUrl()
|
||||
public void testUrl() throws Throwable
|
||||
{
|
||||
sleep();
|
||||
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
||||
String url = testView.getUrl();
|
||||
assertNotNull(url);
|
||||
assertFalse(url.equals(good_url));
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
||||
String url = testView.getUrl();
|
||||
assertNotNull(url);
|
||||
assertFalse(url.equals(good_url));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
|
@ -60,26 +60,62 @@ public class IFrameTest extends ActivityInstrumentationTestCase2 {
|
||||
}
|
||||
|
||||
|
||||
public void testIframeDest()
|
||||
public void testIframeDest() throws Throwable
|
||||
{
|
||||
testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
|
||||
}
|
||||
});
|
||||
sleep(3000);
|
||||
testView.sendJavascript("loadUrl('index2.html')");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.sendJavascript("loadUrl('index2.html')");
|
||||
}
|
||||
});
|
||||
sleep(1000);
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testIframeHistory()
|
||||
public void testIframeHistory() throws Throwable
|
||||
{
|
||||
testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
|
||||
}
|
||||
});
|
||||
sleep(3000);
|
||||
testView.sendJavascript("loadUrl('index2.html')");
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
testView.sendJavascript("loadUrl('index2.html')");
|
||||
}
|
||||
});
|
||||
sleep(1000);
|
||||
String url = testView.getUrl();
|
||||
testView.backHistory();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
testView.backHistory();
|
||||
}
|
||||
});
|
||||
sleep(1000);
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sleep(int timeout) {
|
||||
|
55
test/src/org/apache/cordova/test/junit/MessageTest.java
Normal file
55
test/src/org/apache/cordova/test/junit/MessageTest.java
Normal file
@ -0,0 +1,55 @@
|
||||
package org.apache.cordova.test.junit;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.ScrollEvent;
|
||||
import org.apache.cordova.pluginApi.pluginStub;
|
||||
import org.apache.cordova.test.CordovaWebViewTestActivity;
|
||||
import org.apache.cordova.test.R;
|
||||
|
||||
import com.jayway.android.robotium.solo.By;
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
|
||||
public class MessageTest extends
|
||||
ActivityInstrumentationTestCase2<CordovaWebViewTestActivity> {
|
||||
private CordovaWebViewTestActivity testActivity;
|
||||
private CordovaWebView testView;
|
||||
private pluginStub testPlugin;
|
||||
private int TIMEOUT = 1000;
|
||||
|
||||
private Solo solo;
|
||||
|
||||
public MessageTest() {
|
||||
super("org.apache.cordova.test.activities", CordovaWebViewTestActivity.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
testActivity = this.getActivity();
|
||||
testView = (CordovaWebView) testActivity.findViewById(R.id.cordovaWebView);
|
||||
testPlugin = (pluginStub) testView.pluginManager.getPlugin("PluginStub");
|
||||
solo = new Solo(getInstrumentation(), getActivity());
|
||||
}
|
||||
|
||||
public void testOnScrollChanged()
|
||||
{
|
||||
solo.waitForWebElement(By.textContent("Cordova Android Tests"));
|
||||
solo.scrollDown();
|
||||
sleep();
|
||||
Object data = testPlugin.data;
|
||||
assertTrue(data.getClass().getSimpleName().equals("ScrollEvent"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
fail("Unexpected Timeout");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user