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..88787dbfcf579df0d7718e7863bcd409e5893b5e |
--- /dev/null |
+++ b/ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm |
@@ -0,0 +1,69 @@ |
+// 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; } |
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
How about
|bool is_showing_transient_content_vie
peterlaurens
2017/04/11 21:57:27
Done.
|
+ |
+ private: |
+ bool didShowTransientContentView; |
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
How about:
bool is_showing_transient_content_view_
peterlaurens
2017/04/11 21:57:27
Done.
|
+}; |
+ |
+// 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 suppressed by the delegate. |
+TEST(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) { |
+ TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init]; |
+ SadTabTabHelperTestWebState web_state; |
+ SadTabTabHelper::CreateForWebState(&web_state, delegate); |
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
Optional nit: Do you want to create SadTabTabHelpe
peterlaurens
2017/04/11 21:57:27
Done, this is great, thanks!
|
+ |
+ // 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()); |
+} |
+ |
+// Tests 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()); |
+} |