Commit 26b56a07 authored by Eugene But's avatar Eugene But Committed by Commit Bot

WebState::GetLoadingProgress returns 0 during the session restoration.

Also added NavigationManagerImpl::IsRestoreSessionInProgress method, so
WebStateImpl knows about in-progress restoration and can behave
accordinly.

Bug: 877671
Change-Id: Ic16391b8ba6a2a5742dee7c3fe91bc05c79d25fc
Reviewed-on: https://chromium-review.googlesource.com/c/1352413Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611725}
parent 4ce140dc
......@@ -53,6 +53,7 @@ class LegacyNavigationManagerImpl : public NavigationManagerImpl {
void AddPushStateItemIfNecessary(const GURL& url,
NSString* state_object,
ui::PageTransition transition) override;
bool IsRestoreSessionInProgress() const override;
// NavigationManager:
BrowserState* GetBrowserState() const override;
......
......@@ -349,4 +349,8 @@ void LegacyNavigationManagerImpl::AddPushStateItemIfNecessary(
transition:transition];
}
bool LegacyNavigationManagerImpl::IsRestoreSessionInProgress() const {
return false; // Session restoration is synchronous.
}
} // namespace web
......@@ -143,6 +143,9 @@ class NavigationManagerImpl : public NavigationManager {
NSString* state_object,
ui::PageTransition transition) = 0;
// Returns true if session restoration is in progress.
virtual bool IsRestoreSessionInProgress() const = 0;
// Resets the transient url rewriter list.
void RemoveTransientURLRewriters();
......
......@@ -1975,8 +1975,8 @@ TEST_P(NavigationManagerTest, Restore) {
// Call Restore() and check that the NavigationItems are in the correct order
// and that the last committed index is correct too.
ASSERT_FALSE(navigation_manager()->IsRestoreSessionInProgress());
navigation_manager()->Restore(1, std::move(items));
__block bool restore_done = false;
navigation_manager()->AddRestoreCompletionCallback(base::BindOnce(^{
restore_done = true;
......@@ -1984,6 +1984,7 @@ TEST_P(NavigationManagerTest, Restore) {
if (GetParam() == TEST_WK_BASED_NAVIGATION_MANAGER) {
// Session restore is asynchronous for WKBasedNavigationManager.
ASSERT_TRUE(navigation_manager()->IsRestoreSessionInProgress());
ASSERT_FALSE(restore_done);
// Verify that restore session URL is pending.
......@@ -2006,6 +2007,7 @@ TEST_P(NavigationManagerTest, Restore) {
return restore_done;
}));
EXPECT_FALSE(navigation_manager()->IsRestoreSessionInProgress());
ASSERT_EQ(3, navigation_manager()->GetItemCount());
EXPECT_EQ(1, navigation_manager()->GetLastCommittedItemIndex());
EXPECT_EQ(urls[1], navigation_manager()->GetLastCommittedItem()->GetURL());
......
......@@ -112,6 +112,7 @@ class WKBasedNavigationManagerImpl : public NavigationManagerImpl {
void AddPushStateItemIfNecessary(const GURL& url,
NSString* state_object,
ui::PageTransition transition) override;
bool IsRestoreSessionInProgress() const override;
// NavigationManager:
BrowserState* GetBrowserState() const override;
......
......@@ -296,6 +296,10 @@ void WKBasedNavigationManagerImpl::AddPushStateItemIfNecessary(
// to do here.
}
bool WKBasedNavigationManagerImpl::IsRestoreSessionInProgress() const {
return is_restore_session_in_progress_;
}
BrowserState* WKBasedNavigationManagerImpl::GetBrowserState() const {
return browser_state_;
}
......
......@@ -609,7 +609,9 @@ TEST_F(WKBasedNavigationManagerTest, RestoreSessionWithHistory) {
items.push_back(std::move(item0));
items.push_back(std::move(item1));
ASSERT_FALSE(manager_->IsRestoreSessionInProgress());
manager_->Restore(1 /* last_committed_item_index */, std::move(items));
EXPECT_TRUE(manager_->IsRestoreSessionInProgress());
NavigationItem* pending_item = manager_->GetPendingItem();
ASSERT_TRUE(pending_item != nullptr);
......@@ -673,7 +675,9 @@ TEST_F(WKBasedNavigationManagerTest, RestoreSessionResetsHistory) {
restored_item->SetURL(GURL("http://restored.com"));
std::vector<std::unique_ptr<NavigationItem>> items;
items.push_back(std::move(restored_item));
ASSERT_FALSE(manager_->IsRestoreSessionInProgress());
manager_->Restore(0 /* last_committed_item_index */, std::move(items));
EXPECT_TRUE(manager_->IsRestoreSessionInProgress());
// Check that last_committed_index, previous_item_index and pending_item_index
// are all reset to -1. Note that last_committed_item_index will change to the
......
......@@ -231,6 +231,9 @@ bool WebStateImpl::IsLoading() const {
}
double WebStateImpl::GetLoadingProgress() const {
if (navigation_manager_->IsRestoreSessionInProgress())
return 0.0;
return [web_controller_ loadingProgress];
}
......
......@@ -353,6 +353,7 @@ TEST_P(WebStateTest, RestoreLargeSession) {
navigation_manager->CanGoForward();
if (!restored) {
EXPECT_FALSE(navigation_manager->CanGoForward());
DCHECK_EQ(0.0, web_state_ptr->GetLoadingProgress());
// TODO(crbug.com/877671): Ensure that the following API work correctly:
// - WebState::GetLastCommittedURL
// - NavigationManager::GetBackwardItems
......@@ -375,7 +376,6 @@ TEST_P(WebStateTest, RestoreLargeSession) {
}
// TODO(crbug.com/877671): Ensure that the following API work correctly:
// - WebState::GetTitle
// - WebState::GetLoadingProgress
EXPECT_FALSE(web_state_ptr->IsCrashed());
EXPECT_FALSE(web_state_ptr->IsEvicted());
EXPECT_EQ("http://www.0.com/", web_state_ptr->GetVisibleURL());
......@@ -401,7 +401,9 @@ TEST_P(WebStateTest, RestoreLargeSession) {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^{
EXPECT_FALSE(IsWKInternalUrl(web_state_ptr->GetVisibleURL()));
return !navigation_manager->GetPendingItem() && !web_state_ptr->IsLoading();
return !navigation_manager->GetPendingItem() &&
!web_state_ptr->IsLoading() &&
web_state_ptr->GetLoadingProgress() == 1.0;
}));
}
......
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