Commit 316c04f5 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix session restoration for iOS 12

The restoration of the URL shouldn't be done for session restoration
URL, otherwise ther URL will be the session restoration URL of a session
restoratin URL, which create issues.
It also fixes tests, adding a timeout for checking the URL.

Fixed: 1073871, 1017147
Change-Id: Ia91e626d589d7ad5f04d34c9181160e8039f85fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2162807
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarRobbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#761944}
parent 92409830
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_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/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
...@@ -81,6 +82,20 @@ std::unique_ptr<net::test_server::HttpResponse> CountResponse( ...@@ -81,6 +82,20 @@ std::unique_ptr<net::test_server::HttpResponse> CountResponse(
(*counter)++; (*counter)++;
return std::move(http_response); return std::move(http_response);
} }
// Returns true when omnibox contains |text|, otherwise returns false after
// after a timeout.
bool WaitForOmniboxContaining(std::string text) WARN_UNUSED_RESULT;
bool WaitForOmniboxContaining(std::string text) {
return base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, ^bool {
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:OmniboxText(text)]
assertWithMatcher:grey_notNil()
error:&error];
return error == nil;
});
}
} }
// Integration tests for restoring session history. // Integration tests for restoring session history.
...@@ -276,24 +291,28 @@ std::unique_ptr<net::test_server::HttpResponse> CountResponse( ...@@ -276,24 +291,28 @@ std::unique_ptr<net::test_server::HttpResponse> CountResponse(
// Go back to error page. // Go back to error page.
[[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:OmniboxText("invalid.")] GREYAssert(
assertWithMatcher:grey_notNil()]; WaitForOmniboxContaining("invalid."),
@"Timeout while waiting for omnibox text to become \"invalid.\".");
[ChromeEarlGrey waitForWebStateContainingText:"ERR_"]; [ChromeEarlGrey waitForWebStateContainingText:"ERR_"];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
[self triggerRestore]; [self triggerRestore];
[[EarlGrey selectElementWithMatcher:OmniboxText("invalid.")] GREYAssert(
assertWithMatcher:grey_notNil()]; WaitForOmniboxContaining("invalid."),
@"Timeout while waiting for omnibox text to become \"invalid.\".");
[ChromeEarlGrey waitForWebStateContainingText:"ERR_"]; [ChromeEarlGrey waitForWebStateContainingText:"ERR_"];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Go back to chrome url. // Go back to chrome url.
[[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:OmniboxText("chrome://chrome-urls")] GREYAssert(WaitForOmniboxContaining("chrome://chrome-urls"),
assertWithMatcher:grey_notNil()]; @"Timeout while waiting for omnibox text to become "
@"\"chrome://chrome-urls\".");
[ChromeEarlGrey waitForWebStateContainingText:"List of Chrome"]; [ChromeEarlGrey waitForWebStateContainingText:"List of Chrome"];
[self triggerRestore]; [self triggerRestore];
[[EarlGrey selectElementWithMatcher:OmniboxText("chrome://chrome-urls")] GREYAssert(WaitForOmniboxContaining("chrome://chrome-urls"),
assertWithMatcher:grey_notNil()]; @"Timeout while waiting for omnibox text to become "
@"\"chrome://chrome-urls\".");
[ChromeEarlGrey waitForWebStateContainingText:"List of Chrome"]; [ChromeEarlGrey waitForWebStateContainingText:"List of Chrome"];
// Go back to page1 and confirm page2 is still in the forward history. // Go back to page1 and confirm page2 is still in the forward history.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/web/navigation/navigation_item_storage_builder.h" #import "ios/web/navigation/navigation_item_storage_builder.h"
#import "ios/web/navigation/navigation_item_impl.h" #import "ios/web/navigation/navigation_item_impl.h"
#import "ios/web/navigation/wk_navigation_util.h"
#import "ios/web/public/session/crw_navigation_item_storage.h" #import "ios/web/public/session/crw_navigation_item_storage.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -40,8 +41,14 @@ NavigationItemStorageBuilder::BuildNavigationItemImpl( ...@@ -40,8 +41,14 @@ NavigationItemStorageBuilder::BuildNavigationItemImpl(
// GetVirtualURL() returns |url_| for the non-overridden case, this will also // GetVirtualURL() returns |url_| for the non-overridden case, this will also
// update the virtual URL reported by this object. // update the virtual URL reported by this object.
item->original_request_url_ = navigation_item_storage.URL; item->original_request_url_ = navigation_item_storage.URL;
item->SetURL(navigation_item_storage.URL); if (wk_navigation_util::IsRestoreSessionUrl(navigation_item_storage.URL)) {
item->SetVirtualURL(navigation_item_storage.virtualURL); // If it is a session restoration URL, restore the virtual URL to avoid a
// session restoration of a session restoration.
item->SetURL(navigation_item_storage.virtualURL);
} else {
item->SetURL(navigation_item_storage.URL);
item->SetVirtualURL(navigation_item_storage.virtualURL);
}
item->referrer_ = navigation_item_storage.referrer; item->referrer_ = navigation_item_storage.referrer;
item->timestamp_ = navigation_item_storage.timestamp; item->timestamp_ = navigation_item_storage.timestamp;
item->title_ = navigation_item_storage.title; item->title_ = navigation_item_storage.title;
......
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