Commit 9773a841 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Update SadTabTabHelper to work with SadTabCoordinator.

SadTabTabHelper now calls sadTabTabHelperDidHide: and
sadTabTabHelper:didShowForRepeatedFailure:

Bug: 901563
Change-Id: If2b75702c951c247d44368b681ce360bbb6464d5
Reviewed-on: https://chromium-review.googlesource.com/c/1327167Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606854}
parent 3a5daa30
......@@ -2,6 +2,9 @@
// 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_SAD_TAB_TAB_HELPER_H_
#define IOS_CHROME_BROWSER_WEB_SAD_TAB_TAB_HELPER_H_
#import <Foundation/Foundation.h>
#include "base/macros.h"
......@@ -105,6 +108,9 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>,
// Whether a Sad Tab is being shown over |web_state_|'s content area.
bool showing_sad_tab_ = false;
// true if Sad Tab is presented and presented for repeated load failure.
bool repeated_failure_ = false;
// The fullscreen disabler for when the sad tab is visible.
std::unique_ptr<ScopedFullscreenDisabler> fullscreen_disabler_;
......@@ -126,3 +132,5 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>,
DISALLOW_COPY_AND_ASSIGN(SadTabTabHelper);
};
#endif // IOS_CHROME_BROWSER_WEB_SAD_TAB_TAB_HELPER_H_
......@@ -88,10 +88,17 @@ void SadTabTabHelper::WasShown(web::WebState* web_state) {
requires_reload_on_becoming_visible_ = false;
}
UpdateFullscreenDisabler();
if (showing_sad_tab_) {
[delegate_ sadTabTabHelper:this
didShowForRepeatedFailure:repeated_failure_];
}
}
void SadTabTabHelper::WasHidden(web::WebState* web_state) {
UpdateFullscreenDisabler();
if (showing_sad_tab_) {
[delegate_ sadTabTabHelperDidHide:this];
}
}
void SadTabTabHelper::RenderProcessGone(web::WebState* web_state) {
......@@ -117,6 +124,7 @@ void SadTabTabHelper::DidStartNavigation(
web::NavigationContext* navigation_context) {
// The sad tab is removed when a new navigation begins.
SetIsShowingSadTab(false);
[delegate_ sadTabTabHelperDismissSadTab:this];
}
void SadTabTabHelper::DidFinishNavigation(
......@@ -142,13 +150,13 @@ void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) {
double seconds_since_last_failure =
last_failed_timer_ ? last_failed_timer_->Elapsed().InSecondsF() : DBL_MAX;
bool repeated_failure =
repeated_failure_ =
(url_causing_failure.EqualsIgnoringRef(last_failed_url_) &&
seconds_since_last_failure < repeat_failure_interval_);
[delegate_ sadTabTabHelper:this
presentSadTabForWebState:web_state_
repeatedFailure:repeated_failure];
repeatedFailure:repeated_failure_];
last_failed_url_ = url_causing_failure;
last_failed_timer_ = std::make_unique<base::ElapsedTimer>();
......
......@@ -10,6 +10,7 @@
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper_delegate.h"
#import "ios/web/public/test/fakes/fake_navigation_context.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#import "ios/web/public/web_state/ui/crw_generic_content_view.h"
......@@ -26,6 +27,8 @@
// |repeatedFailure| could be used by the delegate to display different types of
// SadTabs.
@property(nonatomic, assign) BOOL repeatedFailure;
// YES if SadTab is currently being shown.
@property(nonatomic, assign) BOOL showingSadTab;
@end
@implementation SadTabTabHelperTestDelegate
......@@ -35,19 +38,21 @@
presentSadTabForWebState:(web::WebState*)webState
repeatedFailure:(BOOL)repeatedFailure {
self.repeatedFailure = repeatedFailure;
CRWContentView* contentView = [[CRWGenericContentView alloc]
initWithView:[[UIView alloc] initWithFrame:CGRectZero]];
webState->ShowTransientContentView(contentView);
self.showingSadTab = YES;
}
- (void)sadTabTabHelperDismissSadTab:(SadTabTabHelper*)tabHelper {
self.showingSadTab = NO;
}
- (void)sadTabTabHelper:(SadTabTabHelper*)tabHelper
didShowForRepeatedFailure:(BOOL)repeatedFailure {
self.repeatedFailure = repeatedFailure;
self.showingSadTab = YES;
}
- (void)sadTabTabHelperDidHide:(SadTabTabHelper*)tabHelper {
self.showingSadTab = NO;
}
@end
......@@ -89,12 +94,12 @@ TEST_F(SadTabTabHelperTest, ReloadedWhenWebStateWasShown) {
web_state_.WasHidden();
// Delegate should not present a SadTab.
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure,
// but Sad Tab should not be presented, because web state was not shown.
web_state_.OnRenderProcessGone();
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Navigation item must be reloaded once web state is shown.
EXPECT_FALSE(navigation_manager_->LoadIfNecessaryWasCalled());
......@@ -112,12 +117,12 @@ TEST_F(SadTabTabHelperTest, AppInBackground) {
web_state_.WasShown();
// Delegate should not present a SadTab.
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure,
// but Sad Tab should not be presented, because application is backgrounded.
web_state_.OnRenderProcessGone();
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Navigation item must be reloaded once the app became active.
EXPECT_FALSE(navigation_manager_->LoadIfNecessaryWasCalled());
......@@ -137,12 +142,12 @@ TEST_F(SadTabTabHelperTest, AppIsInactive) {
web_state_.WasShown();
// Delegate should not present a SadTab.
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure,
// but Sad Tab should not be presented, because application is inactive.
web_state_.OnRenderProcessGone();
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Navigation item must be reloaded once the app became active.
EXPECT_FALSE(navigation_manager_->LoadIfNecessaryWasCalled());
......@@ -161,12 +166,82 @@ TEST_F(SadTabTabHelperTest, Presented) {
web_state_.WasShown();
// Delegate should not present a SadTab.
EXPECT_FALSE(web_state_.GetTransientContentView());
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure. And the delegate
// should present a SadTab.
web_state_.OnRenderProcessGone();
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
}
// Tests that SadTab is removed by the navigation.
TEST_F(SadTabTabHelperTest, SadTabClearedByNavigation) {
OCMStub([application_ applicationState]).andReturn(UIApplicationStateActive);
web_state_.WasShown();
// Delegate should not present a SadTab.
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure. And the delegate
// should present a SadTab.
web_state_.OnRenderProcessGone();
ASSERT_TRUE(sad_tab_delegate_.showingSadTab);
// Novigation should clear the Sad Tab.
web::FakeNavigationContext context;
web_state_.OnNavigationStarted(&context);
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
}
// Tests that SadTab is presented after web state is shown and removed when web
// state is hidden.
TEST_F(SadTabTabHelperTest, HideAndShowPresented) {
OCMStub([application_ applicationState]).andReturn(UIApplicationStateActive);
web_state_.WasShown();
// Delegate should not present a SadTab.
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure. And the delegate
// should present a SadTab.
web_state_.OnRenderProcessGone();
EXPECT_TRUE(web_state_.GetTransientContentView());
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
web_state_.WasHidden();
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
web_state_.WasShown();
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_FALSE(sad_tab_delegate_.repeatedFailure);
}
// Tests that SadTab is presented after web state is shown and removed when web
// state is hidden.
TEST_F(SadTabTabHelperTest, HideAndShowPresentedForRepeatedFailure) {
OCMStub([application_ applicationState]).andReturn(UIApplicationStateActive);
web_state_.WasShown();
// Delegate should not present a SadTab.
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
// Helper should get notified of render process failure. And the delegate
// should present a SadTab.
web_state_.OnRenderProcessGone();
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
// Simulate repeated failure.
web_state_.OnRenderProcessGone();
ASSERT_TRUE(sad_tab_delegate_.repeatedFailure);
web_state_.WasHidden();
EXPECT_FALSE(sad_tab_delegate_.showingSadTab);
web_state_.WasShown();
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_TRUE(sad_tab_delegate_.repeatedFailure);
}
// Tests that repeated failures are communicated to the delegate correctly.
......@@ -178,18 +253,18 @@ TEST_F(SadTabTabHelperTest, RepeatedFailuresShowCorrectUI) {
web_state_.OnRenderProcessGone();
// SadTab should be displayed and repeatedFailure should be NO.
EXPECT_TRUE(web_state_.GetTransientContentView());
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_FALSE(sad_tab_delegate_.repeatedFailure);
// On a second render process crash, SadTab should be displayed and
// repeatedFailure should be YES.
web_state_.OnRenderProcessGone();
EXPECT_TRUE(web_state_.GetTransientContentView());
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_TRUE(sad_tab_delegate_.repeatedFailure);
// All subsequent crashes should have repeatedFailure as YES.
web_state_.OnRenderProcessGone();
EXPECT_TRUE(web_state_.GetTransientContentView());
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_TRUE(sad_tab_delegate_.repeatedFailure);
}
......@@ -212,12 +287,12 @@ TEST_F(SadTabTabHelperTest, FailureInterval) {
web_state.OnRenderProcessGone();
// SadTab should be displayed and repeatedFailure should be NO.
EXPECT_TRUE(web_state.GetTransientContentView());
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_FALSE(sad_tab_delegate_.repeatedFailure);
// On a second render process crash, SadTab should be displayed and
// repeatedFailure should still be NO due to the 0.0f interval timeout.
web_state.OnRenderProcessGone();
EXPECT_TRUE(web_state.GetTransientContentView());
EXPECT_TRUE(sad_tab_delegate_.showingSadTab);
EXPECT_FALSE(sad_tab_delegate_.repeatedFailure);
}
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