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/ui/content_suggestions/content_suggestions_collectio n_utils.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "ios/chrome/browser/ui/ui_util.h" | |
9 #import "ios/chrome/test/base/scoped_block_swizzler.h" | |
10 #include "testing/platform_test.h" | |
11 #import "third_party/ocmock/OCMock/OCMock.h" | |
12 | |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
14 #error "This file requires ARC support." | |
15 #endif | |
16 | |
17 namespace content_suggestions { | |
18 | |
19 class ContentSuggestionsCollectionUtilsTest : public PlatformTest { | |
20 public: | |
21 void SetAsIPad() { | |
22 device_type_swizzler_ = base::MakeUnique<ScopedBlockSwizzler>( | |
23 [UIDevice class], @selector(userInterfaceIdiom), | |
24 ^UIUserInterfaceIdiom(id self) { | |
25 return UIUserInterfaceIdiomPad; | |
26 }); | |
27 } | |
28 void SetAsIPhone() { | |
29 device_type_swizzler_ = base::MakeUnique<ScopedBlockSwizzler>( | |
30 [UIDevice class], @selector(userInterfaceIdiom), | |
31 ^UIUserInterfaceIdiom(id self) { | |
32 return UIUserInterfaceIdiomPhone; | |
33 }); | |
34 } | |
35 | |
36 private: | |
37 std::unique_ptr<ScopedBlockSwizzler> device_type_swizzler_; | |
38 }; | |
39 | |
40 TEST_F(ContentSuggestionsCollectionUtilsTest, orientationFramePortrait) { | |
41 // Setup. | |
42 CGRect rect1 = CGRectMake(10, 10, 0, 10); | |
43 CGRect rect2 = CGRectMake(20, 20, 0, 20); | |
44 const CGRect rects[2] = {rect1, rect2}; | |
45 | |
46 // Action. | |
47 CGRect result = getOrientationFrame(rects, 400); | |
48 | |
49 // Tests. | |
50 rect1.size.width = 380; | |
51 EXPECT_TRUE(CGRectEqualToRect(rect1, result)); | |
52 } | |
53 | |
54 TEST_F(ContentSuggestionsCollectionUtilsTest, orientationFrameLandscape) { | |
55 // Setup. | |
56 CGRect rect1 = CGRectMake(10, 10, 0, 10); | |
57 CGRect rect2 = CGRectMake(20, 20, 0, 20); | |
58 const CGRect rects[2] = {rect1, rect2}; | |
59 std::unique_ptr<ScopedBlockSwizzler> orientation_swizzler = | |
60 base::MakeUnique<ScopedBlockSwizzler>( | |
61 [UIApplication class], @selector(statusBarOrientation), | |
62 ^UIInterfaceOrientation(id self) { | |
63 return UIInterfaceOrientationLandscapeLeft; | |
64 }); | |
65 | |
66 // Action. | |
67 CGRect result = getOrientationFrame(rects, 400); | |
68 | |
69 // Tests. | |
70 rect1.size.width = 380; | |
71 rect2.size.width = 360; | |
72 if (IsIPadIdiom()) { | |
marq (ping after 24h)
2017/05/10 11:17:26
Here (and elsewhere) -- for each of the tests with
gambard
2017/05/10 11:48:46
Done.
| |
73 EXPECT_TRUE(CGRectEqualToRect(rect1, result)); | |
74 } else { | |
75 EXPECT_TRUE(CGRectEqualToRect(rect2, result)); | |
76 } | |
77 } | |
78 | |
79 TEST_F(ContentSuggestionsCollectionUtilsTest, centeredTilesMarginIPhone6) { | |
80 // Setup. | |
81 SetAsIPhone(); | |
82 | |
83 // Action. | |
84 CGFloat result = centeredTilesMarginForWidth(374); | |
85 | |
86 // Tests. | |
87 EXPECT_EQ(17, result); | |
88 } | |
89 | |
90 TEST_F(ContentSuggestionsCollectionUtilsTest, centeredTilesMarginIPad) { | |
91 // Setup. | |
92 SetAsIPad(); | |
93 | |
94 // Action. | |
95 CGFloat result = centeredTilesMarginForWidth(700); | |
96 | |
97 // Tests. | |
98 EXPECT_EQ(168, result); | |
99 } | |
100 | |
101 TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrame) { | |
102 // Setup. | |
103 CGFloat yValue = 66; | |
104 if (IsIPadIdiom()) | |
105 yValue = 82; | |
106 | |
107 // Action. | |
108 CGRect result = doodleFrame(500, YES); | |
109 | |
110 // Test. | |
111 EXPECT_TRUE(CGRectEqualToRect(CGRectMake(0, yValue, 500, 120), result)); | |
112 } | |
113 | |
114 TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrame) { | |
115 // Setup. | |
116 CGFloat width = 500; | |
117 CGFloat margin = centeredTilesMarginForWidth(width); | |
118 CGFloat offset = 0; | |
119 if (IsIPadIdiom()) | |
120 offset = 66; | |
121 | |
122 // Action. | |
123 CGRect result = searchFieldFrame(width, YES); | |
124 | |
125 // Test. | |
126 EXPECT_TRUE(CGRectEqualToRect( | |
127 CGRectMake(margin, 218 + offset, 500 - 2 * margin, 50), result)); | |
128 } | |
129 | |
130 TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeader) { | |
131 // Setup. | |
132 CGFloat yValue = 284; | |
133 CGFloat offset = 0; | |
134 if (IsIPadIdiom()) { | |
135 yValue = 350; | |
136 offset = 56; | |
137 } | |
138 | |
139 // Action, tests. | |
140 EXPECT_EQ(yValue, heightForLogoHeader(500, YES, YES)); | |
141 EXPECT_EQ(yValue + offset, heightForLogoHeader(500, YES, NO)); | |
142 } | |
143 | |
144 TEST_F(ContentSuggestionsCollectionUtilsTest, SizeIPhone6) { | |
145 // Setup. | |
146 SetAsIPhone(); | |
147 | |
148 // Test. | |
149 EXPECT_EQ(4U, numberOfTilesForWidth(360)); | |
150 } | |
151 | |
152 TEST_F(ContentSuggestionsCollectionUtilsTest, SizeIPhone5) { | |
153 // Setup. | |
154 SetAsIPhone(); | |
155 | |
156 // Test. | |
157 EXPECT_EQ(3U, numberOfTilesForWidth(320)); | |
158 } | |
159 | |
160 // Test for iPad portrait and iPhone landscape. | |
161 TEST_F(ContentSuggestionsCollectionUtilsTest, SizeLarge) { | |
162 // Test. | |
163 EXPECT_EQ(4U, numberOfTilesForWidth(720)); | |
164 } | |
165 | |
166 TEST_F(ContentSuggestionsCollectionUtilsTest, SizeIPadSplit) { | |
167 // Setup. | |
168 SetAsIPad(); | |
169 | |
170 // Test. | |
171 EXPECT_EQ(3U, numberOfTilesForWidth(360)); | |
172 } | |
173 | |
174 } // namespace content_suggestions | |
OLD | NEW |