CB-578 - Adding a test of pause and resume to make sure that they're being called. Need to elaborate on this

This commit is contained in:
Joe Bowser 2012-08-03 14:07:01 -07:00
parent 81ab0a414f
commit d3dc94c04b
4 changed files with 33 additions and 2 deletions

View File

@ -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;

View File

@ -8,4 +8,4 @@
# project structure.
# Project target.
target=Google Inc.:Google APIs:15
target=android-16

View File

@ -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");
}
}
}

View File

@ -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 {