OLD | NEW |
---|---|
(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 { | |
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
| |
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<TabHelperDelegate> | |
30 @property(readwrite, assign) BOOL active; | |
31 - (BOOL)tabHelperShouldBeActive:(NSString*)tabHelperID; | |
32 @end | |
33 | |
34 @implementation TabHelperTestDelegate | |
35 @synthesize active = _active; | |
36 - (BOOL)tabHelperShouldBeActive:(NSString*)tabHelperID { | |
37 return self.active; | |
38 } | |
39 @end | |
40 | |
41 // 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!
| |
42 TEST(SadTabTabHelperTest, PresentationCanBeTriggered) { | |
43 std::unique_ptr<SadTabTabHelperTestWebState> web_state( | |
44 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!
| |
45 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!
| |
46 | |
47 // WebState should not have presented a transient content view | |
48 EXPECT_FALSE(web_state->DidShowTransientContentView()); | |
49 | |
50 // Helper should get notified of render process failure and show a content | |
51 // view | |
52 web_state->OnRenderProcessGone(); | |
53 EXPECT_TRUE(web_state->DidShowTransientContentView()); | |
54 } | |
55 | |
56 // Test that the presentation-block can be suppressed by the delegate | |
57 TEST(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) { | |
58 TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init]; | |
59 std::unique_ptr<SadTabTabHelperTestWebState> web_state( | |
60 new SadTabTabHelperTestWebState()); | |
61 SadTabTabHelper::CreateForWebState(web_state.get(), delegate); | |
62 | |
63 // WebState should not have presented a transient content view | |
64 EXPECT_FALSE(web_state->DidShowTransientContentView()); | |
65 | |
66 // Helper should get notified of render process failure | |
67 // But the delegate should suppress the presentation of a content view | |
68 web_state->OnRenderProcessGone(); | |
69 EXPECT_FALSE(web_state->DidShowTransientContentView()); | |
70 } | |
71 | |
72 // Test that the presentation-block can be allowed by the delegate | |
73 TEST(SadTabTabHelperTest, PresentationCanBeAllowedByDelegate) { | |
74 TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init]; | |
75 delegate.active = YES; | |
76 std::unique_ptr<SadTabTabHelperTestWebState> web_state( | |
77 new SadTabTabHelperTestWebState()); | |
78 SadTabTabHelper::CreateForWebState(web_state.get(), delegate); | |
79 | |
80 // WebState should not have presented a transient content view | |
81 EXPECT_FALSE(web_state->DidShowTransientContentView()); | |
82 | |
83 // Helper should get notified of render process failure | |
84 // The delegate should allow the presentation of a content view | |
85 web_state->OnRenderProcessGone(); | |
86 EXPECT_TRUE(web_state->DidShowTransientContentView()); | |
87 } | |
OLD | NEW |