summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-page/page-rule-declarations-001.html
blob: dc225b5abdc5fb5d4ad27e5c7b251c7b988b31f9 (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
<!doctype html>
<meta charset="utf-8">
<title>CSS Paged Media: parsing @page declarations inside @media</title>
<link rel="author" title="Felipe Erias Morandeira" href="mailto:felipeerias@gmail.com"/>
<link rel="help" href="https://drafts.csswg.org/css-page/#at-page-rule"/>
<meta name="assert" content="Test that @page declarations inside @media are parsed correctly.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style type="text/css">

    @media print {
        @page {
            margin: 3cm;
        }
        @page :first {
            margin-top: 6cm;
        }
        @page :left {
            color: red;
        }
        @page :right {
            color: blue;
        }
    }

</style>
<script type="text/javascript">

    let expectedForSelector = {
        "" : "margin: 3cm;",
        ":first" : "margin-top: 6cm;",
        ":left" : "color: red;",
        ":right" : "color: blue;"
    };
    let styleSheets = document.styleSheets;
    for (let i = 0; i < styleSheets.length; i++) {
        let rules = styleSheets[i].cssRules;
        for (let rule of rules) {
            if (rule.type == CSSRule.MEDIA_RULE && rule.conditionText == 'print') {
                for (let mediaRule of rule.cssRules) {
                    if (mediaRule.type == CSSRule.PAGE_RULE) {
                        let expected = expectedForSelector[mediaRule.selectorText];
                        test(function(){
                            assert_equals(mediaRule.style.cssText, expected, "unexpected @page contents");
                        }, "unexpected contents for selector ['" + mediaRule.selectorText + "']");
                        delete expectedForSelector[mediaRule.selectorText];
                    }
                }
            }
        }
    }
    test(function() {
        assert_equals(Object.keys(expectedForSelector).length, 0, "missing @page selectors in @media");
    });

</script>