incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [2/2] android commit: CB-578 - Adding a test of pause and resume to make sure that they're being called. Need to elaborate on this
Date Fri, 03 Aug 2012 21:09:01 GMT
CB-578 - Adding a test of pause and resume to make sure that they're being called. Need to
elaborate on this


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/d3dc94c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/d3dc94c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/d3dc94c0

Branch: refs/heads/master
Commit: d3dc94c04be6ba43945e0aea5be3daab50789a31
Parents: 81ab0a4
Author: Joe Bowser <bowserj@apache.org>
Authored: Fri Aug 3 14:07:01 2012 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Fri Aug 3 14:07:01 2012 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |    8 +++++
 test/project.properties                            |    2 +-
 .../apache/cordova/test/CordovaActivityTest.java   |   23 ++++++++++++++-
 test/src/org/apache/cordova/test/CordovaTest.java  |    2 +
 4 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3dc94c0/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index fe677f4..f7f2be6 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -57,6 +57,7 @@ public class CordovaWebView extends WebView {
 
     public PluginManager pluginManager;
     public CallbackServer callbackServer;
+    private boolean paused;
 
 
     /** Actvities and other important classes **/
@@ -817,6 +818,7 @@ public class CordovaWebView extends WebView {
             // Pause JavaScript timers (including setInterval)
             this.pauseTimers();
         }
+        paused = true;
    
     }
     
@@ -836,6 +838,7 @@ public class CordovaWebView extends WebView {
             // Resume JavaScript timers (including setInterval)
             this.resumeTimers();
         }
+        paused = false;
     }
     
     public void handleDestroy()
@@ -859,6 +862,11 @@ public class CordovaWebView extends WebView {
             this.pluginManager.onNewIntent(intent);
         }
     }
+    
+    public boolean isPaused()
+    {
+        return paused;
+    }
 
     public boolean hadKeyEvent() {
         return handleButton;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3dc94c0/test/project.properties
----------------------------------------------------------------------
diff --git a/test/project.properties b/test/project.properties
index 9aa0dfa..895c9ce 100644
--- a/test/project.properties
+++ b/test/project.properties
@@ -8,4 +8,4 @@
 # project structure.
 
 # Project target.
-target=Google Inc.:Google APIs:15
+target=android-16

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3dc94c0/test/src/org/apache/cordova/test/CordovaActivityTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/CordovaActivityTest.java b/test/src/org/apache/cordova/test/CordovaActivityTest.java
index b53f000..766dd53 100644
--- a/test/src/org/apache/cordova/test/CordovaActivityTest.java
+++ b/test/src/org/apache/cordova/test/CordovaActivityTest.java
@@ -22,6 +22,7 @@ package org.apache.cordova.test;
 import org.apache.cordova.CordovaWebView;
 import com.phonegap.api.PluginManager;
 
+import android.app.Instrumentation;
 import android.test.ActivityInstrumentationTestCase2;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
@@ -32,6 +33,8 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
     private FrameLayout containerView;
     private LinearLayout innerContainer;
     private CordovaWebView testView;
+    private Instrumentation mInstr;
+    private int TIMEOUT = 1000;
     
     @SuppressWarnings("deprecation")
     public CordovaActivityTest()
@@ -41,6 +44,7 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
     
     protected void setUp() throws Exception {
         super.setUp();
+        mInstr = this.getInstrumentation();
         testActivity = this.getActivity();
         containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
         innerContainer = (LinearLayout) containerView.getChildAt(0);
@@ -63,6 +67,23 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
         String className = innerContainer.getClass().getSimpleName();
         assertTrue(className.equals("LinearLayoutSoftKeyboardDetect"));
     }
+    
 
-
+    public void testPauseAndResume()
+    {
+        mInstr.callActivityOnPause(testActivity);
+        sleep();
+        assertTrue(testView.isPaused());
+        mInstr.callActivityOnResume(testActivity);
+        sleep();
+        assertFalse(testView.isPaused());
+    }
+    
+    private void sleep() {
+        try {
+          Thread.sleep(TIMEOUT);
+        } catch (InterruptedException e) {
+          fail("Unexpected Timeout");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/d3dc94c0/test/src/org/apache/cordova/test/CordovaTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/CordovaTest.java b/test/src/org/apache/cordova/test/CordovaTest.java
index b7edd09..4a24792 100644
--- a/test/src/org/apache/cordova/test/CordovaTest.java
+++ b/test/src/org/apache/cordova/test/CordovaTest.java
@@ -21,6 +21,7 @@ package org.apache.cordova.test;
 import org.apache.cordova.CordovaWebView;
 import com.phonegap.api.PluginManager;
 
+import android.app.Instrumentation;
 import android.test.ActivityInstrumentationTestCase2;
 import android.view.View;
 
@@ -98,6 +99,7 @@ public class CordovaTest extends
     assertTrue(url.equals("file:///android_asset/www/index.html"));
   }
   */
+  
 
   private void sleep() {
     try {


Mime
View raw message