forked from github/cordova-android
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.GET_ACCOUNTS" />
|
||||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="8" />
|
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
|
||||||
|
|
||||||
<instrumentation
|
<instrumentation
|
||||||
android:name="android.test.InstrumentationTestRunner"
|
android:name="android.test.InstrumentationTestRunner"
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
<feature name="Activity">
|
<feature name="Activity">
|
||||||
<param name="android-package" value="org.apache.cordova.test.ActivityPlugin" />
|
<param name="android-package" value="org.apache.cordova.test.ActivityPlugin" />
|
||||||
</feature>
|
</feature>
|
||||||
|
<feature name="PluginStub">
|
||||||
|
<param name="android-package" value="org.apache.cordova.pluginApi.pluginStub" />
|
||||||
|
</feature>
|
||||||
<feature name="App">
|
<feature name="App">
|
||||||
<param name="android-package" value="org.apache.cordova.App" />
|
<param name="android-package" value="org.apache.cordova.App" />
|
||||||
</feature>
|
</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 org.apache.cordova.test.backbuttonmultipage;
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.test.UiThreadTest;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.inputmethod.BaseInputConnection;
|
import android.view.inputmethod.BaseInputConnection;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@ -43,6 +44,7 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
|||||||
super(backbuttonmultipage.class);
|
super(backbuttonmultipage.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThreadTest
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
testActivity = this.getActivity();
|
testActivity = this.getActivity();
|
||||||
@ -53,6 +55,7 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
|||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThreadTest
|
||||||
public void testPreconditions(){
|
public void testPreconditions(){
|
||||||
assertNotNull(innerContainer);
|
assertNotNull(innerContainer);
|
||||||
assertNotNull(testView);
|
assertNotNull(testView);
|
||||||
@ -60,96 +63,202 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
|||||||
assertTrue(url.endsWith("index.html"));
|
assertTrue(url.endsWith("index.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testViaHref() {
|
public void testViaHref() throws Throwable {
|
||||||
testView.sendJavascript("window.location = 'sample2.html';");
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
testView.sendJavascript("window.location = 'sample2.html';");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
String url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
testView.sendJavascript("window.location = 'sample3.html';");
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
testView.sendJavascript("window.location = 'sample3.html';"); }
|
||||||
|
});
|
||||||
|
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample3.html"));
|
public void run()
|
||||||
boolean didGoBack = testView.backHistory();
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample3.html"));
|
||||||
|
testView.backHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
assertTrue(didGoBack);
|
{
|
||||||
didGoBack = testView.backHistory();
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
testView.backHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("index.html"));
|
public void run()
|
||||||
assertTrue(didGoBack);
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("index.html"));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testViaLoadUrl() {
|
public void testViaLoadUrl() throws Throwable {
|
||||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
String url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample3.html"));
|
public void run()
|
||||||
boolean didGoBack = testView.backHistory();
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample3.html"));
|
||||||
|
testView.backHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
assertTrue(didGoBack);
|
{
|
||||||
didGoBack = testView.backHistory();
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
testView.backHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("index.html"));
|
public void run()
|
||||||
assertTrue(didGoBack);
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("index.html"));
|
||||||
|
testView.backHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testViaBackButtonOnView() {
|
public void testViaBackButtonOnView() throws Throwable {
|
||||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
String url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample3.html"));
|
public void run()
|
||||||
BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
|
{
|
||||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
String url = testView.getUrl();
|
||||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
assertTrue(url.endsWith("sample3.html"));
|
||||||
viewConnection.sendKeyEvent(backDown);
|
BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
|
||||||
viewConnection.sendKeyEvent(backUp);
|
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();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
viewConnection.sendKeyEvent(backDown);
|
{
|
||||||
viewConnection.sendKeyEvent(backUp);
|
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();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("index.html"));
|
public void run()
|
||||||
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("index.html"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testViaBackButtonOnLayout() {
|
public void testViaBackButtonOnLayout() throws Throwable {
|
||||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
String url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample3.html"));
|
public void run()
|
||||||
BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
|
{
|
||||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
String url = testView.getUrl();
|
||||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
assertTrue(url.endsWith("sample3.html"));
|
||||||
viewConnection.sendKeyEvent(backDown);
|
BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
|
||||||
viewConnection.sendKeyEvent(backUp);
|
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();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("sample2.html"));
|
public void run()
|
||||||
viewConnection.sendKeyEvent(backDown);
|
{
|
||||||
viewConnection.sendKeyEvent(backUp);
|
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();
|
sleep();
|
||||||
url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("index.html"));
|
public void run()
|
||||||
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("index.html"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThreadTest
|
||||||
private void sleep() {
|
private void sleep() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TIMEOUT);
|
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();
|
sleep();
|
||||||
assertTrue(testView.isPaused());
|
runTestOnUiThread(new Runnable() {
|
||||||
mInstr.callActivityOnResume(testActivity);
|
public void run()
|
||||||
|
{
|
||||||
|
assertTrue(testView.isPaused());
|
||||||
|
mInstr.callActivityOnResume(testActivity);
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep();
|
sleep();
|
||||||
assertFalse(testView.isPaused());
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
assertFalse(testView.isPaused());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sleep() {
|
private void sleep() {
|
||||||
|
@ -54,13 +54,19 @@ public class ErrorUrlTest extends ActivityInstrumentationTestCase2<errorurl> {
|
|||||||
assertNotNull(testView);
|
assertNotNull(testView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUrl()
|
public void testUrl() throws Throwable
|
||||||
{
|
{
|
||||||
sleep();
|
sleep();
|
||||||
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
runTestOnUiThread(new Runnable() {
|
||||||
String url = testView.getUrl();
|
public void run()
|
||||||
assertNotNull(url);
|
{
|
||||||
assertTrue(url.equals(good_url));
|
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);
|
assertNotNull(testView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUrl()
|
public void testUrl() throws Throwable
|
||||||
{
|
{
|
||||||
sleep();
|
sleep();
|
||||||
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
runTestOnUiThread(new Runnable() {
|
||||||
String url = testView.getUrl();
|
public void run()
|
||||||
assertNotNull(url);
|
{
|
||||||
assertFalse(url.equals(good_url));
|
String good_url = "file:///android_asset/www/htmlnotfound/error.html";
|
||||||
|
String url = testView.getUrl();
|
||||||
|
assertNotNull(url);
|
||||||
|
assertFalse(url.equals(good_url));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sleep() {
|
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);
|
sleep(3000);
|
||||||
testView.sendJavascript("loadUrl('index2.html')");
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
testView.sendJavascript("loadUrl('index2.html')");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
String url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
assertTrue(url.endsWith("index.html"));
|
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);
|
sleep(3000);
|
||||||
testView.sendJavascript("loadUrl('index2.html')");
|
runTestOnUiThread(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
testView.sendJavascript("loadUrl('index2.html')");
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
String url = testView.getUrl();
|
runTestOnUiThread(new Runnable() {
|
||||||
testView.backHistory();
|
public void run()
|
||||||
|
{
|
||||||
|
String url = testView.getUrl();
|
||||||
|
testView.backHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
sleep(1000);
|
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) {
|
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