| Index: ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm
|
| diff --git a/ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm b/ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cbda26c282b21fadbd203e469c186a861cdb0c56
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm
|
| @@ -0,0 +1,83 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/browser/web/sad_tab_tab_helper.h"
|
| +
|
| +#import "ios/web/public/test/fakes/test_web_state.h"
|
| +#import "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +// A TestWebState which records whether a transient content view was presented
|
| +class SadTabTabHelperTestWebState : public web::TestWebState {
|
| + public:
|
| + void ShowTransientContentView(CRWContentView* content_view) override {
|
| + if (content_view) {
|
| + didShowTransientContentView = true;
|
| + }
|
| + }
|
| + bool DidShowTransientContentView() { return didShowTransientContentView; }
|
| +
|
| + private:
|
| + bool didShowTransientContentView;
|
| +};
|
| +
|
| +// A configurable TabHelper delegate for testing
|
| +@interface TabHelperTestDelegate : NSObject<SadTabTabHelperDelegate>
|
| +@property(readwrite, assign) BOOL active;
|
| +@end
|
| +
|
| +@implementation TabHelperTestDelegate
|
| +@synthesize active = _active;
|
| +- (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper {
|
| + return self.active;
|
| +}
|
| +@end
|
| +
|
| +// Tests that the presentation-block can be triggered without a delegate
|
| +TEST(SadTabTabHelperTest, PresentationCanBeTriggered) {
|
| + SadTabTabHelperTestWebState web_state;
|
| + SadTabTabHelper::CreateForWebState(&web_state, nil /*delegate*/);
|
| +
|
| + // WebState should not have presented a transient content view
|
| + EXPECT_FALSE(web_state.DidShowTransientContentView());
|
| +
|
| + // Helper should get notified of render process failure and show a content
|
| + // view
|
| + web_state.OnRenderProcessGone();
|
| + EXPECT_TRUE(web_state.DidShowTransientContentView());
|
| +}
|
| +
|
| +// Test that the presentation-block can be suppressed by the delegate
|
| +TEST(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) {
|
| + TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init];
|
| + SadTabTabHelperTestWebState web_state;
|
| + SadTabTabHelper::CreateForWebState(&web_state, delegate);
|
| +
|
| + // WebState should not have presented a transient content view
|
| + EXPECT_FALSE(web_state.DidShowTransientContentView());
|
| +
|
| + // Helper should get notified of render process failure
|
| + // But the delegate should suppress the presentation of a content view
|
| + web_state.OnRenderProcessGone();
|
| + EXPECT_FALSE(web_state.DidShowTransientContentView());
|
| +}
|
| +
|
| +// Test that the presentation-block can be allowed by the delegate
|
| +TEST(SadTabTabHelperTest, PresentationCanBeAllowedByDelegate) {
|
| + TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init];
|
| + delegate.active = YES;
|
| + SadTabTabHelperTestWebState web_state;
|
| + SadTabTabHelper::CreateForWebState(&web_state, delegate);
|
| +
|
| + // WebState should not have presented a transient content view
|
| + EXPECT_FALSE(web_state.DidShowTransientContentView());
|
| +
|
| + // Helper should get notified of render process failure
|
| + // The delegate should allow the presentation of a content view
|
| + web_state.OnRenderProcessGone();
|
| + EXPECT_TRUE(web_state.DidShowTransientContentView());
|
| +}
|
|
|