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

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: 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
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(USHRT_MAX, 0u, LayoutUnit(), LTR, false)) ;
42 }
43
44 TEST_F(LayoutTextTest, WidthZeroFromMaxLength)
45 {
46 setBasicBody(kTacoText);
47 float width = getBasicText()->width(0u, USHRT_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, 120.f);
50 ASSERT_LE(width, 160.f);
51 }
52
53 TEST_F(LayoutTextTest, WidthMaxFromMaxLength)
54 {
55 setBasicBody(kTacoText);
56 ASSERT_EQ(0, getBasicText()->width(USHRT_MAX, USHRT_MAX, LayoutUnit(), LTR, false));
57 }
58
59 TEST_F(LayoutTextTest, WidthWithHugeLengthAvoidsOverflow)
60 {
61 // The test case from http://crbug.com/647820 uses a 288-length string, so f or posterity we follow that closely.
62 setBodyInnerHTML("<div id='target'>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
63 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
64 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
65 "</div>");
66 // Width may vary by platform and we just want to make sure it's something r oughly reasonable.
67 float width = getBasicText()->width(23u, 4294967282u, LayoutUnit(2.59375), R TL, false);
68 ASSERT_GE(width, 200.f);
69 ASSERT_LE(width, 300.f);
70 }
71
72 TEST_F(LayoutTextTest, WidthFromBeyondLength)
73 {
74 setBasicBody("x");
75 ASSERT_EQ(0u, getBasicText()->width(1u, 1u, LayoutUnit(), LTR, false));
76 }
77
78 TEST_F(LayoutTextTest, WidthLengthBeyondLength)
79 {
80 setBasicBody("x");
81 // Width may vary by platform and we just want to make sure it's something r oughly reasonable.
82 float width = getBasicText()->width(0u, 2u, LayoutUnit(), LTR, false);
83 ASSERT_GE(width, 4.f);
84 ASSERT_LE(width, 20.f);
85 }
86
87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698