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

Side by Side 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: Change to delegate interface and other misc 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/web/sad_tab_tab_helper.h"
6
7 #import "ios/web/public/test/fakes/test_web_state.h"
8 #import "testing/gtest/include/gtest/gtest.h"
9
10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support."
12 #endif
13
14 // A TestWebState which records whether a transient content view was presented
15 class SadTabTabHelperTestWebState : public web::TestWebState {
16 public:
17 void ShowTransientContentView(CRWContentView* content_view) override {
18 if (content_view) {
19 didShowTransientContentView = true;
20 }
21 }
22 bool DidShowTransientContentView() { return didShowTransientContentView; }
23
24 private:
25 bool didShowTransientContentView;
26 };
27
28 // A configurable TabHelper delegate for testing
29 @interface TabHelperTestDelegate : NSObject<SadTabTabHelperDelegate>
30 @property(readwrite, assign) BOOL active;
31 @end
32
33 @implementation TabHelperTestDelegate
34 @synthesize active = _active;
35 - (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper {
36 return self.active;
37 }
38 @end
39
40 // Tests that the presentation-block can be triggered without a delegate
41 TEST(SadTabTabHelperTest, PresentationCanBeTriggered) {
42 SadTabTabHelperTestWebState web_state;
43 SadTabTabHelper::CreateForWebState(&web_state, nil /*delegate*/);
44
45 // WebState should not have presented a transient content view
46 EXPECT_FALSE(web_state.DidShowTransientContentView());
47
48 // Helper should get notified of render process failure and show a content
49 // view
50 web_state.OnRenderProcessGone();
51 EXPECT_TRUE(web_state.DidShowTransientContentView());
52 }
53
54 // Test that the presentation-block can be suppressed by the delegate
55 TEST(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) {
56 TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init];
57 SadTabTabHelperTestWebState web_state;
58 SadTabTabHelper::CreateForWebState(&web_state, delegate);
59
60 // WebState should not have presented a transient content view
61 EXPECT_FALSE(web_state.DidShowTransientContentView());
62
63 // Helper should get notified of render process failure
64 // But the delegate should suppress the presentation of a content view
65 web_state.OnRenderProcessGone();
66 EXPECT_FALSE(web_state.DidShowTransientContentView());
67 }
68
69 // Test that the presentation-block can be allowed by the delegate
70 TEST(SadTabTabHelperTest, PresentationCanBeAllowedByDelegate) {
71 TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init];
72 delegate.active = YES;
73 SadTabTabHelperTestWebState web_state;
74 SadTabTabHelper::CreateForWebState(&web_state, delegate);
75
76 // WebState should not have presented a transient content view
77 EXPECT_FALSE(web_state.DidShowTransientContentView());
78
79 // Helper should get notified of render process failure
80 // The delegate should allow the presentation of a content view
81 web_state.OnRenderProcessGone();
82 EXPECT_TRUE(web_state.DidShowTransientContentView());
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698