Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(java): remove duplicate code in BackButtonMultipageTest #1129

Merged
merged 2 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Licensed to the Apache Software Foundation (ASF) under one
public class BackButtonMultipageTest {

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.
private static final int WEBVIEW_ID = 100;
private TestActivity mActivity;
Expand All @@ -71,19 +73,19 @@ public void run() {
webInterface.sendJavascript("window.location = 'sample2.html';");
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
webInterface.sendJavascript("window.location = 'sample3.html';");
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE3_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
Expand All @@ -104,22 +106,22 @@ public void testViaLoadUrl() throws Throwable {

mActivityRule.runOnUiThread(new Runnable() {
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() {
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() {
public void run() {
assertTrue(webInterface.backHistory());
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
Expand All @@ -140,19 +142,24 @@ public void testViaBackButtonOnView() throws Throwable {

mActivityRule.runOnUiThread(new Runnable() {
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() {
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());
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
onView(withId(WEBVIEW_ID)).perform(pressBack());
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
}

private void assertPageSample(String url) {
assertEquals(url, mActivity.onPageFinishedUrl.take());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Licensed to the Apache Software Foundation (ASF) under one
public class BackButtonMultipageTest {

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.
private static final int WEBVIEW_ID = 100;
private TestActivity mActivity;
Expand All @@ -71,19 +73,19 @@ public void run() {
webInterface.sendJavascript("window.location = 'sample2.html';");
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
webInterface.sendJavascript("window.location = 'sample3.html';");
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE3_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
Expand All @@ -104,22 +106,22 @@ public void testViaLoadUrl() throws Throwable {

mActivityRule.runOnUiThread(new Runnable() {
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() {
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() {
public void run() {
assertTrue(webInterface.backHistory());
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
Expand All @@ -140,19 +142,23 @@ public void testViaBackButtonOnView() throws Throwable {

mActivityRule.runOnUiThread(new Runnable() {
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() {
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());
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
assertPageSample(SAMPLE2_URL);
onView(withId(WEBVIEW_ID)).perform(pressBack());
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
}

private void assertPageSample(String url) {
assertEquals(url, mActivity.onPageFinishedUrl.take());
}
}