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/css/StyleSheetContents.h" | 5 #include "core/css/StyleSheetContents.h" |
6 | 6 |
7 #include "core/css/CSSTestHelper.h" | 7 #include "core/css/CSSTestHelper.h" |
8 #include "core/css/parser/CSSParser.h" | 8 #include "core/css/parser/CSSParser.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 TEST(StyleSheetContentsTest, InsertMediaRule) { | 13 TEST(StyleSheetContentsTest, InsertMediaRule) { |
14 CSSParserContext context(HTMLStandardMode, nullptr); | 14 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); |
15 | 15 |
16 StyleSheetContents* styleSheet = StyleSheetContents::create(context); | 16 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
17 styleSheet->parseString("@namespace ns url(test);"); | 17 styleSheet->parseString("@namespace ns url(test);"); |
18 EXPECT_EQ(1U, styleSheet->ruleCount()); | 18 EXPECT_EQ(1U, styleSheet->ruleCount()); |
19 | 19 |
20 styleSheet->setMutable(); | 20 styleSheet->setMutable(); |
21 styleSheet->wrapperInsertRule( | 21 styleSheet->wrapperInsertRule( |
22 CSSParser::parseRule(context, styleSheet, | 22 CSSParser::parseRule(context, styleSheet, |
23 "@media all { div { color: pink } }"), | 23 "@media all { div { color: pink } }"), |
24 0); | 24 0); |
25 EXPECT_EQ(1U, styleSheet->ruleCount()); | 25 EXPECT_EQ(1U, styleSheet->ruleCount()); |
26 EXPECT_TRUE(styleSheet->hasMediaQueries()); | 26 EXPECT_TRUE(styleSheet->hasMediaQueries()); |
27 | 27 |
28 styleSheet->wrapperInsertRule( | 28 styleSheet->wrapperInsertRule( |
29 CSSParser::parseRule(context, styleSheet, | 29 CSSParser::parseRule(context, styleSheet, |
30 "@media all { div { color: green } }"), | 30 "@media all { div { color: green } }"), |
31 1); | 31 1); |
32 EXPECT_EQ(2U, styleSheet->ruleCount()); | 32 EXPECT_EQ(2U, styleSheet->ruleCount()); |
33 EXPECT_TRUE(styleSheet->hasMediaQueries()); | 33 EXPECT_TRUE(styleSheet->hasMediaQueries()); |
34 } | 34 } |
35 | 35 |
36 TEST(StyleSheetContentsTest, InsertFontFaceRule) { | 36 TEST(StyleSheetContentsTest, InsertFontFaceRule) { |
37 CSSParserContext context(HTMLStandardMode, nullptr); | 37 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); |
38 | 38 |
39 StyleSheetContents* styleSheet = StyleSheetContents::create(context); | 39 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
40 styleSheet->parseString("@namespace ns url(test);"); | 40 styleSheet->parseString("@namespace ns url(test);"); |
41 EXPECT_EQ(1U, styleSheet->ruleCount()); | 41 EXPECT_EQ(1U, styleSheet->ruleCount()); |
42 | 42 |
43 styleSheet->setMutable(); | 43 styleSheet->setMutable(); |
44 styleSheet->wrapperInsertRule( | 44 styleSheet->wrapperInsertRule( |
45 CSSParser::parseRule(context, styleSheet, | 45 CSSParser::parseRule(context, styleSheet, |
46 "@font-face { font-family: a }"), | 46 "@font-face { font-family: a }"), |
47 0); | 47 0); |
48 EXPECT_EQ(1U, styleSheet->ruleCount()); | 48 EXPECT_EQ(1U, styleSheet->ruleCount()); |
49 EXPECT_TRUE(styleSheet->hasFontFaceRule()); | 49 EXPECT_TRUE(styleSheet->hasFontFaceRule()); |
50 | 50 |
51 styleSheet->wrapperInsertRule( | 51 styleSheet->wrapperInsertRule( |
52 CSSParser::parseRule(context, styleSheet, | 52 CSSParser::parseRule(context, styleSheet, |
53 "@font-face { font-family: b }"), | 53 "@font-face { font-family: b }"), |
54 1); | 54 1); |
55 EXPECT_EQ(2U, styleSheet->ruleCount()); | 55 EXPECT_EQ(2U, styleSheet->ruleCount()); |
56 EXPECT_TRUE(styleSheet->hasFontFaceRule()); | 56 EXPECT_TRUE(styleSheet->hasFontFaceRule()); |
57 } | 57 } |
58 | 58 |
59 TEST(StyleSheetContentsTest, HasViewportRule) { | 59 TEST(StyleSheetContentsTest, HasViewportRule) { |
60 CSSParserContext context(HTMLStandardMode, nullptr); | 60 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); |
61 | 61 |
62 StyleSheetContents* styleSheet = StyleSheetContents::create(context); | 62 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
63 styleSheet->parseString("@viewport { width: 200px}"); | 63 styleSheet->parseString("@viewport { width: 200px}"); |
64 EXPECT_EQ(1U, styleSheet->ruleCount()); | 64 EXPECT_EQ(1U, styleSheet->ruleCount()); |
65 EXPECT_TRUE(styleSheet->hasViewportRule()); | 65 EXPECT_TRUE(styleSheet->hasViewportRule()); |
66 } | 66 } |
67 | 67 |
68 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertion) { | 68 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertion) { |
69 CSSParserContext context(HTMLStandardMode, nullptr); | 69 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); |
70 | 70 |
71 StyleSheetContents* styleSheet = StyleSheetContents::create(context); | 71 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
72 styleSheet->parseString("body { color: pink }"); | 72 styleSheet->parseString("body { color: pink }"); |
73 EXPECT_EQ(1U, styleSheet->ruleCount()); | 73 EXPECT_EQ(1U, styleSheet->ruleCount()); |
74 EXPECT_FALSE(styleSheet->hasViewportRule()); | 74 EXPECT_FALSE(styleSheet->hasViewportRule()); |
75 | 75 |
76 styleSheet->setMutable(); | 76 styleSheet->setMutable(); |
77 styleSheet->wrapperInsertRule( | 77 styleSheet->wrapperInsertRule( |
78 CSSParser::parseRule(context, styleSheet, "@viewport { width: 200px }"), | 78 CSSParser::parseRule(context, styleSheet, "@viewport { width: 200px }"), |
79 0); | 79 0); |
80 EXPECT_EQ(2U, styleSheet->ruleCount()); | 80 EXPECT_EQ(2U, styleSheet->ruleCount()); |
81 EXPECT_TRUE(styleSheet->hasViewportRule()); | 81 EXPECT_TRUE(styleSheet->hasViewportRule()); |
82 } | 82 } |
83 | 83 |
84 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertionIntoMediaRule) { | 84 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertionIntoMediaRule) { |
85 CSSParserContext context(HTMLStandardMode, nullptr); | 85 CSSParserContext* context = CSSParserContext::create(HTMLStandardMode); |
86 | 86 |
87 StyleSheetContents* styleSheet = StyleSheetContents::create(context); | 87 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
88 styleSheet->parseString("@media {}"); | 88 styleSheet->parseString("@media {}"); |
89 ASSERT_EQ(1U, styleSheet->ruleCount()); | 89 ASSERT_EQ(1U, styleSheet->ruleCount()); |
90 EXPECT_FALSE(styleSheet->hasViewportRule()); | 90 EXPECT_FALSE(styleSheet->hasViewportRule()); |
91 | 91 |
92 StyleRuleMedia* mediaRule = toStyleRuleMedia(styleSheet->ruleAt(0)); | 92 StyleRuleMedia* mediaRule = toStyleRuleMedia(styleSheet->ruleAt(0)); |
93 styleSheet->setMutable(); | 93 styleSheet->setMutable(); |
94 mediaRule->wrapperInsertRule( | 94 mediaRule->wrapperInsertRule( |
95 0, | 95 0, |
96 CSSParser::parseRule(context, styleSheet, "@viewport { width: 200px }")); | 96 CSSParser::parseRule(context, styleSheet, "@viewport { width: 200px }")); |
97 EXPECT_EQ(1U, mediaRule->childRules().size()); | 97 EXPECT_EQ(1U, mediaRule->childRules().size()); |
98 EXPECT_TRUE(styleSheet->hasViewportRule()); | 98 EXPECT_TRUE(styleSheet->hasViewportRule()); |
99 } | 99 } |
100 | 100 |
101 } // namespace blink | 101 } // namespace blink |
OLD | NEW |