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/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 TEST(ContentSuggestionsCollectionUtilsTest, orientationFramePortrait) { | |
| 20 // Setup. | |
| 21 CGRect rect1 = CGRectMake(10, 10, 0, 10); | |
| 22 CGRect rect2 = CGRectMake(20, 20, 0, 20); | |
| 23 const CGRect rects[2] = {rect1, rect2}; | |
| 24 | |
| 25 // Action. | |
| 26 CGRect result = getOrientationFrame(rects, 400); | |
| 27 | |
| 28 // Tests. | |
| 29 rect1.size.width = 380; | |
| 30 EXPECT_TRUE(CGRectEqualToRect(rect1, result)); | |
| 31 } | |
| 32 | |
| 33 TEST(ContentSuggestionsCollectionUtilsTest, orientationFrameLandscape) { | |
| 34 // Setup. | |
| 35 CGRect rect1 = CGRectMake(10, 10, 0, 10); | |
| 36 CGRect rect2 = CGRectMake(20, 20, 0, 20); | |
| 37 const CGRect rects[2] = {rect1, rect2}; | |
| 38 std::unique_ptr<ScopedBlockSwizzler> safe_mode_swizzler_ = | |
|
marq (ping after 24h)
2017/05/10 09:23:49
orientation_swizzler seems like a better name.
Al
gambard
2017/05/10 11:09:40
Done.
| |
| 39 base::MakeUnique<ScopedBlockSwizzler>( | |
| 40 [UIApplication class], @selector(statusBarOrientation), | |
| 41 ^UIInterfaceOrientation(id self) { | |
| 42 return UIInterfaceOrientationLandscapeLeft; | |
| 43 }); | |
| 44 | |
| 45 // Action. | |
| 46 CGRect result = getOrientationFrame(rects, 400); | |
| 47 | |
| 48 // Tests. | |
| 49 rect1.size.width = 380; | |
| 50 rect2.size.width = 360; | |
| 51 if (IsIPadIdiom()) { | |
| 52 EXPECT_TRUE(CGRectEqualToRect(rect1, result)); | |
| 53 } else { | |
| 54 EXPECT_TRUE(CGRectEqualToRect(rect2, result)); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 TEST(ContentSuggestionsCollectionUtilsTest, centeredTilesMarginIPhone6) { | |
| 59 // Setup. | |
| 60 if (IsIPadIdiom()) | |
| 61 return; | |
| 62 | |
| 63 // Action. | |
| 64 CGFloat result = centeredTilesMarginForWidth(374); | |
| 65 | |
| 66 // Tests. | |
| 67 EXPECT_EQ(17, result); | |
| 68 } | |
| 69 | |
| 70 TEST(ContentSuggestionsCollectionUtilsTest, centeredTilesMarginIPad) { | |
| 71 // Setup. | |
| 72 if (!IsIPadIdiom()) | |
|
marq (ping after 24h)
2017/05/10 09:23:49
Can you swizzle UIDevice's -userInterfaceIdiom to
gambard
2017/05/10 11:09:40
Done.
| |
| 73 return; | |
| 74 | |
| 75 // Action. | |
| 76 CGFloat result = centeredTilesMarginForWidth(700); | |
| 77 | |
| 78 // Tests. | |
| 79 EXPECT_EQ(168, result); | |
| 80 } | |
| 81 | |
| 82 TEST(ContentSuggestionsCollectionUtilsTest, doodleFrame) { | |
| 83 // Setup. | |
| 84 CGFloat yValue = 66; | |
| 85 if (IsIPadIdiom()) | |
| 86 yValue = 82; | |
| 87 | |
| 88 // Action. | |
| 89 CGRect result = doodleFrame(500, YES); | |
| 90 | |
| 91 // Test. | |
| 92 EXPECT_TRUE(CGRectEqualToRect(CGRectMake(0, yValue, 500, 120), result)); | |
| 93 } | |
| 94 | |
| 95 TEST(ContentSuggestionsCollectionUtilsTest, searchFieldFrame) { | |
| 96 // Setup. | |
| 97 CGFloat width = 500; | |
| 98 CGFloat margin = centeredTilesMarginForWidth(width); | |
| 99 CGFloat offset = 0; | |
| 100 if (IsIPadIdiom()) | |
| 101 offset = 66; | |
| 102 | |
| 103 // Action. | |
| 104 CGRect result = searchFieldFrame(width, YES); | |
| 105 | |
| 106 // Test. | |
| 107 EXPECT_TRUE(CGRectEqualToRect( | |
| 108 CGRectMake(margin, 218 + offset, 500 - 2 * margin, 50), result)); | |
| 109 } | |
| 110 | |
| 111 TEST(ContentSuggestionsCollectionUtilsTest, heightForLogoHeader) { | |
| 112 // Setup. | |
| 113 CGFloat yValue = 284; | |
| 114 CGFloat offset = 0; | |
| 115 if (IsIPadIdiom()) { | |
| 116 yValue = 350; | |
| 117 offset = 56; | |
| 118 } | |
| 119 | |
| 120 // Action, tests. | |
| 121 EXPECT_EQ(yValue, heightForLogoHeader(500, YES, YES)); | |
| 122 EXPECT_EQ(yValue + offset, heightForLogoHeader(500, YES, NO)); | |
| 123 } | |
| 124 | |
| 125 } // namespace content_suggestions | |
| OLD | NEW |