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

[Nav Experiment] Move ReloadWithUserAgentType into NavigationManager.

This is a code cleanup before changing ReloadWithUserAgentType() to work
also with WKBasedNavigationManager, which would not be appropriate to
add to tab.mm.

This CL also fixed an apparent bug where IsItemRedirectItem() in
tab.mm seemed to have always used the wrong polarity in detecting
redirect items.

Bug: 798836
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Id39b3788a566fc8b188bdceb3a02803e5e182364
Reviewed-on: https://chromium-review.googlesource.com/920101
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537113}
parent b825a421
......@@ -78,7 +78,6 @@
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/voice/voice_search_navigations_tab_helper.h"
#import "ios/chrome/browser/web/navigation_manager_util.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web/passkit_dialog_provider.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h"
......@@ -131,18 +130,6 @@ NSString* const kTabClosingCurrentDocumentNotificationForCrashReporting =
NSString* const kTabUrlKey = @"url";
namespace {
// Returns true if |item| is the result of a HTTP redirect.
// Returns false if |item| is nullptr;
bool IsItemRedirectItem(web::NavigationItem* item) {
if (!item)
return false;
return (ui::PageTransition::PAGE_TRANSITION_IS_REDIRECT_MASK &
item->GetTransitionType()) == 0;
}
} // namespace
@interface Tab ()<CRWWebStateObserver> {
__weak TabModel* _parentTabModel;
ios::ChromeBrowserState* _browserState;
......@@ -396,50 +383,9 @@ bool IsItemRedirectItem(web::NavigationItem* item) {
}
- (void)reloadWithUserAgentType:(web::UserAgentType)userAgentType {
// This removes the web view, which will be recreated at the end of this.
[self.webController requirePageReconstruction];
// TODO(crbug.com/228171): A hack in session_controller -addPendingItem
// discusses making tab responsible for distinguishing history stack
// navigation from new navigations.
web::NavigationManager* navigationManager = [self navigationManager];
DCHECK(navigationManager);
web::NavigationItem* lastNonRedirectItem =
navigationManager->GetTransientItem();
if (!lastNonRedirectItem || IsItemRedirectItem(lastNonRedirectItem))
lastNonRedirectItem = navigationManager->GetVisibleItem();
if (!lastNonRedirectItem || IsItemRedirectItem(lastNonRedirectItem))
lastNonRedirectItem = GetLastCommittedNonRedirectedItem(navigationManager);
if (!lastNonRedirectItem)
return;
// |reloadURL| will be empty if a page was open by DOM.
GURL reloadURL(lastNonRedirectItem->GetOriginalRequestURL());
if (reloadURL.is_empty()) {
DCHECK(self.webState && self.webState->HasOpener());
reloadURL = lastNonRedirectItem->GetVirtualURL();
}
web::NavigationManager::WebLoadParams params(reloadURL);
params.referrer = lastNonRedirectItem->GetReferrer();
params.transition_type = ui::PAGE_TRANSITION_RELOAD;
switch (userAgentType) {
case web::UserAgentType::DESKTOP:
params.user_agent_override_option =
web::NavigationManager::UserAgentOverrideOption::DESKTOP;
break;
case web::UserAgentType::MOBILE:
params.user_agent_override_option =
web::NavigationManager::UserAgentOverrideOption::MOBILE;
break;
case web::UserAgentType::NONE:
NOTREACHED();
}
navigationManager->LoadURLWithParams(params);
navigationManager->ReloadWithUserAgentType(userAgentType);
}
#pragma mark - Public API (relating to U2F)
......
......@@ -21,8 +21,6 @@ source_set("web") {
"mailto_handler_manager.mm",
"mailto_handler_system_mail.h",
"mailto_handler_system_mail.mm",
"navigation_manager_util.h",
"navigation_manager_util.mm",
"network_activity_indicator_tab_helper.h",
"network_activity_indicator_tab_helper.mm",
"page_placeholder_tab_helper.h",
......@@ -81,7 +79,6 @@ source_set("unit_tests") {
"mailto_handler_manager_unittest.mm",
"mailto_handler_system_mail_unittest.mm",
"mailto_handler_unittest.mm",
"navigation_manager_util_unittest.mm",
"network_activity_indicator_tab_helper_unittest.mm",
"page_placeholder_tab_helper_unittest.mm",
"repost_form_tab_helper_unittest.mm",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_WEB_NAVIGATION_MANAGER_UTIL_H_
#define IOS_CHROME_BROWSER_WEB_NAVIGATION_MANAGER_UTIL_H_
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h"
// Utility functions built on web::NavigationManager public API.
// Returns the most recent Committed Item that is not the result of a client or
// server-side redirect from the given Navigation Manager. Returns nullptr if
// there's an error condition on the input |nav_manager|, such as nullptr or no
// non-redirect items.
web::NavigationItem* GetLastCommittedNonRedirectedItem(
web::NavigationManager* nav_manager);
#endif // IOS_CHROME_BROWSER_WEB_NAVIGATION_MANAGER_UTIL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/web/navigation_manager_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
web::NavigationItem* GetLastCommittedNonRedirectedItem(
web::NavigationManager* nav_manager) {
if (!nav_manager || !nav_manager->GetItemCount())
return nullptr;
int index = nav_manager->GetLastCommittedItemIndex();
while (index >= 0) {
web::NavigationItem* item = nav_manager->GetItemAtIndex(index);
// Returns the first non-Redirect item found.
if ((item->GetTransitionType() & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0)
return item;
--index;
}
return nullptr;
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/web/navigation_manager_util.h"
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
class NavigationManagerUtilTest : public PlatformTest {
protected:
web::TestNavigationManager nav_manager_;
};
// Tests that empty navigation manager returns nullptr.
TEST_F(NavigationManagerUtilTest, TestLastNonRedirectedItemEmpty) {
EXPECT_FALSE(GetLastCommittedNonRedirectedItem(nullptr));
EXPECT_FALSE(GetLastCommittedNonRedirectedItem(&nav_manager_));
}
// Tests that typed in URL works correctly.
TEST_F(NavigationManagerUtilTest, TestLastNonRedirectedItemTypedUrl) {
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_TYPED);
web::NavigationItem* item = GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_TYPED));
}
// Tests that link click works correctly.
TEST_F(NavigationManagerUtilTest, TestLastNonRedirectedItemLinkClicked) {
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_LINK);
web::NavigationItem* item = GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_LINK));
}
// Tests that redirect items are skipped.
TEST_F(NavigationManagerUtilTest, TestLastNonRedirectedItemLinkMultiRedirects) {
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_LINK);
nav_manager_.AddItem(GURL("http://bar.com/redir1"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir2"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
web::NavigationItem* item = GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_LINK));
}
// Tests that when all items are redirects, nullptr is returned.
TEST_F(NavigationManagerUtilTest, TestLastNonRedirectedItemAllRedirects) {
nav_manager_.AddItem(GURL("http://bar.com/redir0"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir1"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir2"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
web::NavigationItem* item = GetLastCommittedNonRedirectedItem(&nav_manager_);
EXPECT_FALSE(item);
}
// Tests that earlier redirects are not found.
TEST_F(NavigationManagerUtilTest, TestLastNonRedirectedItemNotEarliest) {
nav_manager_.AddItem(GURL("http://foo.com/bookmark"),
ui::PAGE_TRANSITION_AUTO_BOOKMARK);
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_TYPED);
nav_manager_.AddItem(GURL("http://bar.com/redir1"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir2"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
web::NavigationItem* item = GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_TYPED));
}
......@@ -89,10 +89,6 @@ class LegacyNavigationManagerImpl : public NavigationManagerImpl {
NavigationItemImpl* GetTransientItemImpl() const override;
void FinishGoToIndex(int index, NavigationInitiationType type) override;
// Returns true if the PageTransition for the underlying navigation item at
// |index| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK.
bool IsRedirectItemAtIndex(int index) const;
// CRWSessionController that backs this instance.
// TODO(stuartmorgan): Fold CRWSessionController into this class.
CRWSessionController* session_controller_;
......
......@@ -255,7 +255,10 @@ int LegacyNavigationManagerImpl::GetIndexForOffset(int offset) const {
// even aware existed, it is necessary to pass over pages that would
// immediately result in a redirect (the item *before* the redirected
// page).
while (result > 0 && IsRedirectItemAtIndex(result)) {
while (result > 0) {
const NavigationItem* item = GetItemAtIndex(result);
if (!ui::PageTransitionIsRedirect(item->GetTransitionType()))
break;
--result;
}
--result;
......@@ -271,7 +274,10 @@ int LegacyNavigationManagerImpl::GetIndexForOffset(int offset) const {
++result;
--offset;
// As with going back, skip over redirects.
while (result + 1 < GetItemCount() && IsRedirectItemAtIndex(result + 1)) {
while (result + 1 < GetItemCount()) {
const NavigationItem* item = GetItemAtIndex(result + 1);
if (!ui::PageTransitionIsRedirect(item->GetTransitionType()))
break;
++result;
}
}
......@@ -321,13 +327,6 @@ void LegacyNavigationManagerImpl::FinishGoToIndex(
}
}
bool LegacyNavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
DCHECK_GE(index, 0);
DCHECK_LT(index, GetItemCount());
ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
}
int LegacyNavigationManagerImpl::GetPreviousItemIndex() const {
return base::checked_cast<int>([session_controller_ previousItemIndex]);
}
......
......@@ -51,6 +51,13 @@ class NavigationManagerImpl : public NavigationManager {
NavigationManagerImpl();
~NavigationManagerImpl() override;
// Returns the most recent Committed Item that is not the result of a client
// or server-side redirect from the given Navigation Manager. Returns nullptr
// if there's an error condition on the input |nav_manager|, such as nullptr
// or no non-redirect items.
static NavigationItem* GetLastCommittedNonRedirectedItem(
const NavigationManager* nav_manager);
// Setters for NavigationManagerDelegate and BrowserState.
virtual void SetDelegate(NavigationManagerDelegate* delegate);
virtual void SetBrowserState(BrowserState* browser_state);
......@@ -163,6 +170,7 @@ class NavigationManagerImpl : public NavigationManager {
void AddTransientURLRewriter(BrowserURLRewriter::URLRewriter rewriter) final;
void GoToIndex(int index) final;
void Reload(ReloadType reload_type, bool check_for_reposts) final;
void ReloadWithUserAgentType(UserAgentType user_agent_type) final;
void LoadIfNecessary() final;
// Implementation for corresponding NavigationManager getters.
......
......@@ -45,6 +45,24 @@ NavigationManager::WebLoadParams& NavigationManager::WebLoadParams::operator=(
return *this;
}
/* static */
NavigationItem* NavigationManagerImpl::GetLastCommittedNonRedirectedItem(
const NavigationManager* nav_manager) {
if (!nav_manager || !nav_manager->GetItemCount())
return nullptr;
int index = nav_manager->GetLastCommittedItemIndex();
while (index >= 0) {
NavigationItem* item = nav_manager->GetItemAtIndex(index);
// Returns the first non-Redirect item found.
if (!ui::PageTransitionIsRedirect(item->GetTransitionType()))
return item;
--index;
}
return nullptr;
}
/* static */
bool NavigationManagerImpl::IsFragmentChangeNavigationBetweenUrls(
const GURL& existing_url,
......@@ -305,6 +323,48 @@ void NavigationManagerImpl::Reload(ReloadType reload_type,
delegate_->Reload();
}
void NavigationManagerImpl::ReloadWithUserAgentType(
UserAgentType user_agent_type) {
DCHECK_NE(user_agent_type, UserAgentType::NONE);
// This removes the web view, which will be recreated at the end of this.
delegate_->WillChangeUserAgentType();
NavigationItem* last_non_redirect_item = GetTransientItem();
if (!last_non_redirect_item ||
ui::PageTransitionIsRedirect(last_non_redirect_item->GetTransitionType()))
last_non_redirect_item = GetVisibleItem();
if (!last_non_redirect_item ||
ui::PageTransitionIsRedirect(last_non_redirect_item->GetTransitionType()))
last_non_redirect_item = GetLastCommittedNonRedirectedItem(this);
if (!last_non_redirect_item)
return;
// |reloadURL| will be empty if a page was open by DOM.
GURL reloadURL(last_non_redirect_item->GetOriginalRequestURL());
if (reloadURL.is_empty()) {
reloadURL = last_non_redirect_item->GetVirtualURL();
}
WebLoadParams params(reloadURL);
params.referrer = last_non_redirect_item->GetReferrer();
params.transition_type = ui::PAGE_TRANSITION_RELOAD;
switch (user_agent_type) {
case UserAgentType::DESKTOP:
params.user_agent_override_option = UserAgentOverrideOption::DESKTOP;
break;
case UserAgentType::MOBILE:
params.user_agent_override_option = UserAgentOverrideOption::MOBILE;
break;
case UserAgentType::NONE:
NOTREACHED();
}
LoadURLWithParams(params);
}
void NavigationManagerImpl::LoadIfNecessary() {
delegate_->LoadIfNecessary();
}
......
......@@ -17,6 +17,7 @@
#include "ios/web/public/load_committed_details.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/test/fakes/test_browser_state.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h"
#import "ios/web/test/fakes/crw_fake_back_forward_list.h"
#include "ios/web/test/test_url_constants.h"
#import "ios/web/web_state/ui/crw_web_view_navigation_proxy.h"
......@@ -1347,7 +1348,7 @@ TEST_P(NavigationManagerTest, UserAgentTypePropagationPastNativeItems) {
mock_wk_list_.currentItem = wk_item1;
navigation_manager()->CommitPendingItem();
web::NavigationItem* item1 = navigation_manager()->GetLastCommittedItem();
NavigationItem* item1 = navigation_manager()->GetLastCommittedItem();
ASSERT_EQ(web::UserAgentType::MOBILE, item1->GetUserAgentType());
GURL item2_url = item1->GetURL().ReplaceComponents(native_scheme_replacement);
......@@ -1362,8 +1363,7 @@ TEST_P(NavigationManagerTest, UserAgentTypePropagationPastNativeItems) {
mock_wk_list_.backList = @[ wk_item1 ];
navigation_manager()->CommitPendingItem();
web::NavigationItem* native_item1 =
navigation_manager()->GetLastCommittedItem();
NavigationItem* native_item1 = navigation_manager()->GetLastCommittedItem();
// Having a non-app-specific URL should not change the fact that the native
// item should be skipped when determining user agent inheritance.
native_item1->SetVirtualURL(GURL("http://non-app-specific-url"));
......@@ -1378,7 +1378,7 @@ TEST_P(NavigationManagerTest, UserAgentTypePropagationPastNativeItems) {
mock_wk_list_.currentItem = wk_item2;
mock_wk_list_.backList = @[ wk_item1, wk_native_item2 ];
navigation_manager()->CommitPendingItem();
web::NavigationItem* item2 = navigation_manager()->GetLastCommittedItem();
NavigationItem* item2 = navigation_manager()->GetLastCommittedItem();
// Verify that |item1|'s UserAgentType is propagated to |item2|.
EXPECT_EQ(item1->GetUserAgentType(), item2->GetUserAgentType());
......@@ -1400,8 +1400,7 @@ TEST_P(NavigationManagerTest, UserAgentTypePropagationPastNativeItems) {
mock_wk_list_.backList = @[ wk_item1, wk_native_item2, wk_item2 ];
navigation_manager()->CommitPendingItem();
web::NavigationItem* native_item2 =
navigation_manager()->GetLastCommittedItem();
NavigationItem* native_item2 = navigation_manager()->GetLastCommittedItem();
ASSERT_EQ(web::UserAgentType::NONE, native_item2->GetUserAgentType());
navigation_manager()->AddPendingItem(
GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
......@@ -1415,7 +1414,7 @@ TEST_P(NavigationManagerTest, UserAgentTypePropagationPastNativeItems) {
@[ wk_item1, wk_native_item2, wk_item2, wk_native_item3 ];
navigation_manager()->CommitPendingItem();
web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem();
NavigationItem* item3 = navigation_manager()->GetLastCommittedItem();
// Verify that |item2|'s UserAgentType is propagated to |item3|.
EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType());
......@@ -1735,6 +1734,29 @@ TEST_P(NavigationManagerTest,
navigation_manager()->GetLastCommittedItem()->GetURL());
}
// Tests that ReloadWithUserAgentType triggers new navigation with the expected
// user agent override.
TEST_P(NavigationManagerTest, ReloadWithUserAgentType) {
GURL url("http://www.1.com");
navigation_manager()->AddPendingItem(
url, Referrer(), ui::PAGE_TRANSITION_TYPED,
NavigationInitiationType::USER_INITIATED,
NavigationManager::UserAgentOverrideOption::MOBILE);
[mock_wk_list_ setCurrentURL:@"http://www.1.com"];
navigation_manager()->CommitPendingItem();
EXPECT_CALL(navigation_manager_delegate(), WillChangeUserAgentType());
EXPECT_CALL(navigation_manager_delegate(), RecordPageStateInNavigationItem());
EXPECT_CALL(navigation_manager_delegate(), ClearTransientContent());
EXPECT_CALL(navigation_manager_delegate(), LoadCurrentItem());
navigation_manager()->ReloadWithUserAgentType(UserAgentType::DESKTOP);
NavigationItem* pending_item = navigation_manager()->GetPendingItem();
EXPECT_EQ(url, pending_item->GetURL());
EXPECT_EQ(UserAgentType::DESKTOP, pending_item->GetUserAgentType());
}
// Tests that app-specific URLs are not rewritten for renderer-initiated loads
// unless requested by a page with app-specific url.
TEST_P(NavigationManagerTest, RewritingAppSpecificUrls) {
......@@ -1823,7 +1845,7 @@ TEST_P(NavigationManagerTest, GetIndexOfItem) {
mock_wk_list_.currentItem = wk_item0;
navigation_manager()->CommitPendingItem();
web::NavigationItem* item0 = navigation_manager()->GetLastCommittedItem();
NavigationItem* item0 = navigation_manager()->GetLastCommittedItem();
navigation_manager()->AddPendingItem(
GURL("http://www.url.com/1"), Referrer(), ui::PAGE_TRANSITION_TYPED,
web::NavigationInitiationType::USER_INITIATED,
......@@ -1833,10 +1855,9 @@ TEST_P(NavigationManagerTest, GetIndexOfItem) {
mock_wk_list_.backList = @[ wk_item0 ];
navigation_manager()->CommitPendingItem();
web::NavigationItem* item1 = navigation_manager()->GetLastCommittedItem();
NavigationItem* item1 = navigation_manager()->GetLastCommittedItem();
// Create an item that does not exist in the NavigationManagerImpl.
std::unique_ptr<web::NavigationItem> item_not_found =
web::NavigationItem::Create();
std::unique_ptr<NavigationItem> item_not_found = NavigationItem::Create();
// Verify GetIndexOfItem() results.
EXPECT_EQ(0, navigation_manager()->GetIndexOfItem(item0));
EXPECT_EQ(1, navigation_manager()->GetIndexOfItem(item1));
......@@ -2411,4 +2432,81 @@ INSTANTIATE_TEST_CASE_P(
NavigationManagerChoice::TEST_LEGACY_NAVIGATION_MANAGER,
NavigationManagerChoice::TEST_WK_BASED_NAVIGATION_MANAGER));
class NavigationManagerImplUtilTest : public PlatformTest {
protected:
web::TestNavigationManager nav_manager_;
};
// Tests that empty navigation manager returns nullptr.
TEST_F(NavigationManagerImplUtilTest, TestLastNonRedirectedItemEmpty) {
EXPECT_FALSE(
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(nullptr));
EXPECT_FALSE(
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(&nav_manager_));
}
// Tests that typed in URL works correctly.
TEST_F(NavigationManagerImplUtilTest, TestLastNonRedirectedItemTypedUrl) {
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_TYPED);
NavigationItem* item =
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_TYPED));
}
// Tests that link click works correctly.
TEST_F(NavigationManagerImplUtilTest, TestLastNonRedirectedItemLinkClicked) {
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_LINK);
NavigationItem* item =
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_LINK));
}
// Tests that redirect items are skipped.
TEST_F(NavigationManagerImplUtilTest,
TestLastNonRedirectedItemLinkMultiRedirects) {
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_LINK);
nav_manager_.AddItem(GURL("http://bar.com/redir1"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir2"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
NavigationItem* item =
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_LINK));
}
// Tests that when all items are redirects, nullptr is returned.
TEST_F(NavigationManagerImplUtilTest, TestLastNonRedirectedItemAllRedirects) {
nav_manager_.AddItem(GURL("http://bar.com/redir0"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir1"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir2"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
NavigationItem* item =
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(&nav_manager_);
EXPECT_FALSE(item);
}
// Tests that earlier redirects are not found.
TEST_F(NavigationManagerImplUtilTest, TestLastNonRedirectedItemNotEarliest) {
nav_manager_.AddItem(GURL("http://foo.com/bookmark"),
ui::PAGE_TRANSITION_AUTO_BOOKMARK);
nav_manager_.AddItem(GURL("http://foo.com/page0"), ui::PAGE_TRANSITION_TYPED);
nav_manager_.AddItem(GURL("http://bar.com/redir1"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
nav_manager_.AddItem(GURL("http://bar.com/redir2"),
ui::PAGE_TRANSITION_CLIENT_REDIRECT);
NavigationItem* item =
NavigationManagerImpl::GetLastCommittedNonRedirectedItem(&nav_manager_);
ASSERT_TRUE(item);
EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
item->GetTransitionType(), ui::PAGE_TRANSITION_TYPED));
}
} // namespace web
......@@ -11,6 +11,7 @@
#include "ios/web/public/navigation_item_list.h"
#include "ios/web/public/referrer.h"
#include "ios/web/public/reload_type.h"
#include "ios/web/public/user_agent.h"
#include "ui/base/page_transition_types.h"
@class NSDictionary;
......@@ -174,6 +175,10 @@ class NavigationManager {
// TODO(crbug.com/700958): implement the logic for |check_for_repost|.
virtual void Reload(ReloadType reload_type, bool check_for_repost) = 0;
// Reloads the visible item under the specified UserAgentType.
// TODO(crbug.com/738020): combine both Reload() implementations.
virtual void ReloadWithUserAgentType(UserAgentType user_agent_type) = 0;
// Returns a list of all non-redirected NavigationItems whose index precedes
// or follows the current index.
virtual NavigationItemList GetBackwardItems() const = 0;
......
......@@ -42,6 +42,7 @@ class TestNavigationManager : public NavigationManager {
void GoForward() override;
void GoToIndex(int index) override;
void Reload(ReloadType reload_type, bool check_for_reposts) override;
void ReloadWithUserAgentType(UserAgentType user_agent_type) override;
NavigationItemList GetBackwardItems() const override;
NavigationItemList GetForwardItems() const override;
void Restore(int last_committed_item_index,
......
......@@ -148,6 +148,11 @@ void TestNavigationManager::Reload(ReloadType reload_type,
NOTREACHED();
}
void TestNavigationManager::ReloadWithUserAgentType(
UserAgentType user_agent_type) {
NOTREACHED();
}
NavigationItemList TestNavigationManager::GetBackwardItems() const {
NOTREACHED();
return NavigationItemList();
......
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