cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject [03/33] git commit: Add Timeout Tests
Date Mon, 03 Feb 2014 18:37:16 GMT
Add Timeout Tests

https://issues.labcollab.net/browse/ATLS-691

Conflicts:

	test/res/xml/config.xml

Update CordovaTimeOut path to replicate android.


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/5273423b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/5273423b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/5273423b

Branch: refs/heads/master
Commit: 5273423bb6881784224bc734c411788b3cbcae5a
Parents: 26c4e32
Author: Digvijay Dalapathi <digvijay@lab126.com>
Authored: Wed Nov 27 15:11:57 2013 -0800
Committer: Archana Naik <naika@lab126.com>
Committed: Fri Jan 31 14:47:05 2014 -0800

----------------------------------------------------------------------
 test/AndroidManifest.xml                        | 10 ++
 test/res/xml/config.xml                         |  6 +-
 .../cordova/test/junit/CordovaTimeoutTest.java  | 99 ++++++++++++++++++++
 test/src/org/apache/cordova/test/loadurl.java   | 13 +++
 4 files changed, 127 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/5273423b/test/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/test/AndroidManifest.xml b/test/AndroidManifest.xml
index 8815624..83128ff 100755
--- a/test/AndroidManifest.xml
+++ b/test/AndroidManifest.xml
@@ -256,6 +256,16 @@
                 <category android:name="android.intent.category.SAMPLE_CODE" />
             </intent-filter>
         </activity>
+        <activity
+            android:windowSoftInputMode="adjustPan"
+            android:label="@string/app_name" 
+            android:configChanges="orientation|keyboardHidden"
+            android:name="org.apache.cordova.test.loadurl" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
                 <!-- This is required for the Tests to work with AmazonWebView -->
         <amazon:enable-feature 
             android:name="com.amazon.webview" 

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/5273423b/test/res/xml/config.xml
----------------------------------------------------------------------
diff --git a/test/res/xml/config.xml b/test/res/xml/config.xml
index 1986cff..6edf358 100644
--- a/test/res/xml/config.xml
+++ b/test/res/xml/config.xml
@@ -6,7 +6,11 @@
     </description>
     <author email="dev@cordova.apache.org" href="http://cordova.io">
     </author>
-    <access origin="*.apache.org" />
+    
+    <access origin="*.apache.org"/>
+    <access origin="http://www.flickr.com/explore" />
+
+    <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
     <content src="index.html" />
     <log level="DEBUG" />
     <preference name="useBrowserHistory" value="true" />

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/5273423b/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java b/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java
new file mode 100644
index 0000000..6978dfc
--- /dev/null
+++ b/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java
@@ -0,0 +1,99 @@
+package org.apache.cordova.test.junit;
+
+import org.apache.cordova.CordovaWebView;
+import org.apache.cordova.test.AmazonWebViewOnUiThread;
+import org.apache.cordova.test.loadurl;
+
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+
+public class CordovaTimeoutTest extends
+		ActivityInstrumentationTestCase2<loadurl> {
+
+	private int SLEEPTIME = 10000;
+	private static final String ERROR_URL = "file:///android_asset/www/htmlnotfound/error.html";
+	private static final String TEST_URL = "http://www.flickr.com/explore";
+
+	loadurl testActivity;
+	private FrameLayout containerView;
+	private LinearLayout innerContainer;
+	private CordovaWebView testView;
+
+	private AmazonWebViewOnUiThread mUiThread;
+
+	public CordovaTimeoutTest() {
+		super("org.apache.cordova.test.actions", loadurl.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);
+		mUiThread = new AmazonWebViewOnUiThread(this, testView);
+	}
+
+	public void testPreconditions() {
+		assertNotNull(innerContainer);
+		assertNotNull(testView);
+	}
+
+	/**
+	 * Verify that timeout error occurs and a error page is loaded when set.
+	 */
+	public void testTimeOutErrorOccurs() {
+		// Set the timeout value small so that error occurs
+		this.getActivity().setStringProperty("loadUrlTimeoutValue", "500");
+		this.getActivity().setStringProperty("errorUrl",
+				"file:///android_asset/www/htmlnotfound/error.html");
+		mUiThread.loadUrl(TEST_URL);
+		sleep();
+		String url = mUiThread.getUrl();
+		assertNotNull(url);
+		assertTrue(url.equals(ERROR_URL));
+	}
+
+	/**
+	 * Verify that timeout does not occur for default timeout
+	 */
+	public void testTimeOutErrorDoesNotOccur() {
+		// With default timeout= 20000ms verify error does not occur and
+		// page loads
+		this.getActivity().setStringProperty("errorUrl",
+				"file:///android_asset/www/htmlnotfound/error.html");
+		mUiThread.loadUrl(TEST_URL);
+		sleep();
+		String url = mUiThread.getUrl();
+		assertNotNull(url);
+		assertTrue(url.equals(TEST_URL));
+
+	}
+
+	/**
+	 * Verify if a error splash screen is showing when the error page is not set
+	 */
+	public void testErrorDialogShows() {
+		this.getActivity().setStringProperty("loadUrlTimeoutValue", "500");
+		mUiThread.loadUrl(TEST_URL);
+		sleep();
+		String url = mUiThread.getUrl();
+		assertNotNull(url);
+		assertFalse(this.getActivity().hasWindowFocus());
+	}
+
+	/**
+	 * Sleep to make sure URL loads completely
+	 */
+	private void sleep() {
+		try {
+			Thread.sleep(SLEEPTIME);
+		} catch (InterruptedException e) {
+			fail("Unexpected Timeout");
+		}
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/5273423b/test/src/org/apache/cordova/test/loadurl.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/loadurl.java b/test/src/org/apache/cordova/test/loadurl.java
new file mode 100644
index 0000000..deddc37
--- /dev/null
+++ b/test/src/org/apache/cordova/test/loadurl.java
@@ -0,0 +1,13 @@
+package org.apache.cordova.test;
+
+import android.os.Bundle;
+import org.apache.cordova.*;
+
+public class loadurl extends CordovaActivity {
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		super.loadUrl(Config.getStartUrl());
+	}
+
+}


Mime
View raw message