Index: android_webview/javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java |
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java |
index ceac32826aba553e8992de03bcc4c6075babda65..30c9a5647443e09ac29993b18909ee427a65a174 100644 |
--- a/android_webview/javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java |
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java |
@@ -5,12 +5,14 @@ |
package org.chromium.android_webview.test; |
import android.test.FlakyTest; |
+import android.test.suitebuilder.annotation.MediumTest; |
import android.test.suitebuilder.annotation.SmallTest; |
import org.chromium.android_webview.AwContents; |
import org.chromium.android_webview.test.util.CommonResources; |
import org.chromium.base.ThreadUtils; |
import org.chromium.base.test.util.DisabledTest; |
+import org.chromium.base.test.util.Feature; |
import org.chromium.content.browser.NavigationEntry; |
import org.chromium.content.browser.NavigationHistory; |
import org.chromium.content.browser.test.util.HistoryUtils; |
@@ -26,6 +28,11 @@ public class NavigationHistoryTest extends AwTestBase { |
private static final String PAGE_2_PATH = "/page2.html"; |
private static final String PAGE_2_TITLE = "Page 2 Title"; |
private static final String PAGE_WITH_HASHTAG_REDIRECT_TITLE = "Page with hashtag"; |
+ private static final String LOGIN_PAGE_PATH = "/login.html"; |
+ private static final String LOGIN_PAGE_TITLE = "Login page"; |
+ private static final String LOGIN_RESPONSE_PAGE_PATH = "/login-response.html"; |
+ private static final String LOGIN_RESPONSE_PAGE_TITLE = "Login response"; |
+ private static final String LOGIN_RESPONSE_PAGE_HELP_LINK_ID = "help"; |
private TestWebServer mWebServer; |
private TestAwContentsClient mContentsClient; |
@@ -209,4 +216,94 @@ public class NavigationHistoryTest extends AwTestBase { |
// Make sure the first entry is still okay. |
checkHistoryItem(list.getEntryAtIndex(0), url, url, "", false); |
} |
+ |
+ private String addNoncacheableLoginPageToServer(TestWebServer webServer) { |
+ final String submitButtonId = "submit"; |
+ final String loginPageHtml = |
+ "<html>" + |
+ " <head>" + |
+ " <title>" + LOGIN_PAGE_TITLE + "</title>" + |
+ " <script>" + |
+ " function startAction() {" + |
+ " button = document.getElementById('" + submitButtonId + "');" + |
+ " button.click();" + |
+ " }" + |
+ " </script>" + |
+ " </head>" + |
+ " <body onload='setTimeout(startAction, 0)'>" + |
+ " <form action='" + LOGIN_RESPONSE_PAGE_PATH.substring(1) + "' method='post'>" + |
+ " <input type='text' name='login'>" + |
+ " <input id='" + submitButtonId + "' type='submit' value='Submit'>" + |
+ " </form>" + |
+ " </body>" + |
+ "</html>"; |
+ return mWebServer.setResponse(LOGIN_PAGE_PATH, |
+ loginPageHtml, |
+ CommonResources.getTextHtmlHeaders(true)); |
+ } |
+ |
+ private String addNoncacheableLoginResponsePageToServer(TestWebServer webServer) { |
+ final String loginResponsePageHtml = |
+ "<html>" + |
+ " <head>" + |
+ " <title>" + LOGIN_RESPONSE_PAGE_TITLE + "</title>" + |
+ " </head>" + |
+ " <body>" + |
+ " Login incorrect" + |
+ " <div><a id='" + LOGIN_RESPONSE_PAGE_HELP_LINK_ID + "' href='" + |
+ PAGE_1_PATH.substring(1) + "'>Help</a></div>'" + |
+ " </body>" + |
+ "</html>"; |
+ return mWebServer.setResponse(LOGIN_RESPONSE_PAGE_PATH, |
+ loginResponsePageHtml, |
+ CommonResources.getTextHtmlHeaders(true)); |
+ } |
+ |
+ // This test simulates Google login page behavior. The page is non-cacheable |
+ // and uses POST method for submission. It also contains a help link, leading |
+ // to another page. We are verifying that it is possible to go back to the |
+ // submitted login page after visiting the help page. |
+ @MediumTest |
+ @Feature({"AndroidWebView"}) |
+ public void testNavigateBackToNoncacheableLoginPage() throws Throwable { |
+ final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
+ mContentsClient.getOnPageFinishedHelper(); |
+ |
+ final String loginPageUrl = addNoncacheableLoginPageToServer(mWebServer); |
+ final String loginResponsePageUrl = addNoncacheableLoginResponsePageToServer(mWebServer); |
+ final String page1Url = addPage1ToServer(mWebServer); |
+ |
+ getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); |
+ loadUrlSync(mAwContents, onPageFinishedHelper, loginPageUrl); |
+ // Since the page performs an async action, we can't rely on callbacks. |
+ assertTrue(pollOnUiThread(new Callable<Boolean>() { |
+ @Override |
+ public Boolean call() { |
+ String title = mAwContents.getContentViewCore().getTitle(); |
+ return LOGIN_RESPONSE_PAGE_TITLE.equals(title); |
+ } |
+ })); |
+ executeJavaScriptAndWaitForResult(mAwContents, |
+ mContentsClient, |
+ "link = document.getElementById('" + LOGIN_RESPONSE_PAGE_HELP_LINK_ID + "');" + |
+ "link.click();"); |
+ assertTrue(pollOnUiThread(new Callable<Boolean>() { |
+ @Override |
+ public Boolean call() { |
+ String title = mAwContents.getContentViewCore().getTitle(); |
+ return PAGE_1_TITLE.equals(title); |
+ } |
+ })); |
+ // Verify that we can still go back to the login response page despite that |
+ // it is non-cacheable. |
+ HistoryUtils.goBackSync(getInstrumentation(), mAwContents.getContentViewCore(), |
+ onPageFinishedHelper); |
+ assertTrue(pollOnUiThread(new Callable<Boolean>() { |
+ @Override |
+ public Boolean call() { |
+ String title = mAwContents.getContentViewCore().getTitle(); |
+ return LOGIN_RESPONSE_PAGE_TITLE.equals(title); |
+ } |
+ })); |
+ } |
} |