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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserValuesTest.cpp

Issue 1883983003: Remove CSSParserValues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 /*
2 * Copyright 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "core/css/parser/CSSParserValues.h"
32
33 #include "core/css/parser/CSSParserTokenRange.h"
34 #include "core/css/parser/CSSTokenizer.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36
37 namespace blink {
38
39 TEST(CSSParserValuesTest, InitWithEmptyString)
40 {
41 String string;
42
43 CSSParserString cssParserString;
44 cssParserString.init(string);
45 EXPECT_EQ(0u, cssParserString.length());
46 EXPECT_EQ(string, String(cssParserString));
47 EXPECT_TRUE(String(cssParserString).isNull());
48
49 string = "";
50 cssParserString.init(string);
51 EXPECT_EQ(0u, cssParserString.length());
52 EXPECT_EQ(string, String(cssParserString));
53 EXPECT_FALSE(String(cssParserString).isNull());
54
55 string.ensure16Bit();
56 cssParserString.init(string);
57 EXPECT_EQ(0u, cssParserString.length());
58 EXPECT_EQ(string, String(cssParserString));
59 EXPECT_FALSE(String(cssParserString).isNull());
60 }
61
62 TEST(CSSParserValuesTest, EqualIgnoringASCIICase8BitsString)
63 {
64 CSSParserString cssParserString;
65 String string8bit("sHaDOw");
66 cssParserString.init(string8bit);
67
68 ASSERT_TRUE(cssParserString.equalIgnoringASCIICase("shadow"));
69 ASSERT_TRUE(cssParserString.equalIgnoringASCIICase("ShaDow"));
70 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("shadow-all"));
71 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("sha"));
72 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("abCD"));
73 }
74
75 TEST(CSSParserValuesTest, EqualIgnoringASCIICase16BitsString)
76 {
77 String string16bit("sHaDOw");
78 string16bit.ensure16Bit();
79
80 CSSParserString cssParserString;
81 cssParserString.init(string16bit);
82
83 ASSERT_TRUE(cssParserString.equalIgnoringASCIICase("shadow"));
84 ASSERT_TRUE(cssParserString.equalIgnoringASCIICase("ShaDow"));
85 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("shadow-all"));
86 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("sha"));
87 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("abCD"));
88
89 StringBuilder builder;
90 builder.append(0x017f); // LATIN SMALL LETTER LONG S
91 builder.append("HaDOw");
92 ASSERT_FALSE(builder.is8Bit());
93
94 String string16BitFoldingToASCII = builder.toString();
95 cssParserString.init(string16BitFoldingToASCII);
96
97 ASSERT_FALSE(cssParserString.equalIgnoringASCIICase("shadow"));
98 }
99
100 TEST(CSSParserValuesTest, CSSParserValuelistClear)
101 {
102 CSSParserValueList list;
103 for (int i = 0; i < 3; ++i) {
104 CSSParserValue value;
105 value.setFromNumber(3, CSSPrimitiveValue::UnitType::Number);
106 list.addValue(value);
107 }
108 list.clearAndLeakValues();
109 ASSERT_FALSE(list.size());
110 ASSERT_FALSE(list.currentIndex());
111 }
112
113 TEST(CSSParserValuesTest, CSSParserTokenUrlConversion)
114 {
115 CSSTokenizer::Scope scope("url(some) uRL('test') UrL( \"words\" /**/ ) URl( /**/hi/**/ )");
116 CSSParserValueList valueList(scope.tokenRange());
117 ASSERT_EQ(valueList.size(), 4u);
118 ASSERT_EQ(valueList.valueAt(0)->m_unit, CSSParserValue::URI);
119 EXPECT_EQ(String(valueList.valueAt(0)->string), "some");
120 ASSERT_EQ(valueList.valueAt(1)->m_unit, CSSParserValue::URI);
121 EXPECT_EQ(String(valueList.valueAt(1)->string), "test");
122 ASSERT_EQ(valueList.valueAt(2)->m_unit, CSSParserValue::URI);
123 EXPECT_EQ(String(valueList.valueAt(2)->string), "words");
124 ASSERT_EQ(valueList.valueAt(3)->m_unit, CSSParserValue::URI);
125 EXPECT_EQ(String(valueList.valueAt(3)->string), "/**/hi/**/");
126 }
127
128 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698