Chromium Code Reviews| 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(), LTR, false)); | 33 ASSERT_EQ(0, getBasicText()->width(0u, 0u, LayoutUnit(), TextDirection::Ltr, |
| 34 false)); | |
| 34 } | 35 } |
| 35 | 36 |
| 36 TEST_F(LayoutTextTest, WidthMaxFromZeroLength) { | 37 TEST_F(LayoutTextTest, WidthMaxFromZeroLength) { |
| 37 setBasicBody(kTacoText); | 38 setBasicBody(kTacoText); |
| 38 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, | 39 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, |
| 39 LayoutUnit(), LTR, false)); | 40 LayoutUnit(), TextDirection::Ltr, false)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 TEST_F(LayoutTextTest, WidthZeroFromMaxLength) { | 43 TEST_F(LayoutTextTest, WidthZeroFromMaxLength) { |
| 43 setBasicBody(kTacoText); | 44 setBasicBody(kTacoText); |
| 44 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max(), | 45 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max(), |
| 45 LayoutUnit(), LTR, false); | 46 LayoutUnit(), TextDirection::Ltr, false); |
| 46 // 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 |
| 47 // roughly reasonable. | 48 // roughly reasonable. |
| 48 ASSERT_GE(width, 100.f); | 49 ASSERT_GE(width, 100.f); |
| 49 ASSERT_LE(width, 160.f); | 50 ASSERT_LE(width, 160.f); |
| 50 } | 51 } |
| 51 | 52 |
| 52 TEST_F(LayoutTextTest, WidthMaxFromMaxLength) { | 53 TEST_F(LayoutTextTest, WidthMaxFromMaxLength) { |
| 53 setBasicBody(kTacoText); | 54 setBasicBody(kTacoText); |
| 54 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), | 55 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), |
| 55 std::numeric_limits<unsigned>::max(), | 56 std::numeric_limits<unsigned>::max(), |
| 56 LayoutUnit(), LTR, false)); | 57 LayoutUnit(), TextDirection::Ltr, false)); |
| 57 } | 58 } |
| 58 | 59 |
| 59 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow) { | 60 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow) { |
| 60 // 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 |
| 61 // posterity we follow that closely. | 62 // posterity we follow that closely. |
| 62 setBodyInnerHTML( | 63 setBodyInnerHTML( |
| 63 "<div " | 64 "<div " |
| 64 "id='target'>" | 65 "id='target'>" |
| 65 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 66 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 66 "xxxx" | 67 "xxxx" |
| 67 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 68 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 68 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 69 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 70 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 70 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | 71 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 71 "</div>"); | 72 "</div>"); |
| 72 // 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 |
| 73 // roughly reasonable. | 74 // roughly reasonable. |
| 74 float width = | 75 float width = getBasicText()->width(23u, 4294967282u, LayoutUnit(2.59375), |
|
napper
2016/12/07 05:27:13
const float width = ...
sashab
2016/12/07 05:40:26
Done
| |
| 75 getBasicText()->width(23u, 4294967282u, LayoutUnit(2.59375), RTL, false); | 76 TextDirection::Rtl, false); |
| 76 ASSERT_GE(width, 100.f); | 77 ASSERT_GE(width, 100.f); |
| 77 ASSERT_LE(width, 300.f); | 78 ASSERT_LE(width, 300.f); |
| 78 } | 79 } |
| 79 | 80 |
| 80 TEST_F(LayoutTextTest, WidthFromBeyondLength) { | 81 TEST_F(LayoutTextTest, WidthFromBeyondLength) { |
| 81 setBasicBody("x"); | 82 setBasicBody("x"); |
| 82 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), LTR, false)); | 83 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), TextDirection::Ltr, |
| 84 false)); | |
| 83 } | 85 } |
| 84 | 86 |
| 85 TEST_F(LayoutTextTest, WidthLengthBeyondLength) { | 87 TEST_F(LayoutTextTest, WidthLengthBeyondLength) { |
| 86 setBasicBody("x"); | 88 setBasicBody("x"); |
| 87 // 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 |
| 88 // roughly reasonable. | 90 // roughly reasonable. |
| 89 float width = getBasicText()->width(0u, 2u, LayoutUnit(), LTR, false); | 91 float width = |
|
napper
2016/12/07 05:27:13
const float width = ...
sashab
2016/12/07 05:40:26
Done
| |
| 92 getBasicText()->width(0u, 2u, LayoutUnit(), TextDirection::Ltr, false); | |
| 90 ASSERT_GE(width, 4.f); | 93 ASSERT_GE(width, 4.f); |
| 91 ASSERT_LE(width, 20.f); | 94 ASSERT_LE(width, 20.f); |
| 92 } | 95 } |
| 93 | 96 |
| 94 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |