Commit 531be476 authored by Livvie Lin's avatar Livvie Lin Committed by Commit Bot

Add ChromeWebClientTest where SSLInfo is passed to PrepareErrorPage

Follow-up to crrev.com/c/1793260. Adds a test for SSL committed
interstitials.

Bug: 1017406
Change-Id: I47741700c5233ef6f238b3e2b61692d5a4b10cfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900405
Commit-Queue: Livvie Lin <livvielin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713199}
parent a2c118ae
......@@ -304,6 +304,7 @@ source_set("unit_tests_internal") {
"//ios/web/public/test",
"//ios/web/public/test/fakes",
"//net",
"//net:test_support",
"//testing/gtest",
"//third_party/ocmock",
"//url",
......
......@@ -24,6 +24,9 @@
#import "ios/web/public/test/fakes/test_web_state.h"
#import "ios/web/public/test/js_test_util.h"
#include "ios/web/public/test/scoped_testing_web_client.h"
#include "net/ssl/ssl_info.h"
#include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
......@@ -292,5 +295,40 @@ TEST_F(ChromeWebClientTest, PrepareErrorPagePostOtr) {
page);
}
// TODO(crbug.com/1017406): Add tests for SSL committed interstitials, where
// an SSLInfo value is passed into PrepareErrorPage.
// Tests PrepareErrorPage with SSLInfo, which results in an SSL committed
// interstitial.
TEST_F(ChromeWebClientTest, PrepareErrorPageWithSSLInfo) {
net::SSLInfo info;
info.cert =
net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
info.is_fatal_cert_error = false;
info.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
base::Optional<net::SSLInfo> ssl_info =
base::make_optional<net::SSLInfo>(info);
ChromeWebClient web_client;
NSError* error =
[NSError errorWithDomain:NSURLErrorDomain
code:NSURLErrorServerCertificateHasUnknownRoot
userInfo:nil];
__block bool callback_called = false;
__block NSString* page = nil;
base::OnceCallback<void(NSString*)> callback =
base::BindOnce(^(NSString* error_html) {
callback_called = true;
page = error_html;
});
web::TestWebState test_web_state;
test_web_state.SetBrowserState(browser_state());
web_client.PrepareErrorPage(&test_web_state, GURL(kTestUrl), error,
/*is_post=*/false,
/*is_off_the_record=*/false,
/*info=*/ssl_info,
/*navigation_id=*/0, std::move(callback));
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForActionTimeout, ^bool {
base::RunLoop().RunUntilIdle();
return callback_called;
}));
NSString* error_string = base::SysUTF8ToNSString(
net::ErrorToShortString(net::ERR_CERT_COMMON_NAME_INVALID));
EXPECT_TRUE([page containsString:error_string]);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment