Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTextTest.cpp

Issue 2345633007: Don't overflow in LayoutText::width() on a huge length. (Closed)
Patch Set: Tweak test ranges for Mac results. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutText.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/layout/LayoutText.h"
6
7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/line/InlineTextBox.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace blink {
12
13 namespace {
14
15 class LayoutTextTest : public RenderingTest {
16 public:
17 void setBasicBody(const char* message)
18 {
19 setBodyInnerHTML(String::format("<div id='target' style='font-size: 10px ;'>%s</div>", message));
20 }
21
22 LayoutText* getBasicText()
23 {
24 return toLayoutText(getLayoutObjectByElementId("target")->slowFirstChild ());
25 }
26 };
27
28 const char* kTacoText = "Los Compadres Taco Truck";
29
30 } // namespace
31
32 TEST_F(LayoutTextTest, WidthZeroFromZeroLength)
33 {
34 setBasicBody(kTacoText);
35 ASSERT_EQ(0, getBasicText()->width(0u, 0u, LayoutUnit(), LTR, false));
36 }
37
38 TEST_F(LayoutTextTest, WidthMaxFromZeroLength)
39 {
40 setBasicBody(kTacoText);
41 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(), 0u, LayoutUnit(), LTR, false));
42 }
43
44 TEST_F(LayoutTextTest, WidthZeroFromMaxLength)
45 {
46 setBasicBody(kTacoText);
47 float width = getBasicText()->width(0u, std::numeric_limits<unsigned>::max() , LayoutUnit(), LTR, false);
48 // Width may vary by platform and we just want to make sure it's something r oughly reasonable.
49 ASSERT_GE(width, 100.f);
50 ASSERT_LE(width, 160.f);
51 }
52
53 TEST_F(LayoutTextTest, WidthMaxFromMaxLength)
54 {
55 setBasicBody(kTacoText);
56 ASSERT_EQ(0, getBasicText()->width(std::numeric_limits<unsigned>::max(),
57 std::numeric_limits<unsigned>::max(), LayoutUnit(), LTR, false));
58 }
59
60 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow)
61 {
62 // The test case from http://crbug.com/647820 uses a 288-length string, so f or posterity we follow that closely.
63 setBodyInnerHTML("<div id='target'>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
64 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
65 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
66 "</div>");
67 // Width may vary by platform and we just want to make sure it's something r oughly reasonable.
68 float width = getBasicText()->width(23u, 4294967282u, LayoutUnit(2.59375), R TL, false);
69 ASSERT_GE(width, 100.f);
70 ASSERT_LE(width, 300.f);
71 }
72
73 TEST_F(LayoutTextTest, WidthFromBeyondLength)
74 {
75 setBasicBody("x");
76 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), LTR, false));
77 }
78
79 TEST_F(LayoutTextTest, WidthLengthBeyondLength)
80 {
81 setBasicBody("x");
82 // Width may vary by platform and we just want to make sure it's something r oughly reasonable.
83 float width = getBasicText()->width(0u, 2u, LayoutUnit(), LTR, false);
84 ASSERT_GE(width, 4.f);
85 ASSERT_LE(width, 20.f);
86 }
87
88 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutText.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698