summaryrefslogtreecommitdiff
path: root/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java')
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
index d2db7ddad7..2b40274878 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
@@ -508,4 +508,54 @@ public class AwContentsTest extends AwTestBase {
}
}
+ // TODO(hush): more ssl tests. And put the ssl tests into a separate test
+ // class.
+ @Feature({"AndroidWebView"})
+ @SmallTest
+ // If the user allows the ssl error, the same ssl error will not trigger
+ // the onReceivedSslError callback; If the user denies it, the same ssl
+ // error will still trigger the onReceivedSslError callback.
+ public void testSslPreferences() throws Throwable {
+ final AwTestContainerView testContainer =
+ createAwTestContainerViewOnMainSync(mContentsClient);
+ final AwContents awContents = testContainer.getAwContents();
+ TestWebServer webServer = TestWebServer.startSsl();
+ final String pagePath = "/hello.html";
+ final String pageUrl =
+ webServer.setResponse(pagePath, "<html><body>hello world</body></html>", null);
+ final CallbackHelper onReceivedSslErrorHelper =
+ mContentsClient.getOnReceivedSslErrorHelper();
+ int onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount();
+
+ loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+
+ assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCount());
+ assertEquals(1, webServer.getRequestCount(pagePath));
+
+ // Now load the page again. This time, we expect no ssl error, because
+ // user's decision should be remembered.
+ onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount();
+ loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+ assertEquals(onSslErrorCallCount, onReceivedSslErrorHelper.getCallCount());
+
+ // Now clear the ssl preferences then load the same url again. Expect to see
+ // onReceivedSslError getting called again.
+ awContents.clearSslPreferences();
+ onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount();
+ loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+ assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCount());
+
+ // Now clear the stored decisions and tell the client to deny ssl errors.
+ awContents.clearSslPreferences();
+ mContentsClient.setAllowSslError(false);
+ onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount();
+ loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+ assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCount());
+
+ // Now load the same page again. This time, we still expect onReceivedSslError,
+ // because we only remember user's decision if it is "allow".
+ onSslErrorCallCount = onReceivedSslErrorHelper.getCallCount();
+ loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
+ assertEquals(onSslErrorCallCount + 1, onReceivedSslErrorHelper.getCallCount());
+ }
}