OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac/scoped_nsobject.h" | |
6 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" |
7 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" | 6 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" |
8 #include "ios/chrome/browser/ui/ui_util.h" | 7 #include "ios/chrome/browser/ui/ui_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/gtest_mac.h" | 9 #include "testing/gtest_mac.h" |
11 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
12 #import "third_party/ocmock/OCMock/OCMock.h" | 11 #import "third_party/ocmock/OCMock/OCMock.h" |
13 #import "third_party/ocmock/gtest_support.h" | 12 #import "third_party/ocmock/gtest_support.h" |
14 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
15 @interface NewTabPageBar (Testing) | 18 @interface NewTabPageBar (Testing) |
16 - (void)buttonDidTap:(UIButton*)button; | 19 - (void)buttonDidTap:(UIButton*)button; |
17 @end | 20 @end |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 class NewTabPageBarTest : public PlatformTest { | 24 class NewTabPageBarTest : public PlatformTest { |
22 protected: | 25 protected: |
23 void SetUp() override { | 26 void SetUp() override { |
24 CGRect frame = CGRectMake(0, 0, 320, 44); | 27 CGRect frame = CGRectMake(0, 0, 320, 44); |
25 bar_.reset([[NewTabPageBar alloc] initWithFrame:frame]); | 28 bar_ = [[NewTabPageBar alloc] initWithFrame:frame]; |
26 }; | 29 }; |
27 base::scoped_nsobject<NewTabPageBar> bar_; | 30 NewTabPageBar* bar_; |
28 }; | 31 }; |
29 | 32 |
30 TEST_F(NewTabPageBarTest, SetItems) { | 33 TEST_F(NewTabPageBarTest, SetItems) { |
31 NewTabPageBarItem* firstItem = [NewTabPageBarItem | 34 NewTabPageBarItem* firstItem = [NewTabPageBarItem |
32 newTabPageBarItemWithTitle:@"First" | 35 newTabPageBarItemWithTitle:@"First" |
33 identifier:1 | 36 identifier:1 |
34 image:[UIImage imageNamed:@"ntp_bookmarks"]]; | 37 image:[UIImage imageNamed:@"ntp_bookmarks"]]; |
35 // Tests that identifier test function can return both true and false. | 38 // Tests that identifier test function can return both true and false. |
36 EXPECT_TRUE(firstItem.identifier == 1U); | 39 EXPECT_TRUE(firstItem.identifier == 1U); |
37 | 40 |
38 NewTabPageBarItem* secondItem = [NewTabPageBarItem | 41 NewTabPageBarItem* secondItem = [NewTabPageBarItem |
39 newTabPageBarItemWithTitle:@"Second" | 42 newTabPageBarItemWithTitle:@"Second" |
40 identifier:2 | 43 identifier:2 |
41 image:[UIImage imageNamed:@"ntp_bookmarks"]]; | 44 image:[UIImage imageNamed:@"ntp_bookmarks"]]; |
42 NewTabPageBarItem* thirdItem = [NewTabPageBarItem | 45 NewTabPageBarItem* thirdItem = [NewTabPageBarItem |
43 newTabPageBarItemWithTitle:@"Third" | 46 newTabPageBarItemWithTitle:@"Third" |
44 identifier:3 | 47 identifier:3 |
45 image:[UIImage imageNamed:@"ntp_bookmarks"]]; | 48 image:[UIImage imageNamed:@"ntp_bookmarks"]]; |
46 | 49 |
47 [bar_ setItems:[NSArray arrayWithObject:firstItem]]; | 50 [bar_ setItems:[NSArray arrayWithObject:firstItem]]; |
48 EXPECT_EQ(bar_.get().buttons.count, 1U); | 51 EXPECT_EQ(bar_.buttons.count, 1U); |
49 [bar_ setItems:[NSArray arrayWithObjects:firstItem, secondItem, nil]]; | 52 [bar_ setItems:[NSArray arrayWithObjects:firstItem, secondItem, nil]]; |
50 EXPECT_EQ(bar_.get().buttons.count, 2U); | 53 EXPECT_EQ(bar_.buttons.count, 2U); |
51 [bar_ setItems:[NSArray | 54 [bar_ setItems:[NSArray |
52 arrayWithObjects:firstItem, secondItem, thirdItem, nil]]; | 55 arrayWithObjects:firstItem, secondItem, thirdItem, nil]]; |
53 EXPECT_EQ(bar_.get().buttons.count, 3U); | 56 EXPECT_EQ(bar_.buttons.count, 3U); |
54 [bar_ setItems:[NSArray arrayWithObject:firstItem]]; | 57 [bar_ setItems:[NSArray arrayWithObject:firstItem]]; |
55 EXPECT_EQ(bar_.get().buttons.count, 1U); | 58 EXPECT_EQ(bar_.buttons.count, 1U); |
56 } | 59 } |
57 | 60 |
58 TEST_F(NewTabPageBarTest, SetSelectedIndex_iPadOnly) { | 61 TEST_F(NewTabPageBarTest, SetSelectedIndex_iPadOnly) { |
59 // Selected index isn't meaningful on iPhone. | 62 // Selected index isn't meaningful on iPhone. |
60 if (!IsIPadIdiom()) { | 63 if (!IsIPadIdiom()) { |
61 return; | 64 return; |
62 } | 65 } |
63 | 66 |
64 NewTabPageBarItem* firstItem = [NewTabPageBarItem | 67 NewTabPageBarItem* firstItem = [NewTabPageBarItem |
65 newTabPageBarItemWithTitle:@"First" | 68 newTabPageBarItemWithTitle:@"First" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 id uncalledDelegate = | 108 id uncalledDelegate = |
106 [OCMockObject niceMockForProtocol:@protocol(NewTabPageBarDelegate)]; | 109 [OCMockObject niceMockForProtocol:@protocol(NewTabPageBarDelegate)]; |
107 [[uncalledDelegate reject] newTabBarItemDidChange:OCMOCK_ANY changePanel:YES]; | 110 [[uncalledDelegate reject] newTabBarItemDidChange:OCMOCK_ANY changePanel:YES]; |
108 [bar_ setDelegate:uncalledDelegate]; | 111 [bar_ setDelegate:uncalledDelegate]; |
109 [bar_ setSelectedIndex:2]; | 112 [bar_ setSelectedIndex:2]; |
110 EXPECT_TRUE([[[bar_ buttons] objectAtIndex:2] isSelected]); | 113 EXPECT_TRUE([[[bar_ buttons] objectAtIndex:2] isSelected]); |
111 EXPECT_OCMOCK_VERIFY(uncalledDelegate); | 114 EXPECT_OCMOCK_VERIFY(uncalledDelegate); |
112 } | 115 } |
113 | 116 |
114 } // anonymous namespace | 117 } // anonymous namespace |
OLD | NEW |