forked from github/cordova-android
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:
parent
81ab0a414f
commit
d3dc94c04b
@ -57,6 +57,7 @@ public class CordovaWebView extends WebView {
|
|||||||
|
|
||||||
public PluginManager pluginManager;
|
public PluginManager pluginManager;
|
||||||
public CallbackServer callbackServer;
|
public CallbackServer callbackServer;
|
||||||
|
private boolean paused;
|
||||||
|
|
||||||
|
|
||||||
/** Actvities and other important classes **/
|
/** Actvities and other important classes **/
|
||||||
@ -817,6 +818,7 @@ public class CordovaWebView extends WebView {
|
|||||||
// Pause JavaScript timers (including setInterval)
|
// Pause JavaScript timers (including setInterval)
|
||||||
this.pauseTimers();
|
this.pauseTimers();
|
||||||
}
|
}
|
||||||
|
paused = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,6 +838,7 @@ public class CordovaWebView extends WebView {
|
|||||||
// Resume JavaScript timers (including setInterval)
|
// Resume JavaScript timers (including setInterval)
|
||||||
this.resumeTimers();
|
this.resumeTimers();
|
||||||
}
|
}
|
||||||
|
paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleDestroy()
|
public void handleDestroy()
|
||||||
@ -860,6 +863,11 @@ public class CordovaWebView extends WebView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPaused()
|
||||||
|
{
|
||||||
|
return paused;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hadKeyEvent() {
|
public boolean hadKeyEvent() {
|
||||||
return handleButton;
|
return handleButton;
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
# project structure.
|
# project structure.
|
||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=Google Inc.:Google APIs:15
|
target=android-16
|
||||||
|
@ -22,6 +22,7 @@ package org.apache.cordova.test;
|
|||||||
import org.apache.cordova.CordovaWebView;
|
import org.apache.cordova.CordovaWebView;
|
||||||
import com.phonegap.api.PluginManager;
|
import com.phonegap.api.PluginManager;
|
||||||
|
|
||||||
|
import android.app.Instrumentation;
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -32,6 +33,8 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
|
|||||||
private FrameLayout containerView;
|
private FrameLayout containerView;
|
||||||
private LinearLayout innerContainer;
|
private LinearLayout innerContainer;
|
||||||
private CordovaWebView testView;
|
private CordovaWebView testView;
|
||||||
|
private Instrumentation mInstr;
|
||||||
|
private int TIMEOUT = 1000;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public CordovaActivityTest()
|
public CordovaActivityTest()
|
||||||
@ -41,6 +44,7 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
|
|||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
mInstr = this.getInstrumentation();
|
||||||
testActivity = this.getActivity();
|
testActivity = this.getActivity();
|
||||||
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
||||||
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
||||||
@ -65,4 +69,21 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package org.apache.cordova.test;
|
|||||||
import org.apache.cordova.CordovaWebView;
|
import org.apache.cordova.CordovaWebView;
|
||||||
import com.phonegap.api.PluginManager;
|
import com.phonegap.api.PluginManager;
|
||||||
|
|
||||||
|
import android.app.Instrumentation;
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@ -99,6 +100,7 @@ public class CordovaTest extends
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
private void sleep() {
|
private void sleep() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(TIMEOUT);
|
Thread.sleep(TIMEOUT);
|
||||||
|
Loading…
Reference in New Issue
Block a user