Commit 68306e9d authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix Error key for WebUI scheme handler

This CL changes the key used in the error to pass the URL of the failed
navigation as it is not the one used in the rest of the navigation code.

Fixed: 1140976
Change-Id: I752feef45742477ca38f9e3e89f3921378889f28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550674Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Reviewed-by: default avatarMike Pinkerton <pinkerton@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831013}
parent 290627df
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
#import "ios/web/public/test/web_view_content_test_util.h" #import "ios/web/public/test/web_view_content_test_util.h"
#import "ios/web/public/web_client.h" #import "ios/web/public/web_client.h"
#import "ios/web/public/web_state.h" #import "ios/web/public/web_state.h"
#include "ios/web/test/test_url_constants.h"
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#include "net/base/net_errors.h"
#include "net/test/embedded_test_server/default_handlers.h" #include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/request_handler_util.h" #include "net/test/embedded_test_server/request_handler_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -545,4 +547,56 @@ TEST_F(ErrorPageTest, ShouldAllowResponseCancelAndDisplayErrorBackNav) { ...@@ -545,4 +547,56 @@ TEST_F(ErrorPageTest, ShouldAllowResponseCancelAndDisplayErrorBackNav) {
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), error_text)); ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), error_text));
} }
// Tests that restoring an invalid WebUI URL doesn't create a new navigation.
TEST_F(ErrorPageTest, RestorationFromInvalidURL) {
server_responds_with_content_ = true;
std::string scheme = kTestWebUIScheme;
GURL invalid_webui = GURL(scheme + "://invalid");
NSError* error = testing::CreateErrorWithUnderlyingErrorChain(
{{@"NSURLErrorDomain", NSURLErrorUnsupportedURL},
{net::kNSErrorDomain, net::ERR_INVALID_URL}});
test::LoadUrl(web_state(), server_.GetURL("/echo-query?foo"));
ASSERT_TRUE(test::WaitForWebViewContainingText(web_state(), "foo"));
test::LoadUrl(web_state(), invalid_webui);
ASSERT_TRUE(test::WaitForWebViewContainingText(
web_state(), testing::GetErrorText(web_state(), invalid_webui, error,
/*is_post=*/false, /*is_otr=*/false,
/*cert_status=*/0)));
// Restore the session.
WebState::CreateParams params(GetBrowserState());
auto restored_web_state = WebState::CreateWithStorageSession(
params, web_state()->BuildSessionStorage());
restored_web_state->GetNavigationManager()->LoadIfNecessary();
ASSERT_TRUE(test::WaitForWebViewContainingText(
restored_web_state.get(),
testing::GetErrorText(restored_web_state.get(), invalid_webui, error,
/*is_post=*/false, /*is_otr=*/false,
/*cert_status=*/0)));
// Check that there is one item in the back list and no forward item.
EXPECT_EQ(
1UL,
restored_web_state->GetNavigationManager()->GetBackwardItems().size());
EXPECT_EQ(
0UL,
restored_web_state->GetNavigationManager()->GetForwardItems().size());
restored_web_state->GetNavigationManager()->GoBack();
ASSERT_TRUE(
test::WaitForWebViewContainingText(restored_web_state.get(), "foo"));
// Check that there is one item in the forward list and no back item.
EXPECT_EQ(
0UL,
restored_web_state->GetNavigationManager()->GetBackwardItems().size());
EXPECT_EQ(
1UL,
restored_web_state->GetNavigationManager()->GetForwardItems().size());
}
} // namespace web } // namespace web
...@@ -52,11 +52,11 @@ NSInteger GetErrorCodeForUrl(const GURL& URL) { ...@@ -52,11 +52,11 @@ NSInteger GetErrorCodeForUrl(const GURL& URL) {
NSInteger errorCode = GetErrorCodeForUrl( NSInteger errorCode = GetErrorCodeForUrl(
net::GURLWithNSURL(urlSchemeTask.request.mainDocumentURL)); net::GURLWithNSURL(urlSchemeTask.request.mainDocumentURL));
if (errorCode != 0) { if (errorCode != 0) {
NSError* error = NSError* error = [NSError
[NSError errorWithDomain:NSURLErrorDomain errorWithDomain:NSURLErrorDomain
code:errorCode code:errorCode
userInfo:@{ userInfo:@{
NSURLErrorKey : urlSchemeTask.request.URL, NSURLErrorFailingURLErrorKey : urlSchemeTask.request.URL,
NSURLErrorFailingURLStringErrorKey : NSURLErrorFailingURLStringErrorKey :
urlSchemeTask.request.URL.absoluteString urlSchemeTask.request.URL.absoluteString
}]; }];
......
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