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/chrome/browser/web/sad_tab_tab_helper_delegate.h" |
| 8 #import "ios/web/public/test/fakes/test_web_state.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/platform_test.h" |
| 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 16 // A TestWebState which records whether a transient content view was presented. |
| 17 class SadTabTabHelperTestWebState : public web::TestWebState { |
| 18 public: |
| 19 void ShowTransientContentView(CRWContentView* content_view) override { |
| 20 if (content_view) { |
| 21 is_showing_transient_content_view_ = true; |
| 22 } |
| 23 } |
| 24 bool is_showing_transient_content_view() const { |
| 25 return is_showing_transient_content_view_; |
| 26 } |
| 27 |
| 28 private: |
| 29 bool is_showing_transient_content_view_; |
| 30 }; |
| 31 |
| 32 // A configurable TabHelper delegate for testing. |
| 33 @interface TabHelperTestDelegate : NSObject<SadTabTabHelperDelegate> |
| 34 @property(readwrite, assign) BOOL active; |
| 35 @end |
| 36 |
| 37 @implementation TabHelperTestDelegate |
| 38 @synthesize active = _active; |
| 39 - (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper { |
| 40 return self.active; |
| 41 } |
| 42 @end |
| 43 |
| 44 class SadTabTabHelperTest : public PlatformTest { |
| 45 protected: |
| 46 SadTabTabHelperTest() : delegate_([[TabHelperTestDelegate alloc] init]) { |
| 47 SadTabTabHelper::CreateForWebState(&web_state_, delegate_); |
| 48 } |
| 49 TabHelperTestDelegate* delegate_; |
| 50 SadTabTabHelperTestWebState web_state_; |
| 51 }; |
| 52 |
| 53 // Tests that the presentation-block can be suppressed by the delegate. |
| 54 TEST_F(SadTabTabHelperTest, PresentationCanBeSuppressedByDelegate) { |
| 55 // WebState should not have presented a transient content view. |
| 56 EXPECT_FALSE(web_state_.is_showing_transient_content_view()); |
| 57 |
| 58 // Helper should get notified of render process failure, |
| 59 // but the delegate should suppress the presentation of a content view. |
| 60 web_state_.OnRenderProcessGone(); |
| 61 EXPECT_FALSE(web_state_.is_showing_transient_content_view()); |
| 62 } |
| 63 |
| 64 // Tests that the presentation-block can be allowed by the delegate. |
| 65 TEST_F(SadTabTabHelperTest, PresentationCanBeAllowedByDelegate) { |
| 66 delegate_.active = YES; |
| 67 |
| 68 // WebState should not have presented a transient content view. |
| 69 EXPECT_FALSE(web_state_.is_showing_transient_content_view()); |
| 70 |
| 71 // Helper should get notified of render process failure. |
| 72 // The delegate should allow the presentation of a content view. |
| 73 web_state_.OnRenderProcessGone(); |
| 74 EXPECT_TRUE(web_state_.is_showing_transient_content_view()); |
| 75 } |
OLD | NEW |