mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
CB-1864: Figured out how to simulate back button, test both the CordovaWebView back button and the general DroidGap case using the default implementation
This commit is contained in:
parent
f4612fdb5d
commit
6c19a440f5
@ -26,6 +26,7 @@ import org.apache.cordova.test.actions.backbuttonmultipage;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.BaseInputConnection;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@ -97,6 +98,54 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
||||
assertTrue(didGoBack);
|
||||
}
|
||||
|
||||
public void testViaBackButtonOnView() {
|
||||
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"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
|
||||
public void testViaBackButtonOnLayout() {
|
||||
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"));
|
||||
BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
|
||||
KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
|
||||
KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("sample2.html"));
|
||||
viewConnection.sendKeyEvent(backDown);
|
||||
viewConnection.sendKeyEvent(backUp);
|
||||
sleep();
|
||||
url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(TIMEOUT);
|
||||
|
Loading…
Reference in New Issue
Block a user