Commit f1291fb3 authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Nav Experiment] Propagate virtual URL in ReloadWithUserAgentType.

This hides the internal URL used by WKBasedNavigationManager to force
create an entry in WKBackForwardList when reloading with a different
user agent type (see crrev.com/c/919175).

Also fixed a bug in NavigationManagerTest which wasn't testing the
redirect case when GetParam() == TEST_WK_BASED_NAVIGATION_MANAGER.

Bug: 833958
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I095178302bfc4d209c2d058aab736777cc8b2de4
Reviewed-on: https://chromium-review.googlesource.com/1016002Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Danyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551548}
parent 1197b4da
...@@ -348,19 +348,21 @@ void NavigationManagerImpl::ReloadWithUserAgentType( ...@@ -348,19 +348,21 @@ void NavigationManagerImpl::ReloadWithUserAgentType(
return; return;
// |reloadURL| will be empty if a page was open by DOM. // |reloadURL| will be empty if a page was open by DOM.
GURL reloadURL(last_non_redirect_item->GetOriginalRequestURL()); GURL reload_url(last_non_redirect_item->GetOriginalRequestURL());
if (reloadURL.is_empty()) { if (reload_url.is_empty()) {
reloadURL = last_non_redirect_item->GetVirtualURL(); reload_url = last_non_redirect_item->GetVirtualURL();
} }
// Reload using a client-side redirect URL to create a new entry in // Reload using a client-side redirect URL to create a new entry in
// WKBackForwardList for the new user agent type. This hack is not needed for // WKBackForwardList for the new user agent type. This hack is not needed for
// LegacyNavigationManagerImpl which manages its own history entries. // LegacyNavigationManagerImpl which manages its own history entries.
if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) { if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
reloadURL = wk_navigation_util::CreateRedirectUrl(reloadURL); reload_url = wk_navigation_util::CreateRedirectUrl(reload_url);
} }
WebLoadParams params(reloadURL); WebLoadParams params(reload_url);
if (last_non_redirect_item->GetVirtualURL() != reload_url)
params.virtual_url = last_non_redirect_item->GetVirtualURL();
params.referrer = last_non_redirect_item->GetReferrer(); params.referrer = last_non_redirect_item->GetReferrer();
params.transition_type = ui::PAGE_TRANSITION_RELOAD; params.transition_type = ui::PAGE_TRANSITION_RELOAD;
......
...@@ -10,10 +10,13 @@ ...@@ -10,10 +10,13 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/bind_objc_block.h" #include "base/mac/bind_objc_block.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#import "ios/web/navigation/crw_session_controller+private_constructors.h" #import "ios/web/navigation/crw_session_controller+private_constructors.h"
#import "ios/web/navigation/legacy_navigation_manager_impl.h" #import "ios/web/navigation/legacy_navigation_manager_impl.h"
#import "ios/web/navigation/navigation_manager_delegate.h" #import "ios/web/navigation/navigation_manager_delegate.h"
#import "ios/web/navigation/wk_based_navigation_manager_impl.h" #import "ios/web/navigation/wk_based_navigation_manager_impl.h"
#import "ios/web/navigation/wk_navigation_util.h"
#include "ios/web/public/features.h"
#include "ios/web/public/load_committed_details.h" #include "ios/web/public/load_committed_details.h"
#include "ios/web/public/navigation_item.h" #include "ios/web/public/navigation_item.h"
#include "ios/web/public/test/fakes/test_browser_state.h" #include "ios/web/public/test/fakes/test_browser_state.h"
...@@ -114,11 +117,14 @@ class NavigationManagerTest ...@@ -114,11 +117,14 @@ class NavigationManagerTest
protected: protected:
NavigationManagerTest() { NavigationManagerTest() {
if (GetParam() == TEST_LEGACY_NAVIGATION_MANAGER) { if (GetParam() == TEST_LEGACY_NAVIGATION_MANAGER) {
feature_list_.InitAndDisableFeature(
web::features::kSlimNavigationManager);
manager_.reset(new LegacyNavigationManagerImpl); manager_.reset(new LegacyNavigationManagerImpl);
controller_ = controller_ =
[[CRWSessionController alloc] initWithBrowserState:&browser_state_]; [[CRWSessionController alloc] initWithBrowserState:&browser_state_];
delegate_.SetSessionController(session_controller()); delegate_.SetSessionController(session_controller());
} else { } else {
feature_list_.InitAndEnableFeature(web::features::kSlimNavigationManager);
manager_.reset(new WKBasedNavigationManagerImpl); manager_.reset(new WKBasedNavigationManagerImpl);
mock_web_view_ = OCMClassMock([WKWebView class]); mock_web_view_ = OCMClassMock([WKWebView class]);
mock_wk_list_ = [[CRWFakeBackForwardList alloc] init]; mock_wk_list_ = [[CRWFakeBackForwardList alloc] init];
...@@ -156,6 +162,7 @@ class NavigationManagerTest ...@@ -156,6 +162,7 @@ class NavigationManagerTest
CRWFakeBackForwardList* mock_wk_list_; CRWFakeBackForwardList* mock_wk_list_;
WKWebView* mock_web_view_; WKWebView* mock_web_view_;
base::test::ScopedFeatureList feature_list_;
private: private:
TestBrowserState browser_state_; TestBrowserState browser_state_;
...@@ -1742,6 +1749,8 @@ TEST_P(NavigationManagerTest, ReloadWithUserAgentType) { ...@@ -1742,6 +1749,8 @@ TEST_P(NavigationManagerTest, ReloadWithUserAgentType) {
url, Referrer(), ui::PAGE_TRANSITION_TYPED, url, Referrer(), ui::PAGE_TRANSITION_TYPED,
NavigationInitiationType::USER_INITIATED, NavigationInitiationType::USER_INITIATED,
NavigationManager::UserAgentOverrideOption::MOBILE); NavigationManager::UserAgentOverrideOption::MOBILE);
GURL virtual_url("http://www.1.com/virtual");
navigation_manager()->GetPendingItem()->SetVirtualURL(virtual_url);
[mock_wk_list_ setCurrentURL:@"http://www.1.com"]; [mock_wk_list_ setCurrentURL:@"http://www.1.com"];
navigation_manager()->CommitPendingItem(); navigation_manager()->CommitPendingItem();
...@@ -1753,7 +1762,15 @@ TEST_P(NavigationManagerTest, ReloadWithUserAgentType) { ...@@ -1753,7 +1762,15 @@ TEST_P(NavigationManagerTest, ReloadWithUserAgentType) {
navigation_manager()->ReloadWithUserAgentType(UserAgentType::DESKTOP); navigation_manager()->ReloadWithUserAgentType(UserAgentType::DESKTOP);
NavigationItem* pending_item = navigation_manager()->GetPendingItem(); NavigationItem* pending_item = navigation_manager()->GetPendingItem();
EXPECT_EQ(url, pending_item->GetURL()); if (GetParam() == TEST_LEGACY_NAVIGATION_MANAGER) {
EXPECT_EQ(url, pending_item->GetURL());
} else {
GURL reload_target_url;
ASSERT_TRUE(wk_navigation_util::ExtractTargetURL(pending_item->GetURL(),
&reload_target_url));
EXPECT_EQ(url, reload_target_url);
}
EXPECT_EQ(virtual_url, pending_item->GetVirtualURL());
EXPECT_EQ(UserAgentType::DESKTOP, pending_item->GetUserAgentType()); EXPECT_EQ(UserAgentType::DESKTOP, pending_item->GetUserAgentType());
} }
......
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