Chromium Code Reviews| 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..16cc17cf9c24a7ed390cdd2fd63730c01781d5ad |
| --- /dev/null |
| +++ b/ios/chrome/browser/web/sad_tab_tab_helper_unittest.mm |
| @@ -0,0 +1,87 @@ |
| +// 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 { |
|
Eugene But (OOO till 7-30)
2017/04/10 22:56:28
Do you want to update web::TestWebState instead of
PL
2017/04/11 01:35:21
I could do that no problem, but here's why I did t
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
Are you sure that web::TestWebState uses CRWWebCon
Eugene But (OOO till 7-30)
2017/04/12 01:01:31
I think you missed this comment.
peterlaurens
2017/04/12 17:07:38
I did, thanks! I understand this a bit better now
|
| + if (content_view) { |
| + didShowTransientContentView = true; |
| + } |
| + } |
| + bool DidShowTransientContentView() { return didShowTransientContentView; } |
| + |
| + private: |
| + bool didShowTransientContentView; |
| +}; |
| + |
| +// A configurable TabHelper delegate for testing |
| +@interface TabHelperTestDelegate : NSObject<TabHelperDelegate> |
| +@property(readwrite, assign) BOOL active; |
| +- (BOOL)tabHelperShouldBeActive:(NSString*)tabHelperID; |
| +@end |
| + |
| +@implementation TabHelperTestDelegate |
| +@synthesize active = _active; |
| +- (BOOL)tabHelperShouldBeActive:(NSString*)tabHelperID { |
| + return self.active; |
| +} |
| +@end |
| + |
| +// Test that the presentation-block can be triggered without a delegate |
|
Eugene But (OOO till 7-30)
2017/04/10 22:56:28
nit: s/Test/Tests
From Style Guide: "These commen
PL
2017/04/11 01:35:21
Done, thanks!
|
| +TEST(SadTabTabHelperTest, PresentationCanBeTriggered) { |
| + std::unique_ptr<SadTabTabHelperTestWebState> web_state( |
| + new SadTabTabHelperTestWebState()); |
|
Eugene But (OOO till 7-30)
2017/04/10 22:56:28
nit: How about this?:
SadTabTabHelperTestWebState
PL
2017/04/11 01:35:21
Done; this is great thanks!
|
| + SadTabTabHelper::CreateForWebState(web_state.get(), nil); |
|
Eugene But (OOO till 7-30)
2017/04/10 22:56:28
Do you want to document |nil| with comments?:
Sad
PL
2017/04/11 01:35:22
Done!
|
| + |
| + // 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]; |
| + std::unique_ptr<SadTabTabHelperTestWebState> web_state( |
| + new SadTabTabHelperTestWebState()); |
| + SadTabTabHelper::CreateForWebState(web_state.get(), 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; |
| + std::unique_ptr<SadTabTabHelperTestWebState> web_state( |
| + new SadTabTabHelperTestWebState()); |
| + SadTabTabHelper::CreateForWebState(web_state.get(), 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()); |
| +} |