| 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..9fa58a6d52fdfade062eec812ec6d2b0d11c436d
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm
|
| @@ -0,0 +1,75 @@
|
| +// 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/chrome/browser/web/sad_tab_tab_helper_delegate.h"
|
| +#import "ios/web/public/test/fakes/test_web_state.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/platform_test.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) {
|
| + is_showing_transient_content_view_ = true;
|
| + }
|
| + }
|
| + bool is_showing_transient_content_view() const {
|
| + return is_showing_transient_content_view_;
|
| + }
|
| +
|
| + private:
|
| + bool is_showing_transient_content_view_;
|
| +};
|
| +
|
| +// 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
|
| +
|
| +class SadTabTabHelperTest : public PlatformTest {
|
| + protected:
|
| + SadTabTabHelperTest() : delegate_([[TabHelperTestDelegate alloc] init]) {
|
| + SadTabTabHelper::CreateForWebState(&web_state_, delegate_);
|
| + }
|
| + TabHelperTestDelegate* delegate_;
|
| + SadTabTabHelperTestWebState web_state_;
|
| +};
|
| +
|
| +// Tests that the presentation-block can be suppressed by the delegate.
|
| +TEST_F(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) {
|
| + // WebState should not have presented a transient content view.
|
| + EXPECT_FALSE(web_state_.is_showing_transient_content_view());
|
| +
|
| + // 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_.is_showing_transient_content_view());
|
| +}
|
| +
|
| +// Tests that the presentation-block can be allowed by the delegate.
|
| +TEST_F(SadTabTabHelperTest, PresentationCanBeAllowedByDelegate) {
|
| + delegate_.active = YES;
|
| +
|
| + // WebState should not have presented a transient content view.
|
| + EXPECT_FALSE(web_state_.is_showing_transient_content_view());
|
| +
|
| + // 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_.is_showing_transient_content_view());
|
| +}
|
|
|