mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
test(java): remove duplicate code in BackButtonMultipageTest (#1129)
* Removed duplicate code in test * test: Remove duplicate code in BackButtonMultipageTest Authored-by: leofernandesmo <leonardo.fernandes@ifal.edu.br> Co-authored-by: breautek <norman@nbsolutions.ca>
This commit is contained in:
parent
b245337501
commit
97e2d15634
@ -45,6 +45,8 @@ import static org.apache.cordova.unittests.R.id.cordovaWebView;
|
|||||||
public class BackButtonMultipageTest {
|
public class BackButtonMultipageTest {
|
||||||
|
|
||||||
private static final String START_URL = "file:///android_asset/www/backbuttonmultipage/index.html";
|
private static final String START_URL = "file:///android_asset/www/backbuttonmultipage/index.html";
|
||||||
|
private static final String SAMPLE3_URL = "file:///android_asset/www/backbuttonmultipage/sample3.html";
|
||||||
|
private static final String SAMPLE2_URL = "file:///android_asset/www/backbuttonmultipage/sample2.html";
|
||||||
//I have no idea why we picked 100, but we did.
|
//I have no idea why we picked 100, but we did.
|
||||||
private static final int WEBVIEW_ID = 100;
|
private static final int WEBVIEW_ID = 100;
|
||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
@ -71,19 +73,19 @@ public class BackButtonMultipageTest {
|
|||||||
webInterface.sendJavascript("window.location = 'sample2.html';");
|
webInterface.sendJavascript("window.location = 'sample2.html';");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.sendJavascript("window.location = 'sample3.html';");
|
webInterface.sendJavascript("window.location = 'sample3.html';");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE3_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
@ -104,22 +106,22 @@ public class BackButtonMultipageTest {
|
|||||||
|
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
webInterface.loadUrl(SAMPLE2_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
webInterface.loadUrl(SAMPLE3_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE3_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
@ -140,19 +142,24 @@ public class BackButtonMultipageTest {
|
|||||||
|
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
webInterface.loadUrl(SAMPLE2_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
webInterface.loadUrl(SAMPLE3_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE3_URL);
|
||||||
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
||||||
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
|
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertPageSample(String url) {
|
||||||
|
assertEquals(url, mActivity.onPageFinishedUrl.take());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@ import static org.apache.cordova.unittests.R.id.cordovaWebView;
|
|||||||
public class BackButtonMultipageTest {
|
public class BackButtonMultipageTest {
|
||||||
|
|
||||||
private static final String START_URL = "file:///android_asset/www/backbuttonmultipage/index.html";
|
private static final String START_URL = "file:///android_asset/www/backbuttonmultipage/index.html";
|
||||||
|
private static final String SAMPLE3_URL = "file:///android_asset/www/backbuttonmultipage/sample3.html";
|
||||||
|
private static final String SAMPLE2_URL = "file:///android_asset/www/backbuttonmultipage/sample2.html";
|
||||||
//I have no idea why we picked 100, but we did.
|
//I have no idea why we picked 100, but we did.
|
||||||
private static final int WEBVIEW_ID = 100;
|
private static final int WEBVIEW_ID = 100;
|
||||||
private TestActivity mActivity;
|
private TestActivity mActivity;
|
||||||
@ -71,19 +73,19 @@ public class BackButtonMultipageTest {
|
|||||||
webInterface.sendJavascript("window.location = 'sample2.html';");
|
webInterface.sendJavascript("window.location = 'sample2.html';");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.sendJavascript("window.location = 'sample3.html';");
|
webInterface.sendJavascript("window.location = 'sample3.html';");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE3_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
@ -104,22 +106,22 @@ public class BackButtonMultipageTest {
|
|||||||
|
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
webInterface.loadUrl(SAMPLE2_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
webInterface.loadUrl(SAMPLE3_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE3_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
assertTrue(webInterface.backHistory());
|
assertTrue(webInterface.backHistory());
|
||||||
@ -140,19 +142,23 @@ public class BackButtonMultipageTest {
|
|||||||
|
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
|
webInterface.loadUrl(SAMPLE2_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
mActivityRule.runOnUiThread(new Runnable() {
|
mActivityRule.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
|
webInterface.loadUrl(SAMPLE3_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE3_URL);
|
||||||
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
||||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
|
assertPageSample(SAMPLE2_URL);
|
||||||
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
onView(withId(WEBVIEW_ID)).perform(pressBack());
|
||||||
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
|
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertPageSample(String url) {
|
||||||
|
assertEquals(url, mActivity.onPageFinishedUrl.take());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user