summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/css/CSSSelectorTest.cpp
blob: baf04659d658f169e0eb2b2a7f4712a07c788ae5 (plain)
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
// Copyright 2014 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 "config.h"
#include "core/css/CSSTestHelper.h"
#include "core/css/RuleSet.h"

#include <gtest/gtest.h>

namespace WebCore {

TEST(CSSSelector, Representations)
{
    CSSTestHelper helper;

    const char* cssRules =
    "summary::-webkit-details-marker { }"
    "* {}"
    "div {}"
    "#id {}"
    ".class {}"
    "[attr] {}"
    "div:hover {}"
    "div:nth-child(2){}"
    ".class#id { }"
    "#id.class { }"
    "[attr]#id { }"
    "div[attr]#id { }"
    "div::content { }"
    "div::first-line { }"
    ".a.b.c { }"
    "div:not(.a) { }" // without class a
    "div:not(:visited) { }" // without the visited pseudo class

    "[attr=\"value\"] { }" // Exact equality
    "[attr~=\"value\"] { }" // One of a space-separated list
    "[attr^=\"value\"] { }" // Begins with
    "[attr$=\"value\"] { }" // Ends with
    "[attr*=\"value\"] { }" // Substring equal to
    "[attr|=\"value\"] { }" // One of a hyphen-separated list

    ".a .b { }" // .b is a descendant of .a
    ".a > .b { }" // .b is a direct descendant of .a
    ".a ~ .b { }" // .a precedes .b in sibling order
    ".a + .b { }" // .a element immediately precedes .b in sibling order
    ".a, .b { }" // matches .a or .b

    ".a.b .c {}";

    helper.addCSSRules(cssRules);
    EXPECT_EQ(30u, helper.ruleSet().ruleCount()); // .a, .b counts as two rules.
#ifndef NDEBUG
    helper.ruleSet().show();
#endif
}

} // namespace WebCore