5 <title>CSS Test: @viewport cascading - !important declaration wins
</title>
6 <link rel=
"author" title=
"Rune Lillesveen" href=
"mailto:rune@opera.com">
7 <link rel=
"help" href=
"http://www.w3.org/TR/css-device-adapt/#the-viewport-rule">
8 <meta name=
"flags" content=
"visual scroll dom">
9 <meta name=
"assert" content=
"A preceeding !important declaration wins over a non-important descriptor.">
10 <script src=
"../../../resources/testharness.js" type=
"text/javascript"></script>
11 <script src=
"../../../resources/testharnessreport.js" type=
"text/javascript"></script>
12 <style type=
"text/css">
14 html
, body
, #test
{ width: 100%; height: 100%; }
15 #log { padding: 1em; display: none
; }
16 /* Reset viewport values to initial values to ignore UA stylesheet. */
28 <style type=
"text/css">
29 /* CSS for the test below. */
30 @viewport
{ width: 300px !important
; width: 500px }
31 /* Set root element font-size to something different from the initial
32 font-size to make sure 'rem' and 'em' for @viewport is based on the
33 initial font-size, not the root element font-size. */
34 html
{ font-size: 2rem; }
35 body
{ font-size: 0.5rem; }
37 <script type=
"text/javascript">
38 var test
= async_test("CSS Test: @viewport cascading - !important declaration wins");
39 window
.onload = function(){
41 var testStyleSheet
= document
.styleSheets
.item(1);
43 /* Initialize an object to store viewport values to be used by the test
45 var viewport
= new Object();
47 /* An element with the same size as the initial containing block. */
48 var testElm
= document
.getElementById("test");
50 if (window
.testRunner
) {
51 viewport
.fontSize
= parseInt(getComputedStyle(testElm
, "").fontSize
);
52 viewport
.initialWidth
= 320;
53 viewport
.initialHeight
= 352;
55 var vpString
= internals
.viewportAsText(document
, 1,
56 viewport
.initialWidth
,
57 viewport
.initialHeight
);
59 var match
= /viewport size (.+)x(.+) scale (.+ )/.exec(vpString
);
62 viewport
.actualWidth
= parseFloat(match
[1]);
63 viewport
.actualHeight
= parseFloat(match
[2]);
64 viewport
.zoom
= parseFloat(match
[3]);
68 /* Disable the stylesheet that contains the @viewport to test. */
69 testStyleSheet
.disabled
= true;
71 /* Retrieve the initial viewport values before applying the @viewport to
73 viewport
.fontSize
= parseInt(getComputedStyle(testElm
, "").fontSize
);
74 viewport
.initialWidth
= testElm
.offsetWidth
;
75 viewport
.initialHeight
= testElm
.offsetHeight
;
77 /* Enable the stylesheet that contains the @viewport to test. */
78 testStyleSheet
.disabled
= false;
80 /* Retrieve the actual viewport values for the test. */
81 viewport
.actualWidth
= testElm
.offsetWidth
;
82 viewport
.actualHeight
= testElm
.offsetHeight
;
83 viewport
.zoom
= viewport
.initialWidth
/ window
.innerWidth
;
86 /* Check viewport values. */
88 assert_equals(viewport
.actualWidth
, 300);
91 /* Finished. Show the results. */
93 testStyleSheet
.disabled
= true;
94 document
.getElementById("log").style
.display
= "block";