Commit 17ea80c1 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Don't load new error navigation while restoring

This CL makes sure that when the application doesn't start a new
navigation when an error occurs while loading a session restoration
page.

Fixed: 1138895
Change-Id: I9d0b4558ddccf3f53f9dd8dd7d671434b31f1d77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520896
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825404}
parent 4091d9b4
......@@ -451,6 +451,7 @@ source_set("eg2_tests") {
"//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/ui/infobars/banners:public",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/tab_grid:features",
"//ios/chrome/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/net:test_support",
......
......@@ -6,10 +6,12 @@
#include <string>
#include "base/bind.h"
#import "ios/chrome/browser/ui/tab_grid/features.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ios/testing/embedded_test_server_handlers.h"
#include "ios/web/common/features.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
......@@ -36,6 +38,21 @@ std::string GetErrorMessage() {
@implementation ErrorPageTestCase
@synthesize serverRespondsWithContent = _serverRespondsWithContent;
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
// Features are enabled or disabled based on the name of the test that is
// running. This is done because it is inefficient to use
// ensureAppLaunchedWithConfiguration for each test.
if ([self isRunningTest:@selector(testRestoreErrorPage)]) {
config.features_disabled.push_back(kEnableCloseAllTabsConfirmation);
config.features_enabled.push_back(web::features::kUseJSForErrorPage);
} else {
config.features_enabled.push_back(kEnableCloseAllTabsConfirmation);
}
return config;
}
- (void)setUp {
[super setUp];
......@@ -74,4 +91,24 @@ std::string GetErrorMessage() {
[ChromeEarlGrey waitForWebStateContainingText:GetErrorMessage()];
}
// Loads a URL then restore the session and fail during the reload
- (void)testRestoreErrorPage {
// Load the page.
self.serverRespondsWithContent = YES;
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo-query?foo")];
[ChromeEarlGrey waitForWebStateContainingText:"foo"];
GREYAssertEqual(1, [ChromeEarlGrey navigationBackListItemsCount],
@"The navigation back list should have only 1 entries before "
@"the restoration.");
// Restore the session but with the page no longer loading.
self.serverRespondsWithContent = NO;
[ChromeEarlGrey triggerRestoreViaTabGridRemoveAllUndo];
[ChromeEarlGrey waitForWebStateContainingText:GetErrorMessage()];
GREYAssertEqual(1, [ChromeEarlGrey navigationBackListItemsCount],
@"The navigation back list should still have only 1 entries "
@"after the restoration.");
}
@end
......@@ -76,6 +76,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// induced on error.
- (NSInteger)browsingHistoryEntryCount;
// Gets the number of items in the back list.
- (NSInteger)navigationBackListItemsCount;
// Clears browsing cache. Raises an EarlGrey exception if history is not
// cleared within a timeout.
- (void)removeBrowsingCache;
......
......@@ -133,6 +133,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return result;
}
- (NSInteger)navigationBackListItemsCount {
return [ChromeEarlGreyAppInterface navigationBackListItemsCount];
}
- (void)removeBrowsingCache {
EG_TEST_HELPER_ASSERT_NO_ERROR(
[ChromeEarlGreyAppInterface removeBrowsingCache]);
......
......@@ -30,6 +30,9 @@
+ (NSInteger)browsingHistoryEntryCountWithError:
(NSError* __autoreleasing*)error;
// Gets the number of items in the back list. Returns -1 in case of error.
+ (NSInteger)navigationBackListItemsCount;
// Clears browsing cache. Returns nil on success, or else an NSError indicating
// the operation failed.
+ (NSError*)removeBrowsingCache;
......
......@@ -105,6 +105,15 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
return chrome_test_util::GetBrowsingHistoryEntryCount(error);
}
+ (NSInteger)navigationBackListItemsCount {
web::WebState* webState = chrome_test_util::GetCurrentWebState();
if (!webState)
return -1;
return webState->GetNavigationManager()->GetBackwardItems().size();
}
+ (NSError*)removeBrowsingCache {
if (chrome_test_util::RemoveBrowsingCache()) {
return nil;
......
......@@ -2049,14 +2049,16 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
// 2. Current nav item has a failed URL. This may happen when
// back/forward/refresh on a loaded page;
// 3. Current nav item is an irrelevant page.
// For 1&2, load an empty string to remove existing JS code.
// 4. Current nav item is a session restoration.
// For 1, 2 and 4, load an empty string to remove existing JS code.
// For 3, load error page file to create a new nav item.
// The actual error HTML will be loaded in didFinishNavigation callback.
WKNavigation* errorNavigation = nil;
if (provisionalLoad &&
![errorPage
isErrorPageFileURLForFailedNavigationURL:backForwardItem.URL] &&
![backForwardItem.URL isEqual:errorPage.failedNavigationURL]) {
![backForwardItem.URL isEqual:errorPage.failedNavigationURL] &&
!web::wk_navigation_util::IsRestoreSessionUrl(backForwardItem.URL)) {
errorNavigation = [webView loadFileURL:errorPage.errorPageFileURL
allowingReadAccessToURL:errorPage.errorPageFileURL];
} else {
......
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