OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h" |
| 6 |
| 7 #include "base/i18n/rtl.h" |
| 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "testing/platform_test.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 class BidiContainerViewTest : public PlatformTest { |
| 14 protected: |
| 15 void SetUp() override { defaultLocale_ = base::i18n::GetConfiguredLocale(); }; |
| 16 void TearDown() override { base::i18n::SetICUDefaultLocale(defaultLocale_); } |
| 17 UIViewAutoresizing AutoresizingMaskForLocale(const char* locale, |
| 18 UIViewAutoresizing autoresizing); |
| 19 std::string defaultLocale_; |
| 20 }; |
| 21 |
| 22 UIViewAutoresizing BidiContainerViewTest::AutoresizingMaskForLocale( |
| 23 const char* locale, |
| 24 UIViewAutoresizing autoresizing) { |
| 25 base::i18n::SetICUDefaultLocale(base::i18n::GetCanonicalLocale(locale)); |
| 26 base::scoped_nsobject<BidiContainerView> view( |
| 27 [[BidiContainerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]); |
| 28 base::scoped_nsobject<UILabel> label( |
| 29 [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 40, 50)]); |
| 30 [label setAutoresizingMask:autoresizing]; |
| 31 [view addSubview:label]; |
| 32 [view layoutSubviews]; |
| 33 return [label autoresizingMask]; |
| 34 } |
| 35 |
| 36 TEST_F(BidiContainerViewTest, InitializeLeftToRight) { |
| 37 base::i18n::SetICUDefaultLocale( |
| 38 base::i18n::GetCanonicalLocale("en" /* English */)); |
| 39 base::scoped_nsobject<BidiContainerView> view( |
| 40 [[BidiContainerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]); |
| 41 base::scoped_nsobject<UILabel> label( |
| 42 [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 40, 50)]); |
| 43 [view addSubview:label]; |
| 44 [view layoutSubviews]; |
| 45 CGRect labelFrame = [label frame]; |
| 46 EXPECT_EQ(20, labelFrame.origin.x); |
| 47 EXPECT_EQ(30, labelFrame.origin.y); |
| 48 EXPECT_EQ(40, labelFrame.size.width); |
| 49 EXPECT_EQ(50, labelFrame.size.height); |
| 50 } |
| 51 |
| 52 TEST_F(BidiContainerViewTest, InitializeRightToLeft) { |
| 53 base::i18n::SetICUDefaultLocale( |
| 54 base::i18n::GetCanonicalLocale("he" /* Hebrew */)); |
| 55 base::scoped_nsobject<BidiContainerView> view( |
| 56 [[BidiContainerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]); |
| 57 base::scoped_nsobject<UILabel> label( |
| 58 [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 40, 50)]); |
| 59 [view addSubview:label]; |
| 60 [view layoutSubviews]; |
| 61 CGRect labelFrame = [label frame]; |
| 62 EXPECT_EQ(100 - 20 - 40 /* view.width - label.originX - label.width */, |
| 63 labelFrame.origin.x); |
| 64 EXPECT_EQ(30, labelFrame.origin.y); |
| 65 EXPECT_EQ(40, labelFrame.size.width); |
| 66 EXPECT_EQ(50, labelFrame.size.height); |
| 67 } |
| 68 |
| 69 TEST_F(BidiContainerViewTest, InitializeRightToLeftTwoViews) { |
| 70 base::i18n::SetICUDefaultLocale( |
| 71 base::i18n::GetCanonicalLocale("he" /* Hebrew */)); |
| 72 base::scoped_nsobject<BidiContainerView> view( |
| 73 [[BidiContainerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]); |
| 74 base::scoped_nsobject<UILabel> label1( |
| 75 [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 40, 50)]); |
| 76 [view addSubview:label1]; |
| 77 base::scoped_nsobject<UILabel> label2( |
| 78 [[UILabel alloc] initWithFrame:CGRectMake(60, 30, 30, 50)]); |
| 79 [view addSubview:label2]; |
| 80 [view layoutSubviews]; |
| 81 EXPECT_EQ(100 - 20 - 40 /* view.width - label1.originX - label1.width */, |
| 82 [label1 frame].origin.x); |
| 83 EXPECT_EQ(100 - 60 - 30 /* view.width - label2.originX - label2.width */, |
| 84 [label2 frame].origin.x); |
| 85 } |
| 86 |
| 87 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleLeftForRightToLeft) { |
| 88 UIViewAutoresizing otherFlags = |
| 89 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin; |
| 90 UIViewAutoresizing testedFlags = UIViewAutoresizingFlexibleLeftMargin; |
| 91 UIViewAutoresizing adjustedFlags = |
| 92 AutoresizingMaskForLocale("he" /* Hebrew */, otherFlags | testedFlags); |
| 93 EXPECT_EQ(UIViewAutoresizingFlexibleRightMargin | otherFlags, adjustedFlags); |
| 94 EXPECT_FALSE(UIViewAutoresizingFlexibleLeftMargin & adjustedFlags); |
| 95 } |
| 96 |
| 97 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleLeftForLeftToRight) { |
| 98 UIViewAutoresizing otherFlags = |
| 99 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin; |
| 100 UIViewAutoresizing testedFlags = UIViewAutoresizingFlexibleLeftMargin; |
| 101 UIViewAutoresizing adjustedFlags = |
| 102 AutoresizingMaskForLocale("en" /* English */, otherFlags | testedFlags); |
| 103 EXPECT_EQ(UIViewAutoresizingFlexibleLeftMargin | otherFlags, adjustedFlags); |
| 104 EXPECT_FALSE(UIViewAutoresizingFlexibleRightMargin & adjustedFlags); |
| 105 } |
| 106 |
| 107 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleRightForRightToLeft) { |
| 108 UIViewAutoresizing otherFlags = UIViewAutoresizingNone; |
| 109 UIViewAutoresizing testedFlags = UIViewAutoresizingFlexibleRightMargin; |
| 110 UIViewAutoresizing adjustedFlags = |
| 111 AutoresizingMaskForLocale("he" /* Hebrew */, otherFlags | testedFlags); |
| 112 EXPECT_EQ(UIViewAutoresizingFlexibleLeftMargin | otherFlags, adjustedFlags); |
| 113 EXPECT_FALSE(UIViewAutoresizingFlexibleRightMargin & adjustedFlags); |
| 114 } |
| 115 |
| 116 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleRightForLeftToRight) { |
| 117 UIViewAutoresizing otherFlags = UIViewAutoresizingNone; |
| 118 UIViewAutoresizing testedFlags = UIViewAutoresizingFlexibleRightMargin; |
| 119 UIViewAutoresizing adjustedFlags = |
| 120 AutoresizingMaskForLocale("en" /* English */, otherFlags | testedFlags); |
| 121 EXPECT_EQ(UIViewAutoresizingFlexibleRightMargin | otherFlags, adjustedFlags); |
| 122 EXPECT_FALSE(UIViewAutoresizingFlexibleLeftMargin & adjustedFlags); |
| 123 } |
| 124 |
| 125 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleBothForRightToLeft) { |
| 126 UIViewAutoresizing otherFlags = |
| 127 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; |
| 128 UIViewAutoresizing testedFlags = UIViewAutoresizingFlexibleRightMargin | |
| 129 UIViewAutoresizingFlexibleLeftMargin; |
| 130 UIViewAutoresizing adjustedFlags = |
| 131 AutoresizingMaskForLocale("he" /* Hebrew */, otherFlags | testedFlags); |
| 132 EXPECT_EQ(UIViewAutoresizingFlexibleRightMargin | |
| 133 UIViewAutoresizingFlexibleLeftMargin | otherFlags, |
| 134 adjustedFlags); |
| 135 } |
| 136 |
| 137 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleBothForLeftToRight) { |
| 138 UIViewAutoresizing otherFlags = |
| 139 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; |
| 140 UIViewAutoresizing testedFlags = UIViewAutoresizingFlexibleRightMargin | |
| 141 UIViewAutoresizingFlexibleLeftMargin; |
| 142 UIViewAutoresizing adjustedFlags = |
| 143 AutoresizingMaskForLocale("en" /* English */, otherFlags | testedFlags); |
| 144 EXPECT_EQ(UIViewAutoresizingFlexibleRightMargin | |
| 145 UIViewAutoresizingFlexibleLeftMargin | otherFlags, |
| 146 adjustedFlags); |
| 147 } |
| 148 |
| 149 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleNoneForRightToLeft) { |
| 150 UIViewAutoresizing flags = UIViewAutoresizingNone; |
| 151 UIViewAutoresizing adjustedFlags = |
| 152 AutoresizingMaskForLocale("he" /* Hebrew */, flags); |
| 153 EXPECT_EQ(flags, adjustedFlags); |
| 154 } |
| 155 |
| 156 TEST_F(BidiContainerViewTest, SetAutoresizingFlexibleNoneForLeftToRight) { |
| 157 UIViewAutoresizing flags = UIViewAutoresizingNone; |
| 158 UIViewAutoresizing adjustedFlags = |
| 159 AutoresizingMaskForLocale("en" /* English */, flags); |
| 160 EXPECT_EQ(flags, adjustedFlags); |
| 161 } |
| 162 |
| 163 } // namespace |
OLD | NEW |