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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
| 60 CSSParserContext context(HTMLStandardMode, nullptr); |
| 61 |
| 62 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
| 63 styleSheet->parseString("@viewport { width: 200px}"); |
| 64 EXPECT_EQ(1U, styleSheet->ruleCount()); |
| 65 EXPECT_TRUE(styleSheet->hasViewportRule()); |
| 66 } |
| 67 |
| 68 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertion) { |
| 69 CSSParserContext context(HTMLStandardMode, nullptr); |
| 70 |
| 71 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
| 72 styleSheet->parseString("body { color: pink }"); |
| 73 EXPECT_EQ(1U, styleSheet->ruleCount()); |
| 74 EXPECT_FALSE(styleSheet->hasViewportRule()); |
| 75 |
| 76 styleSheet->setMutable(); |
| 77 styleSheet->wrapperInsertRule( |
| 78 CSSParser::parseRule(context, styleSheet, "@viewport { width: 200px }"), |
| 79 0); |
| 80 EXPECT_EQ(2U, styleSheet->ruleCount()); |
| 81 EXPECT_TRUE(styleSheet->hasViewportRule()); |
| 82 } |
| 83 |
| 84 TEST(StyleSheetContentsTest, HasViewportRuleAfterInsertionIntoMediaRule) { |
| 85 CSSParserContext context(HTMLStandardMode, nullptr); |
| 86 |
| 87 StyleSheetContents* styleSheet = StyleSheetContents::create(context); |
| 88 styleSheet->parseString("@media {}"); |
| 89 ASSERT_EQ(1U, styleSheet->ruleCount()); |
| 90 EXPECT_FALSE(styleSheet->hasViewportRule()); |
| 91 |
| 92 StyleRuleMedia* mediaRule = toStyleRuleMedia(styleSheet->ruleAt(0)); |
| 93 styleSheet->setMutable(); |
| 94 mediaRule->wrapperInsertRule( |
| 95 0, |
| 96 CSSParser::parseRule(context, styleSheet, "@viewport { width: 200px }")); |
| 97 EXPECT_EQ(1U, mediaRule->childRules().size()); |
| 98 EXPECT_TRUE(styleSheet->hasViewportRule()); |
| 99 } |
| 100 |
59 } // namespace blink | 101 } // namespace blink |
OLD | NEW |