mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
[CB-574] Added backbutton automated unit test for android.
This commit is contained in:
parent
f9d9a0a4bd
commit
e0a5fe4002
@ -35,7 +35,6 @@ $
|
|||||||
<h4>Page 3</h4>
|
<h4>Page 3</h4>
|
||||||
Press the 3 buttons below. You should stay on same page.<br>
|
Press the 3 buttons below. You should stay on same page.<br>
|
||||||
Press "backbutton" 4 times. This will go back to #test3, #test2, #test1, then return to previous Page 2.<br>
|
Press "backbutton" 4 times. This will go back to #test3, #test2, #test1, then return to previous Page 2.<br>
|
||||||
(NOTE: IS THIS CORRECT BEHAVIOR?)
|
|
||||||
</div>
|
</div>
|
||||||
<a href="sample3.html#test1" class="btn large">page3#test1</a>
|
<a href="sample3.html#test1" class="btn large">page3#test1</a>
|
||||||
<a href="sample3.html#test2" class="btn large">page3#test2</a>
|
<a href="sample3.html#test2" class="btn large">page3#test2</a>
|
||||||
|
4
test/assets/www/cordova.js
vendored
4
test/assets/www/cordova.js
vendored
@ -17,5 +17,5 @@
|
|||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
document.write('<script type="text/javascript" charset="utf-8" src="../cordova-1.7.0.js"></script>');
|
document.write('<script type="text/javascript" charset="utf-8" src="../cordova.android.js"></script>');
|
||||||
document.write('<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>');
|
document.write('<script type="text/javascript" charset="utf-8" src="cordova.android.js"></script>');
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
package org.apache.cordova.test;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
|
|
||||||
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<backbuttonmultipage> {
|
||||||
|
|
||||||
|
private int TIMEOUT = 1000;
|
||||||
|
backbuttonmultipage testActivity;
|
||||||
|
private FrameLayout containerView;
|
||||||
|
private LinearLayout innerContainer;
|
||||||
|
private CordovaWebView testView;
|
||||||
|
|
||||||
|
|
||||||
|
public BackButtonMultiPageTest() {
|
||||||
|
super("org.apache.cordova.test", backbuttonmultipage.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
testActivity = this.getActivity();
|
||||||
|
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
||||||
|
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
||||||
|
testView = (CordovaWebView) innerContainer.getChildAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPreconditions(){
|
||||||
|
assertNotNull(innerContainer);
|
||||||
|
assertNotNull(testView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testViaHref() {
|
||||||
|
testView.sendJavascript("window.location = 'sample2.html';");
|
||||||
|
sleep();
|
||||||
|
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();
|
||||||
|
sleep();
|
||||||
|
url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
assertTrue(didGoBack);
|
||||||
|
didGoBack = testView.backHistory();
|
||||||
|
sleep();
|
||||||
|
url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("index.html"));
|
||||||
|
assertTrue(didGoBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testViaLoadUrl() {
|
||||||
|
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");
|
||||||
|
sleep();
|
||||||
|
url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample3.html"));
|
||||||
|
boolean didGoBack = testView.backHistory();
|
||||||
|
sleep();
|
||||||
|
url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("sample2.html"));
|
||||||
|
assertTrue(didGoBack);
|
||||||
|
didGoBack = testView.backHistory();
|
||||||
|
sleep();
|
||||||
|
url = testView.getUrl();
|
||||||
|
assertTrue(url.endsWith("index.html"));
|
||||||
|
assertTrue(didGoBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sleep() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(TIMEOUT);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
fail("Unexpected Timeout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cordova.test;
|
|
||||||
|
|
||||||
import org.openqa.selenium.android.library.ViewAdapter;
|
|
||||||
import org.openqa.selenium.android.library.ViewFactory;
|
|
||||||
|
|
||||||
import org.apache.cordova.CordovaWebView;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
public class CordovaViewFactory implements ViewFactory {
|
|
||||||
|
|
||||||
public ViewAdapter createNewView(Activity arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return new ViewAdapter("org.apache.cordova.CordovaWebView", new CordovaWebView(arg0));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -44,11 +44,11 @@ public class ErrorUrlTest extends ActivityInstrumentationTestCase2<errorurl> {
|
|||||||
|
|
||||||
private void sleep() {
|
private void sleep() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TIMEOUT);
|
Thread.sleep(TIMEOUT);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
fail("Unexpected Timeout");
|
fail("Unexpected Timeout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cordova.test;
|
|
||||||
|
|
||||||
import org.apache.cordova.CordovaWebViewClient;
|
|
||||||
import org.apache.cordova.CordovaWebView;
|
|
||||||
import org.apache.cordova.CordovaChromeClient;
|
|
||||||
|
|
||||||
import org.apache.cordova.test.CordovaViewFactory;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.android.library.AndroidWebDriver;
|
|
||||||
import org.openqa.selenium.android.library.ChromeClientWrapper;
|
|
||||||
import org.openqa.selenium.android.library.ViewClientWrapper;
|
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
|
||||||
|
|
||||||
public class WebDriverTest extends ActivityInstrumentationTestCase2<CordovaDriverAction> {
|
|
||||||
|
|
||||||
private static final long TIMEOUT = 5000;
|
|
||||||
private CordovaDriverAction testActivity;
|
|
||||||
private CordovaWebView testView;
|
|
||||||
private CordovaViewFactory viewFactory;
|
|
||||||
private CordovaChromeClient appCode;
|
|
||||||
private CordovaWebViewClient viewHandler;
|
|
||||||
private AndroidWebDriver testDriver;
|
|
||||||
private ViewClientWrapper viewClientWrapper;
|
|
||||||
private ChromeClientWrapper chromeClientWrapper;
|
|
||||||
|
|
||||||
public WebDriverTest() {
|
|
||||||
super("com.phonegap.test.activities",CordovaDriverAction.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setUp() throws Exception{
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
testActivity = this.getActivity();
|
|
||||||
viewFactory = new CordovaViewFactory();
|
|
||||||
appCode = new CordovaChromeClient(testActivity);
|
|
||||||
viewHandler = new CordovaWebViewClient(testActivity);
|
|
||||||
viewClientWrapper = new ViewClientWrapper("org.apache.cordova.CordovaWebViewClient", viewHandler);
|
|
||||||
chromeClientWrapper = new ChromeClientWrapper("org.apache.cordova.CordovaChromeClient", appCode);
|
|
||||||
testDriver = new AndroidWebDriver(testActivity, viewFactory, viewClientWrapper, chromeClientWrapper);
|
|
||||||
testView = (CordovaWebView) testDriver.getWebView();
|
|
||||||
viewHandler.setWebView(testView);
|
|
||||||
appCode.setWebView(testView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPreconditions(){
|
|
||||||
assertNotNull(testView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWebLoad() {
|
|
||||||
testDriver.get("file:///android_asset/www/index.html");
|
|
||||||
sleep();
|
|
||||||
String url = testView.getUrl();
|
|
||||||
//Check the sanity!
|
|
||||||
boolean result = url.equals("file:///android_asset/www/index.html");
|
|
||||||
assertTrue(result);
|
|
||||||
WebElement platformSpan = testDriver.findElement(By.id("platform"));
|
|
||||||
String text = platformSpan.getText();
|
|
||||||
assertTrue(text.equals("Android"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void sleep() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TIMEOUT);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
fail("Unexpected Timeout");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user