summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-page/page-rule-declarations-003.html
blob: aaf0bbb1a8c1a2e4298be5be2a6895ddc290ed48 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Paged Media: parsing @page selectors</title>
<link rel="author" title="Mozilla" href="https://mozilla.org"/>
<link rel="help" href="https://drafts.csswg.org/css-page/#page-selectors"/>
<meta name="assert" content="Test that @page selectors are parsed correctly.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
    @page a, B {
        size: 1in;
    }
    @page A,b,C {
        size: 2in;
    }
    @page auto {
        size: 3in;
    }
    @page something, auto {
        size: 4in;
    }
    @page auto, other_thing {
        size: 5in;
    }
    @page _a, Z {
        size: 6in;
    }
    @page -b, y {
        size: 7in;
    }
    @page _abcd {
        size: 8in;
    }
    @page n,-XYZ {
        size: 9in;
    }
</style>

<script>
    let expectedForSelector = {
        "a, B" : "size: 1in;",
        "A, b, C" : "size: 2in;",
        "auto" : "size: 3in;",
        "something, auto" : "size: 4in;",
        "auto, other_thing" : "size: 5in;",
        "_a, Z" : "size: 6in;",
        "-b, y" : "size: 7in;",
        "_abcd" : "size: 8in;",
        "n, -XYZ" : "size: 9in;"
    };
    let styleSheets = document.styleSheets;
    for (let sheet of styleSheets) {
        let rules = sheet.cssRules;
        for (let rule of rules) {
            if (rule.type == CSSRule.PAGE_RULE) {
                let expected = expectedForSelector[rule.selectorText];
                test(function(){
                    assert_equals(rule.style.cssText, expected, "unexpected @page contents");
                }, "contents for selector ['" + rule.selectorText + "']");
                delete expectedForSelector[rule.selectorText];
            }
        }
    }
    // Validate that we can assign an empty selector
    test(function() {
        let rule = styleSheets[0].cssRules[0];
        assert_equals(rule.type, CSSRule.PAGE_RULE, "expected first rule to be @page");
        rule.selectorText = "";
        assert_equals(rule.selectorText, "", "unexpected selector when assigning blank string");
    }, "expected empty selector when assigning blank string");
    test(function() {
        assert_equals(Object.keys(expectedForSelector).length, 0, "missing @page selectors");
    });
</script>