Commit 211a27ff authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Update non-native NTP for ios/web changes.

Hide the error page that now shows for the NTP, Ignore |success|
in -didLoadPageWithSuccess (as it's been meaningless for the NTP
forever), and move NewTabPageTabHelper to activate on
DidFinishNavigation as the NTP now loads asynchronously.

Bug: 826369
Change-Id: I8899668daca1f7862a8d6c234d1ad6f3aa963ca0
Reviewed-on: https://chromium-review.googlesource.com/c/1298181Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602881}
parent 41254ebb
...@@ -37,8 +37,8 @@ class NewTabPageTabHelper : public web::WebStateObserver, ...@@ -37,8 +37,8 @@ class NewTabPageTabHelper : public web::WebStateObserver,
// web::WebStateObserver overrides: // web::WebStateObserver overrides:
void WebStateDestroyed(web::WebState* web_state) override; void WebStateDestroyed(web::WebState* web_state) override;
void DidStartNavigation(web::WebState* web_state, void DidFinishNavigation(web::WebState* web_state,
web::NavigationContext* navigation_context) override; web::NavigationContext* navigation_context) override;
// Enable or disable the tab helper. // Enable or disable the tab helper.
void SetActive(bool active); void SetActive(bool active);
......
...@@ -66,7 +66,7 @@ void NewTabPageTabHelper::WebStateDestroyed(web::WebState* web_state) { ...@@ -66,7 +66,7 @@ void NewTabPageTabHelper::WebStateDestroyed(web::WebState* web_state) {
SetActive(false); SetActive(false);
} }
void NewTabPageTabHelper::DidStartNavigation( void NewTabPageTabHelper::DidFinishNavigation(
web::WebState* web_state, web::WebState* web_state,
web::NavigationContext* navigation_context) { web::NavigationContext* navigation_context) {
if (navigation_context->IsSameDocument()) { if (navigation_context->IsSameDocument()) {
......
...@@ -118,19 +118,19 @@ TEST_F(NewTabPageTabHelperTest, TestToggleToAndFromNTP) { ...@@ -118,19 +118,19 @@ TEST_F(NewTabPageTabHelperTest, TestToggleToAndFromNTP) {
GURL url(kChromeUINewTabURL); GURL url(kChromeUINewTabURL);
web::FakeNavigationContext context; web::FakeNavigationContext context;
context.SetUrl(url); context.SetUrl(url);
test_web_state_.OnNavigationStarted(&context); test_web_state_.OnNavigationFinished(&context);
EXPECT_TRUE(tab_helper()->IsActive()); EXPECT_TRUE(tab_helper()->IsActive());
GURL not_ntp_url(kTestURL); GURL not_ntp_url(kTestURL);
context.SetUrl(not_ntp_url); context.SetUrl(not_ntp_url);
test_web_state_.OnNavigationStarted(&context); test_web_state_.OnNavigationFinished(&context);
EXPECT_FALSE(tab_helper()->IsActive()); EXPECT_FALSE(tab_helper()->IsActive());
context.SetUrl(url); context.SetUrl(url);
test_web_state_.OnNavigationStarted(&context); test_web_state_.OnNavigationFinished(&context);
EXPECT_TRUE(tab_helper()->IsActive()); EXPECT_TRUE(tab_helper()->IsActive());
context.SetUrl(not_ntp_url); context.SetUrl(not_ntp_url);
test_web_state_.OnNavigationStarted(&context); test_web_state_.OnNavigationFinished(&context);
EXPECT_FALSE(tab_helper()->IsActive()); EXPECT_FALSE(tab_helper()->IsActive());
} }
...@@ -186,9 +186,6 @@ const char kNTPHelpURL[] = ...@@ -186,9 +186,6 @@ const char kNTPHelpURL[] =
- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { - (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
DCHECK_EQ(_webState, webState); DCHECK_EQ(_webState, webState);
if (!success)
return;
[self setContentOffsetForWebState:webState]; [self setContentOffsetForWebState:webState];
} }
......
...@@ -211,6 +211,15 @@ void ChromeWebClient::PrepareErrorPage(NSError* error, ...@@ -211,6 +211,15 @@ void ChromeWebClient::PrepareErrorPage(NSError* error,
bool is_off_the_record, bool is_off_the_record,
NSString** error_html) { NSString** error_html) {
DCHECK(error); DCHECK(error);
// Return an empty page for the NTP.
NSString* url_spec = error.userInfo[NSURLErrorFailingURLStringErrorKey];
GURL url(base::SysNSStringToUTF16(url_spec));
if (url.GetOrigin() == kChromeUINewTabURL) {
*error_html = @"";
return;
}
*error_html = GetErrorPage(error, is_post, is_off_the_record); *error_html = GetErrorPage(error, is_post, is_off_the_record);
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/passwords/credential_manager_features.h" #include "ios/chrome/browser/passwords/credential_manager_features.h"
#import "ios/chrome/browser/web/error_page_util.h" #import "ios/chrome/browser/web/error_page_util.h"
#import "ios/web/public/test/error_test_util.h" #import "ios/web/public/test/error_test_util.h"
...@@ -220,3 +221,20 @@ TEST_F(ChromeWebClientTest, PrepareErrorPagePostOtr) { ...@@ -220,3 +221,20 @@ TEST_F(ChromeWebClientTest, PrepareErrorPagePostOtr) {
EXPECT_NSEQ(GetErrorPage(error, /*is_post=*/true, /*is_off_the_record=*/true), EXPECT_NSEQ(GetErrorPage(error, /*is_post=*/true, /*is_off_the_record=*/true),
page); page);
} }
// Tests PrepareErrorPage wth NTP and an empty string.
TEST_F(ChromeWebClientTest, PrepareErrorPageNTP) {
ChromeWebClient web_client;
NSString* ntp_url = base::SysUTF8ToNSString(kChromeUINewTabURL);
NSDictionary* info = @{
NSURLErrorFailingURLStringErrorKey : ntp_url,
};
NSError* error = web::testing::CreateTestNetError([NSError
errorWithDomain:NSURLErrorDomain
code:NSURLErrorNetworkConnectionLost
userInfo:info]);
NSString* page = nil;
web_client.PrepareErrorPage(error, /*is_post=*/false,
/*is_off_the_record=*/false, &page);
EXPECT_NSEQ(@"", page);
}
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