diff --git a/test/assets/www/backbuttonmultipage/sample3.html b/test/assets/www/backbuttonmultipage/sample3.html index ba2b4640..f4b1f8a9 100755 --- a/test/assets/www/backbuttonmultipage/sample3.html +++ b/test/assets/www/backbuttonmultipage/sample3.html @@ -35,7 +35,6 @@ $

Page 3

Press the 3 buttons below. You should stay on same page.
Press "backbutton" 4 times. This will go back to #test3, #test2, #test1, then return to previous Page 2.
- (NOTE: IS THIS CORRECT BEHAVIOR?) page3#test1 page3#test2 diff --git a/test/assets/www/cordova.js b/test/assets/www/cordova.js index 874ed18a..03dae062 100755 --- a/test/assets/www/cordova.js +++ b/test/assets/www/cordova.js @@ -17,5 +17,5 @@ under the License. */ -document.write(''); -document.write(''); +document.write(''); +document.write(''); diff --git a/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java b/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java new file mode 100644 index 00000000..f8850e6a --- /dev/null +++ b/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java @@ -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 { + + 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"); + } + } + +} + diff --git a/test/src/org/apache/cordova/test/CordovaViewFactory.java b/test/src/org/apache/cordova/test/CordovaViewFactory.java deleted file mode 100644 index 99686f24..00000000 --- a/test/src/org/apache/cordova/test/CordovaViewFactory.java +++ /dev/null @@ -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)); - } - -} diff --git a/test/src/org/apache/cordova/test/ErrorUrlTest.java b/test/src/org/apache/cordova/test/ErrorUrlTest.java index 59b1742e..4d43e7c2 100644 --- a/test/src/org/apache/cordova/test/ErrorUrlTest.java +++ b/test/src/org/apache/cordova/test/ErrorUrlTest.java @@ -44,11 +44,11 @@ public class ErrorUrlTest extends ActivityInstrumentationTestCase2 { private void sleep() { try { - Thread.sleep(TIMEOUT); + Thread.sleep(TIMEOUT); } catch (InterruptedException e) { - fail("Unexpected Timeout"); + fail("Unexpected Timeout"); } - } + } } diff --git a/test/src/org/apache/cordova/test/WebDriverTest.java b/test/src/org/apache/cordova/test/WebDriverTest.java deleted file mode 100644 index 6b39e084..00000000 --- a/test/src/org/apache/cordova/test/WebDriverTest.java +++ /dev/null @@ -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 { - - 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"); - } - } -}