Chromium Code Reviews| 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 { | |
| 18 if (content_view) { | |
| 19 didShowTransientContentView = true; | |
| 20 } | |
| 21 } | |
| 22 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.
| |
| 23 | |
| 24 private: | |
| 25 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.
| |
| 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 suppressed by the delegate. | |
| 41 TEST(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) { | |
| 42 TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init]; | |
| 43 SadTabTabHelperTestWebState web_state; | |
| 44 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!
| |
| 45 | |
| 46 // WebState should not have presented a transient content view. | |
| 47 EXPECT_FALSE(web_state.DidShowTransientContentView()); | |
| 48 | |
| 49 // Helper should get notified of render process failure, | |
| 50 // but the delegate should suppress the presentation of a content view. | |
| 51 web_state.OnRenderProcessGone(); | |
| 52 EXPECT_FALSE(web_state.DidShowTransientContentView()); | |
| 53 } | |
| 54 | |
| 55 // Tests that the presentation-block can be allowed by the delegate. | |
| 56 TEST(SadTabTabHelperTest, PresentationCanBeAllowedByDelegate) { | |
| 57 TabHelperTestDelegate* delegate = [[TabHelperTestDelegate alloc] init]; | |
| 58 delegate.active = YES; | |
| 59 SadTabTabHelperTestWebState web_state; | |
| 60 SadTabTabHelper::CreateForWebState(&web_state, delegate); | |
| 61 | |
| 62 // WebState should not have presented a transient content view. | |
| 63 EXPECT_FALSE(web_state.DidShowTransientContentView()); | |
| 64 | |
| 65 // Helper should get notified of render process failure. | |
| 66 // The delegate should allow the presentation of a content view. | |
| 67 web_state.OnRenderProcessGone(); | |
| 68 EXPECT_TRUE(web_state.DidShowTransientContentView()); | |
| 69 } | |
| OLD | NEW |