| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2014, 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 | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * 3. Neither the name of Opera Software ASA nor the names of its | |
| 13 * contributors may be used to endorse or promote products derived | |
| 14 * from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 20 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 27 * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 */ | |
| 29 | |
| 30 #include "sky/engine/config.h" | |
| 31 #include "sky/engine/core/css/CSSTestHelper.h" | |
| 32 #include "sky/engine/core/css/RuleSet.h" | |
| 33 | |
| 34 #include <gtest/gtest.h> | |
| 35 | |
| 36 namespace blink { | |
| 37 | |
| 38 TEST(RuleSetTest, findBestRuleSetAndAdd_CustomPseudoElements) | |
| 39 { | |
| 40 CSSTestHelper helper; | |
| 41 | |
| 42 helper.addCSSRules("summary::-webkit-details-marker { }"); | |
| 43 RuleSet& ruleSet = helper.ruleSet(); | |
| 44 AtomicString str("-webkit-details-marker"); | |
| 45 const TerminatedArray<RuleData>* rules = ruleSet.shadowPseudoElementRules(st
r); | |
| 46 ASSERT_EQ(1u, rules->size()); | |
| 47 ASSERT_EQ(str, rules->at(0).selector().value()); | |
| 48 } | |
| 49 | |
| 50 TEST(RuleSetTest, findBestRuleSetAndAdd_Id) | |
| 51 { | |
| 52 CSSTestHelper helper; | |
| 53 | |
| 54 helper.addCSSRules("#id { }"); | |
| 55 RuleSet& ruleSet = helper.ruleSet(); | |
| 56 AtomicString str("id"); | |
| 57 const TerminatedArray<RuleData>* rules = ruleSet.idRules(str); | |
| 58 ASSERT_EQ(1u, rules->size()); | |
| 59 ASSERT_EQ(str, rules->at(0).selector().value()); | |
| 60 } | |
| 61 | |
| 62 TEST(RuleSetTest, findBestRuleSetAndAdd_NthChild) | |
| 63 { | |
| 64 CSSTestHelper helper; | |
| 65 | |
| 66 helper.addCSSRules("div:nth-child(2) { }"); | |
| 67 RuleSet& ruleSet = helper.ruleSet(); | |
| 68 AtomicString str("div"); | |
| 69 const TerminatedArray<RuleData>* rules = ruleSet.tagRules(str); | |
| 70 ASSERT_EQ(1u, rules->size()); | |
| 71 ASSERT_EQ(str, rules->at(0).selector().tagQName().localName()); | |
| 72 } | |
| 73 | |
| 74 TEST(RuleSetTest, findBestRuleSetAndAdd_ClassThenId) | |
| 75 { | |
| 76 CSSTestHelper helper; | |
| 77 | |
| 78 helper.addCSSRules(".class#id { }"); | |
| 79 RuleSet& ruleSet = helper.ruleSet(); | |
| 80 AtomicString str("id"); | |
| 81 // id is prefered over class even if class preceeds it in the selector. | |
| 82 const TerminatedArray<RuleData>* rules = ruleSet.idRules(str); | |
| 83 ASSERT_EQ(1u, rules->size()); | |
| 84 AtomicString classStr("class"); | |
| 85 ASSERT_EQ(classStr, rules->at(0).selector().value()); | |
| 86 } | |
| 87 | |
| 88 TEST(RuleSetTest, findBestRuleSetAndAdd_IdThenClass) | |
| 89 { | |
| 90 CSSTestHelper helper; | |
| 91 | |
| 92 helper.addCSSRules("#id.class { }"); | |
| 93 RuleSet& ruleSet = helper.ruleSet(); | |
| 94 AtomicString str("id"); | |
| 95 const TerminatedArray<RuleData>* rules = ruleSet.idRules(str); | |
| 96 ASSERT_EQ(1u, rules->size()); | |
| 97 ASSERT_EQ(str, rules->at(0).selector().value()); | |
| 98 } | |
| 99 | |
| 100 TEST(RuleSetTest, findBestRuleSetAndAdd_AttrThenId) | |
| 101 { | |
| 102 CSSTestHelper helper; | |
| 103 | |
| 104 helper.addCSSRules("[attr]#id { }"); | |
| 105 RuleSet& ruleSet = helper.ruleSet(); | |
| 106 AtomicString str("id"); | |
| 107 const TerminatedArray<RuleData>* rules = ruleSet.idRules(str); | |
| 108 ASSERT_EQ(1u, rules->size()); | |
| 109 AtomicString attrStr("attr"); | |
| 110 ASSERT_EQ(attrStr, rules->at(0).selector().attribute().localName()); | |
| 111 } | |
| 112 | |
| 113 TEST(RuleSetTest, findBestRuleSetAndAdd_TagThenAttrThenId) | |
| 114 { | |
| 115 CSSTestHelper helper; | |
| 116 | |
| 117 helper.addCSSRules("div[attr]#id { }"); | |
| 118 RuleSet& ruleSet = helper.ruleSet(); | |
| 119 AtomicString str("id"); | |
| 120 const TerminatedArray<RuleData>* rules = ruleSet.idRules(str); | |
| 121 ASSERT_EQ(1u, rules->size()); | |
| 122 AtomicString tagStr("div"); | |
| 123 ASSERT_EQ(tagStr, rules->at(0).selector().tagQName().localName()); | |
| 124 } | |
| 125 | |
| 126 TEST(RuleSetTest, findBestRuleSetAndAdd_DivWithContent) | |
| 127 { | |
| 128 CSSTestHelper helper; | |
| 129 | |
| 130 helper.addCSSRules("div::content { }"); | |
| 131 RuleSet& ruleSet = helper.ruleSet(); | |
| 132 AtomicString str("div"); | |
| 133 const TerminatedArray<RuleData>* rules = ruleSet.tagRules(str); | |
| 134 ASSERT_EQ(1u, rules->size()); | |
| 135 AtomicString valueStr("content"); | |
| 136 ASSERT_EQ(valueStr, rules->at(0).selector().value()); | |
| 137 } | |
| 138 | |
| 139 } // namespace blink | |
| OLD | NEW |