Commit dd3bffc7 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Small fixes for navigation callbacks.

This CL fixes NavigationContext::IsRendererInitiated for reloads and
WebStatePolicyDecider::RequestInfo::transition_type for
browser-initiated navigation.

Bug: 676129, 725239
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I608b208d204bc055fcfd6c34dd7bd2a04b9c232a
Reviewed-on: https://chromium-review.googlesource.com/c/1282448
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600460}
parent 76a90fd9
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#import "ios/chrome/test/app/histogram_test_util.h" #import "ios/chrome/test/app/histogram_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/web/public/web_client.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -778,19 +777,8 @@ using payments::JourneyLogger; ...@@ -778,19 +777,8 @@ using payments::JourneyLogger;
buckets[0].min & JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS, @""); buckets[0].min & JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW, @""); GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_COMPLETED, @""); GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_COMPLETED, @"");
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
// TODO(crbug.com/676129): LegacyNavigationManager has a bug that doesn't GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
// create a pending item when reloading the page. This is incorrectly causing
// the second navigation above to be considered a renderer-initiated
// navigation, and the abort reason is incorrectly logged as
// EVENT_OTHER_ABORTED.
if (!web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
} else {
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
}
GREYAssertTrue( GREYAssertTrue(
buckets[0].min & JourneyLogger::EVENT_HAD_INITIAL_FORM_OF_PAYMENT, @""); buckets[0].min & JourneyLogger::EVENT_HAD_INITIAL_FORM_OF_PAYMENT, @"");
GREYAssertTrue( GREYAssertTrue(
...@@ -840,18 +828,8 @@ using payments::JourneyLogger; ...@@ -840,18 +828,8 @@ using payments::JourneyLogger;
buckets[0].min & JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS, @""); buckets[0].min & JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW, @""); GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_COMPLETED, @""); GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_COMPLETED, @"");
// TODO(crbug.com/676129): LegacyNavigationManager has a bug that doesn't GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
// create a pending item when reloading the page. This is incorrectly causing GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
// the second navigation above to be considered a renderer-initiated
// navigation, and the abort reason is incorrectly logged as
// EVENT_OTHER_ABORTED.
if (!web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
} else {
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
}
GREYAssertFalse( GREYAssertFalse(
buckets[0].min & JourneyLogger::EVENT_HAD_INITIAL_FORM_OF_PAYMENT, @""); buckets[0].min & JourneyLogger::EVENT_HAD_INITIAL_FORM_OF_PAYMENT, @"");
GREYAssertFalse( GREYAssertFalse(
...@@ -902,18 +880,8 @@ using payments::JourneyLogger; ...@@ -902,18 +880,8 @@ using payments::JourneyLogger;
buckets[0].min & JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS, @""); buckets[0].min & JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW, @""); GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_SKIPPED_SHOW, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_COMPLETED, @""); GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_COMPLETED, @"");
// TODO(crbug.com/676129): LegacyNavigationManager has a bug that doesn't GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
// create a pending item when reloading the page. This is incorrectly causing GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
// the second navigation above to be considered a renderer-initiated
// navigation, and the abort reason is incorrectly logged as
// EVENT_OTHER_ABORTED.
if (!web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
} else {
GREYAssertTrue(buckets[0].min & JourneyLogger::EVENT_USER_ABORTED, @"");
GREYAssertFalse(buckets[0].min & JourneyLogger::EVENT_OTHER_ABORTED, @"");
}
GREYAssertFalse( GREYAssertFalse(
buckets[0].min & JourneyLogger::EVENT_HAD_INITIAL_FORM_OF_PAYMENT, @""); buckets[0].min & JourneyLogger::EVENT_HAD_INITIAL_FORM_OF_PAYMENT, @"");
GREYAssertFalse( GREYAssertFalse(
......
...@@ -153,8 +153,11 @@ class WebStateImpl; ...@@ -153,8 +153,11 @@ class WebStateImpl;
// appropriate, as this method won't display any error to the user. // appropriate, as this method won't display any error to the user.
- (GURL)currentURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel; - (GURL)currentURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel;
// Methods for navigation and properties to interrogate state. // Reloads web view. |isRendererInitiated| is YES for renderer-initiated
- (void)reload; // navigation. |isRendererInitiated| is NO for browser-initiated navigation.
- (void)reloadWithRendererInitiatedNavigation:(BOOL)isRendererInitiated;
// Stops web view loading.
- (void)stopLoading; - (void)stopLoading;
// Loads the URL indicated by current session state. // Loads the URL indicated by current session state.
......
...@@ -2032,7 +2032,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2032,7 +2032,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
!_webStateImpl->HasWebUI(); !_webStateImpl->HasWebUI();
} }
- (void)reload { - (void)reloadWithRendererInitiatedNavigation:(BOOL)isRendererInitiated {
// Clear last user interaction. // Clear last user interaction.
// TODO(crbug.com/546337): Move to after the load commits, in the subclass // TODO(crbug.com/546337): Move to after the load commits, in the subclass
// implementation. This will be inaccurate if the reload fails or is // implementation. This will be inaccurate if the reload fails or is
...@@ -2047,6 +2047,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2047,6 +2047,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
transition:ui::PageTransition::PAGE_TRANSITION_RELOAD transition:ui::PageTransition::PAGE_TRANSITION_RELOAD
sameDocumentNavigation:NO sameDocumentNavigation:NO
hasUserGesture:YES]; hasUserGesture:YES];
navigationContext->SetIsRendererInitiated(isRendererInitiated);
_webStateImpl->OnNavigationStarted(navigationContext.get()); _webStateImpl->OnNavigationStarted(navigationContext.get());
[self didStartLoading]; [self didStartLoading];
self.navigationManagerImpl->CommitPendingItem(); self.navigationManagerImpl->CommitPendingItem();
...@@ -2221,7 +2222,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2221,7 +2222,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
return; return;
if (delta == 0) { if (delta == 0) {
[self reload]; [self reloadWithRendererInitiatedNavigation:YES];
return; return;
} }
...@@ -4191,6 +4192,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4191,6 +4192,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
sameDocumentNavigation:NO sameDocumentNavigation:NO
hasUserGesture:true]; hasUserGesture:true];
} }
context->SetIsRendererInitiated(false);
context->SetLoadingHtmlString(true); context->SetLoadingHtmlString(true);
[_navigationStates setContext:std::move(context) forNavigation:navigation]; [_navigationStates setContext:std::move(context) forNavigation:navigation];
} }
...@@ -4405,15 +4407,23 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4405,15 +4407,23 @@ registerLoadRequestForURL:(const GURL&)requestURL
} }
} }
ui::PageTransition transition =
[self pageTransitionFromNavigationType:action.navigationType];
BOOL isMainFrameNavigationAction = [self isMainFrameNavigationAction:action]; BOOL isMainFrameNavigationAction = [self isMainFrameNavigationAction:action];
if (base::FeatureList::IsEnabled(web::features::kWebErrorPages) && if (isMainFrameNavigationAction) {
isMainFrameNavigationAction) {
web::NavigationContextImpl* context = web::NavigationContextImpl* context =
[self contextForPendingMainFrameNavigationWithURL:requestURL]; [self contextForPendingMainFrameNavigationWithURL:requestURL];
if (context && context->IsLoadingErrorPage()) { if (context) {
// loadHTMLString: navigation which loads error page into WKWebView. DCHECK(!context->IsRendererInitiated());
decisionHandler(WKNavigationActionPolicyAllow); transition = context->GetPageTransition();
return;
if (base::FeatureList::IsEnabled(web::features::kWebErrorPages)) {
if (context->IsLoadingErrorPage()) {
// loadHTMLString: navigation which loads error page into WKWebView.
decisionHandler(WKNavigationActionPolicyAllow);
return;
}
}
} }
} }
...@@ -4457,8 +4467,6 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4457,8 +4467,6 @@ registerLoadRequestForURL:(const GURL&)requestURL
return; return;
} }
ui::PageTransition transition =
[self pageTransitionFromNavigationType:action.navigationType];
BOOL userInteractedWithRequestMainFrame = BOOL userInteractedWithRequestMainFrame =
[self userClickedRecently] && [self userClickedRecently] &&
net::GURLWithNSURL(action.request.mainDocumentURL) == net::GURLWithNSURL(action.request.mainDocumentURL) ==
...@@ -5622,6 +5630,8 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -5622,6 +5630,8 @@ registerLoadRequestForURL:(const GURL&)requestURL
WKNavigation* navigation = [self loadPOSTRequest:request]; WKNavigation* navigation = [self loadPOSTRequest:request];
[_navigationStates setContext:std::move(navigationContext) [_navigationStates setContext:std::move(navigationContext)
forNavigation:navigation]; forNavigation:navigation];
[_navigationStates setState:web::WKNavigationState::REQUESTED
forNavigation:navigation];
return; return;
} }
} }
...@@ -5635,6 +5645,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -5635,6 +5645,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
transition:self.currentTransition transition:self.currentTransition
sameDocumentNavigation:sameDocumentNavigation sameDocumentNavigation:sameDocumentNavigation
hasUserGesture:YES]; hasUserGesture:YES];
navigationContext->SetIsRendererInitiated(false);
WKNavigation* navigation = [self loadRequest:request]; WKNavigation* navigation = [self loadRequest:request];
[_navigationStates setContext:std::move(navigationContext) [_navigationStates setContext:std::move(navigationContext)
forNavigation:navigation]; forNavigation:navigation];
...@@ -5677,6 +5688,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -5677,6 +5688,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
transition:self.currentTransition transition:self.currentTransition
sameDocumentNavigation:sameDocumentNavigation sameDocumentNavigation:sameDocumentNavigation
hasUserGesture:YES]; hasUserGesture:YES];
navigationContext->SetIsRendererInitiated(false);
WKNavigation* navigation = nil; WKNavigation* navigation = nil;
if (navigationURL == net::GURLWithNSURL([_webView URL])) { if (navigationURL == net::GURLWithNSURL([_webView URL])) {
navigation = [_webView reload]; navigation = [_webView reload];
......
...@@ -825,7 +825,7 @@ void WebStateImpl::LoadIfNecessary() { ...@@ -825,7 +825,7 @@ void WebStateImpl::LoadIfNecessary() {
} }
void WebStateImpl::Reload() { void WebStateImpl::Reload() {
[web_controller_ reload]; [web_controller_ reloadWithRendererInitiatedNavigation:NO];
} }
void WebStateImpl::OnNavigationItemsPruned(size_t pruned_item_count) { void WebStateImpl::OnNavigationItemsPruned(size_t pruned_item_count) {
......
...@@ -53,10 +53,10 @@ class NavigationDelegateTest : public ios_web_view::WebViewInttestBase { ...@@ -53,10 +53,10 @@ class NavigationDelegateTest : public ios_web_view::WebViewInttestBase {
// Tests that expected delegate methods are called for a successful request. // Tests that expected delegate methods are called for a successful request.
TEST_F(NavigationDelegateTest, RequestSucceeds) { TEST_F(NavigationDelegateTest, RequestSucceeds) {
// A request made with -loadRequest: has type CWVNavigationTypeClientRedirect. // A request made with -loadRequest: has type CWVNavigationTypeTyped.
OCMExpect([mock_delegate_ webView:web_view_ OCMExpect([mock_delegate_ webView:web_view_
shouldStartLoadWithRequest:ArgWithURL(GetEchoURL()) shouldStartLoadWithRequest:ArgWithURL(GetEchoURL())
navigationType:CWVNavigationTypeClientRedirect]) navigationType:CWVNavigationTypeTyped])
.andReturn(YES); .andReturn(YES);
OCMExpect([mock_delegate_ webViewDidStartProvisionalNavigation:web_view_]); OCMExpect([mock_delegate_ webViewDidStartProvisionalNavigation:web_view_]);
OCMExpect([mock_delegate_ webView:web_view_ OCMExpect([mock_delegate_ webView:web_view_
...@@ -74,7 +74,7 @@ TEST_F(NavigationDelegateTest, RequestSucceeds) { ...@@ -74,7 +74,7 @@ TEST_F(NavigationDelegateTest, RequestSucceeds) {
TEST_F(NavigationDelegateTest, RequestFails) { TEST_F(NavigationDelegateTest, RequestFails) {
OCMExpect([mock_delegate_ webView:web_view_ OCMExpect([mock_delegate_ webView:web_view_
shouldStartLoadWithRequest:ArgWithURL(GetCloseSocketURL()) shouldStartLoadWithRequest:ArgWithURL(GetCloseSocketURL())
navigationType:CWVNavigationTypeClientRedirect]) navigationType:CWVNavigationTypeTyped])
.andReturn(YES); .andReturn(YES);
OCMExpect([mock_delegate_ webViewDidStartProvisionalNavigation:web_view_]); OCMExpect([mock_delegate_ webViewDidStartProvisionalNavigation:web_view_]);
OCMExpect([mock_delegate_ webViewDidCommitNavigation:web_view_]); OCMExpect([mock_delegate_ webViewDidCommitNavigation:web_view_]);
...@@ -92,7 +92,7 @@ TEST_F(NavigationDelegateTest, RequestFails) { ...@@ -92,7 +92,7 @@ TEST_F(NavigationDelegateTest, RequestFails) {
TEST_F(NavigationDelegateTest, CancelRequest) { TEST_F(NavigationDelegateTest, CancelRequest) {
OCMExpect([mock_delegate_ webView:web_view_ OCMExpect([mock_delegate_ webView:web_view_
shouldStartLoadWithRequest:ArgWithURL(GetEchoURL()) shouldStartLoadWithRequest:ArgWithURL(GetEchoURL())
navigationType:CWVNavigationTypeClientRedirect]) navigationType:CWVNavigationTypeTyped])
.andReturn(NO); .andReturn(NO);
ASSERT_TRUE(test::LoadUrl(web_view_, GetEchoURL())); ASSERT_TRUE(test::LoadUrl(web_view_, GetEchoURL()));
...@@ -104,7 +104,7 @@ TEST_F(NavigationDelegateTest, CancelRequest) { ...@@ -104,7 +104,7 @@ TEST_F(NavigationDelegateTest, CancelRequest) {
TEST_F(NavigationDelegateTest, CancelResponse) { TEST_F(NavigationDelegateTest, CancelResponse) {
OCMExpect([mock_delegate_ webView:web_view_ OCMExpect([mock_delegate_ webView:web_view_
shouldStartLoadWithRequest:ArgWithURL(GetEchoURL()) shouldStartLoadWithRequest:ArgWithURL(GetEchoURL())
navigationType:CWVNavigationTypeClientRedirect]) navigationType:CWVNavigationTypeTyped])
.andReturn(YES); .andReturn(YES);
OCMExpect([mock_delegate_ webViewDidStartProvisionalNavigation:web_view_]); OCMExpect([mock_delegate_ webViewDidStartProvisionalNavigation:web_view_]);
OCMExpect([mock_delegate_ webView:web_view_ OCMExpect([mock_delegate_ webView:web_view_
......
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