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::kLtr, | 33 ASSERT_EQ( |
34 false)); | 34 0, |
| 35 getBasicText()->width(0u, 0u, LayoutUnit(), TextDirection::kLtr, false)); |
35 } | 36 } |
36 | 37 |
37 TEST_F(LayoutTextTest, WidthMaxFromZeroLength) { | 38 TEST_F(LayoutTextTest, WidthMaxFromZeroLength) { |
38 setBasicBody(kTacoText); | 39 setBasicBody(kTacoText); |
39 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, | 40 ASSERT_EQ(0, |
40 LayoutUnit(), TextDirection::kLtr, false)); | 41 getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, |
| 42 LayoutUnit(), TextDirection::kLtr, false)); |
41 } | 43 } |
42 | 44 |
43 TEST_F(LayoutTextTest, WidthZeroFromMaxLength) { | 45 TEST_F(LayoutTextTest, WidthZeroFromMaxLength) { |
44 setBasicBody(kTacoText); | 46 setBasicBody(kTacoText); |
45 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max(), | 47 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max(), |
46 LayoutUnit(), TextDirection::kLtr, false); | 48 LayoutUnit(), TextDirection::kLtr, false); |
47 // Width may vary by platform and we just want to make sure it's something | 49 // Width may vary by platform and we just want to make sure it's something |
48 // roughly reasonable. | 50 // roughly reasonable. |
49 ASSERT_GE(width, 100.f); | 51 ASSERT_GE(width, 100.f); |
50 ASSERT_LE(width, 160.f); | 52 ASSERT_LE(width, 160.f); |
51 } | 53 } |
52 | 54 |
53 TEST_F(LayoutTextTest, WidthMaxFromMaxLength) { | 55 TEST_F(LayoutTextTest, WidthMaxFromMaxLength) { |
54 setBasicBody(kTacoText); | 56 setBasicBody(kTacoText); |
55 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), | 57 ASSERT_EQ(0, |
56 std::numeric_limits<unsigned>::max(), | 58 getBasicText()->width(std::numeric_limits<unsigned>::max(), |
57 LayoutUnit(), TextDirection::kLtr, false)); | 59 std::numeric_limits<unsigned>::max(), |
| 60 LayoutUnit(), TextDirection::kLtr, false)); |
58 } | 61 } |
59 | 62 |
60 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow) { | 63 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow) { |
61 // The test case from http://crbug.com/647820 uses a 288-length string, so for | 64 // The test case from http://crbug.com/647820 uses a 288-length string, so for |
62 // posterity we follow that closely. | 65 // posterity we follow that closely. |
63 setBodyInnerHTML( | 66 setBodyInnerHTML( |
64 "<div " | 67 "<div " |
65 "id='target'>" | 68 "id='target'>" |
66 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
67 "xxxx" | 70 "xxxx" |
68 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 71 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 72 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
70 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 73 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
71 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 74 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
72 "</div>"); | 75 "</div>"); |
73 // Width may vary by platform and we just want to make sure it's something | 76 // Width may vary by platform and we just want to make sure it's something |
74 // roughly reasonable. | 77 // roughly reasonable. |
75 const float width = getBasicText()->width( | 78 const float width = getBasicText()->width( |
76 23u, 4294967282u, LayoutUnit(2.59375), TextDirection::kRtl, false); | 79 23u, 4294967282u, LayoutUnit(2.59375), TextDirection::kRtl, false); |
77 ASSERT_GE(width, 100.f); | 80 ASSERT_GE(width, 100.f); |
78 ASSERT_LE(width, 300.f); | 81 ASSERT_LE(width, 300.f); |
79 } | 82 } |
80 | 83 |
81 TEST_F(LayoutTextTest, WidthFromBeyondLength) { | 84 TEST_F(LayoutTextTest, WidthFromBeyondLength) { |
82 setBasicBody("x"); | 85 setBasicBody("x"); |
83 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), TextDirection::kLtr, | 86 ASSERT_EQ( |
84 false)); | 87 0u, |
| 88 getBasicText()->width(1u, 1u, LayoutUnit(), TextDirection::kLtr, false)); |
85 } | 89 } |
86 | 90 |
87 TEST_F(LayoutTextTest, WidthLengthBeyondLength) { | 91 TEST_F(LayoutTextTest, WidthLengthBeyondLength) { |
88 setBasicBody("x"); | 92 setBasicBody("x"); |
89 // Width may vary by platform and we just want to make sure it's something | 93 // Width may vary by platform and we just want to make sure it's something |
90 // roughly reasonable. | 94 // roughly reasonable. |
91 const float width = | 95 const float width = |
92 getBasicText()->width(0u, 2u, LayoutUnit(), TextDirection::kLtr, false); | 96 getBasicText()->width(0u, 2u, LayoutUnit(), TextDirection::kLtr, false); |
93 ASSERT_GE(width, 4.f); | 97 ASSERT_GE(width, 4.f); |
94 ASSERT_LE(width, 20.f); | 98 ASSERT_LE(width, 20.f); |
95 } | 99 } |
96 | 100 |
97 } // namespace blink | 101 } // namespace blink |
OLD | NEW |