Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1215)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java

Issue 794023002: Remember user's decisions on SSL errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
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 ac9a1df2040d3aca3684f89b441c19418f852822..fbba821a7ced05b9885da13e305a8441deac84e9 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
@@ -500,7 +500,7 @@ public class AwContentsTest extends AwTestBase {
}
}
- // This is a meta test that we don't accidentally turn of hardware
+ // This is a meta test that we don't accidentally turn off hardware
// acceleration in instrumentation tests without notice. Do not add the
// @DisableHardwareAccelerationForTest annotation for this test.
@Feature({"AndroidWebView"})
@@ -511,4 +511,55 @@ public class AwContentsTest extends AwTestBase {
assertTrue(testContainer.isHardwareAccelerated());
assertTrue(testContainer.isBackedByHardwareView());
}
+
+ // 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());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698