Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1943)

Unified Diff: ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm

Issue 2807843002: Refactor creation of SadTabView into a tab helper object (Closed)
Patch Set: Further small review changes Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
+}

Powered by Google App Engine
This is Rietveld 408576698