| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 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 <Foundation/Foundation.h> | |
| 6 | |
| 7 #include "base/mac/scoped_nsobject.h" | |
| 8 #import "ios/chrome/browser/ui/no_tabs/no_tabs_controller.h" | |
| 9 #import "ios/chrome/browser/ui/no_tabs/no_tabs_controller_testing.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "testing/platform_test.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 class NoTabsControllerTest : public PlatformTest { | |
| 16 protected: | |
| 17 void SetUp() override { | |
| 18 view_.reset([[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)]); | |
| 19 controller_.reset([[NoTabsController alloc] initWithView:view_]); | |
| 20 }; | |
| 21 | |
| 22 base::scoped_nsobject<UIView> view_; | |
| 23 base::scoped_nsobject<NoTabsController> controller_; | |
| 24 }; | |
| 25 | |
| 26 // Verifies that the mode toggle switch is properly shown and hidden. | |
| 27 TEST_F(NoTabsControllerTest, ModeToggleSwitch) { | |
| 28 // The mode toggle button starts out hidden. | |
| 29 UIButton* button = [controller_ modeToggleButton]; | |
| 30 ASSERT_TRUE([button isHidden]); | |
| 31 | |
| 32 [controller_ setHasModeToggleSwitch:YES]; | |
| 33 ASSERT_FALSE([button isHidden]); | |
| 34 | |
| 35 [controller_ setHasModeToggleSwitch:NO]; | |
| 36 ASSERT_TRUE([button isHidden]); | |
| 37 } | |
| 38 | |
| 39 // Tests that creating a NoTabsController properly installs the No-Tabs UI into | |
| 40 // the provided view. | |
| 41 TEST_F(NoTabsControllerTest, Installation) { | |
| 42 // The toolbar view should be installed in |view_|, and it should take up the | |
| 43 // full width of |view_|. | |
| 44 UIView* toolbarView = [controller_ toolbarView]; | |
| 45 EXPECT_EQ(view_, [toolbarView superview]); | |
| 46 EXPECT_EQ(CGRectGetWidth([view_ bounds]), | |
| 47 CGRectGetWidth([toolbarView frame])); | |
| 48 | |
| 49 // The background view should fill |view_| completely. Note that its | |
| 50 // height/width might be larger than those of |view_|, as it has some padding | |
| 51 // to avoid visual flickering around the edges on device rotation. | |
| 52 UIView* backgroundView = [controller_ backgroundView]; | |
| 53 EXPECT_EQ(view_, [backgroundView superview]); | |
| 54 EXPECT_LE([view_ bounds].size.width, [backgroundView frame].size.width); | |
| 55 EXPECT_LE([view_ bounds].size.height, [backgroundView frame].size.height); | |
| 56 EXPECT_TRUE(CGPointEqualToPoint([view_ center], [backgroundView center])); | |
| 57 } | |
| 58 | |
| 59 // Tests that running through the show and hide methods does not crash. | |
| 60 // TODO(rohitrao): This is a somewhat silly test. Test something more | |
| 61 // interesting. | |
| 62 TEST_F(NoTabsControllerTest, ShowAndHideNoTabsUI) { | |
| 63 // Show the UI. | |
| 64 [controller_ prepareForShowAnimation]; | |
| 65 [controller_ showNoTabsUI]; | |
| 66 [controller_ showAnimationDidFinish]; | |
| 67 | |
| 68 // Hide the UI. | |
| 69 [controller_ prepareForDismissAnimation]; | |
| 70 [controller_ dismissNoTabsUI]; | |
| 71 [controller_ dismissAnimationDidFinish]; | |
| 72 } | |
| 73 | |
| 74 } // namespace | |
| OLD | NEW |