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