OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/layout/LayoutText.h" | 5 #include "core/layout/LayoutText.h" |
6 | 6 |
7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
8 #include "core/layout/line/InlineTextBox.h" | 8 #include "core/layout/line/InlineTextBox.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 return toLayoutText(getLayoutObjectByElementId("target")->slowFirstChild()); | 23 return toLayoutText(getLayoutObjectByElementId("target")->slowFirstChild()); |
24 } | 24 } |
25 }; | 25 }; |
26 | 26 |
27 const char* kTacoText = "Los Compadres Taco Truck"; | 27 const char* kTacoText = "Los Compadres Taco Truck"; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 TEST_F(LayoutTextTest, WidthZeroFromZeroLength) { | 31 TEST_F(LayoutTextTest, WidthZeroFromZeroLength) { |
32 setBasicBody(kTacoText); | 32 setBasicBody(kTacoText); |
33 ASSERT_EQ(0, getBasicText()->width(0u, 0u, LayoutUnit(), TextDirection::Ltr, | 33 ASSERT_EQ(0, getBasicText()->width(0u, 0u, LayoutUnit(), TextDirection::kLtr, |
34 false)); | 34 false)); |
35 } | 35 } |
36 | 36 |
37 TEST_F(LayoutTextTest, WidthMaxFromZeroLength) { | 37 TEST_F(LayoutTextTest, WidthMaxFromZeroLength) { |
38 setBasicBody(kTacoText); | 38 setBasicBody(kTacoText); |
39 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, | 39 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, |
40 LayoutUnit(), TextDirection::Ltr, false)); | 40 LayoutUnit(), TextDirection::kLtr, false)); |
41 } | 41 } |
42 | 42 |
43 TEST_F(LayoutTextTest, WidthZeroFromMaxLength) { | 43 TEST_F(LayoutTextTest, WidthZeroFromMaxLength) { |
44 setBasicBody(kTacoText); | 44 setBasicBody(kTacoText); |
45 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max(), | 45 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max(), |
46 LayoutUnit(), TextDirection::Ltr, false); | 46 LayoutUnit(), TextDirection::kLtr, false); |
47 // Width may vary by platform and we just want to make sure it's something | 47 // Width may vary by platform and we just want to make sure it's something |
48 // roughly reasonable. | 48 // roughly reasonable. |
49 ASSERT_GE(width, 100.f); | 49 ASSERT_GE(width, 100.f); |
50 ASSERT_LE(width, 160.f); | 50 ASSERT_LE(width, 160.f); |
51 } | 51 } |
52 | 52 |
53 TEST_F(LayoutTextTest, WidthMaxFromMaxLength) { | 53 TEST_F(LayoutTextTest, WidthMaxFromMaxLength) { |
54 setBasicBody(kTacoText); | 54 setBasicBody(kTacoText); |
55 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), | 55 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), |
56 std::numeric_limits<unsigned>::max(), | 56 std::numeric_limits<unsigned>::max(), |
57 LayoutUnit(), TextDirection::Ltr, false)); | 57 LayoutUnit(), TextDirection::kLtr, false)); |
58 } | 58 } |
59 | 59 |
60 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow) { | 60 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow) { |
61 // The test case from http://crbug.com/647820 uses a 288-length string, so for | 61 // The test case from http://crbug.com/647820 uses a 288-length string, so for |
62 // posterity we follow that closely. | 62 // posterity we follow that closely. |
63 setBodyInnerHTML( | 63 setBodyInnerHTML( |
64 "<div " | 64 "<div " |
65 "id='target'>" | 65 "id='target'>" |
66 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 66 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
67 "xxxx" | 67 "xxxx" |
68 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 68 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
70 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 70 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
71 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 71 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
72 "</div>"); | 72 "</div>"); |
73 // Width may vary by platform and we just want to make sure it's something | 73 // Width may vary by platform and we just want to make sure it's something |
74 // roughly reasonable. | 74 // roughly reasonable. |
75 const float width = getBasicText()->width( | 75 const float width = getBasicText()->width( |
76 23u, 4294967282u, LayoutUnit(2.59375), TextDirection::Rtl, false); | 76 23u, 4294967282u, LayoutUnit(2.59375), TextDirection::kRtl, false); |
77 ASSERT_GE(width, 100.f); | 77 ASSERT_GE(width, 100.f); |
78 ASSERT_LE(width, 300.f); | 78 ASSERT_LE(width, 300.f); |
79 } | 79 } |
80 | 80 |
81 TEST_F(LayoutTextTest, WidthFromBeyondLength) { | 81 TEST_F(LayoutTextTest, WidthFromBeyondLength) { |
82 setBasicBody("x"); | 82 setBasicBody("x"); |
83 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), TextDirection::Ltr, | 83 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), TextDirection::kLtr, |
84 false)); | 84 false)); |
85 } | 85 } |
86 | 86 |
87 TEST_F(LayoutTextTest, WidthLengthBeyondLength) { | 87 TEST_F(LayoutTextTest, WidthLengthBeyondLength) { |
88 setBasicBody("x"); | 88 setBasicBody("x"); |
89 // Width may vary by platform and we just want to make sure it's something | 89 // Width may vary by platform and we just want to make sure it's something |
90 // roughly reasonable. | 90 // roughly reasonable. |
91 const float width = | 91 const float width = |
92 getBasicText()->width(0u, 2u, LayoutUnit(), TextDirection::Ltr, false); | 92 getBasicText()->width(0u, 2u, LayoutUnit(), TextDirection::kLtr, false); |
93 ASSERT_GE(width, 4.f); | 93 ASSERT_GE(width, 4.f); |
94 ASSERT_LE(width, 20.f); | 94 ASSERT_LE(width, 20.f); |
95 } | 95 } |
96 | 96 |
97 } // namespace blink | 97 } // namespace blink |
OLD | NEW |