layout/reftests/image-rect/dom-api-computed-style.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 <!DOCTYPE html>
     2 <!--
     3     Any copyright is dedicated to the Public Domain.
     4     http://creativecommons.org/licenses/publicdomain/
     6     Tests if getComputedStyle() works on -moz-image-rect() and formats the
     7     output correctly.
     8 -->
     9 <html>
    10   <head>
    11     <title>Testcases: -moz-image-rect() [bug 113577]</title>
    12     <style>
    13       div.wrapper {
    14         width: 32px;
    15         height: 32px;
    16         margin: 10px;
    17         background-color: red;
    18       }
    19       div.wrapper div {
    20         width: 32px;
    21         height: 32px;
    22         background: no-repeat;
    23       }
    24     </style>
    25     <script>
    26       var curdir   = location.href.replace(/[^/]+$/, "");
    27       // Tests a common usage
    28       var test1    = "-moz-image-rect(url(green-16x16-in-blue-32x32.png), 0, 16, 16, 0)";
    29       var testRef1 = "-moz-image-rect(url(\"" + curdir + "green-16x16-in-blue-32x32.png\"), 0, 16, 16, 0)";
    30       // Tests an irregular but valid usage
    31       var test2    = "-moz-image-rect( 'green-16x16-in-blue-32x32.png' , 0.0% , 50.5% , 49.5% , 0.0% )";
    32       var testRef2 = "-moz-image-rect(url(\"" + curdir + "green-16x16-in-blue-32x32.png\"), 0%, 50.5%, 49.5%, 0%)";
    33       // Tests a wrong syntax (negative value)
    34       var test3    = "-moz-image-rect(url(green-16x16-in-blue-32x32.png), 0%, -50%, 50%, 0%)";
    35       var testRef3 = "none";
    36       // Checks if I didn't break the default url() notation.
    37       var test4    = "url(  green-16x16-in-blue-32x32.png  )";
    38       var testRef4 = "url(\"" + curdir + "green-16x16-in-blue-32x32.png\")";
    40       function equalComputedDOMIO(domInput, domOutputRef, targetId) {
    41         var targetObj = document.getElementById(targetId);
    42         targetObj.style.backgroundImage = domInput;
    43         var domOutput = getComputedStyle(targetObj, null).getPropertyValue("background-image");
    44         document.write(domOutput == domOutputRef ? "SUCCESS" : ("FAIL: " + domOutput));
    45       }
    46     </script>
    47   </head>
    48   <body>
    49     <div class="wrapper"><div id="test1"></div></div>
    50     <script>
    51       equalComputedDOMIO(test1, testRef1, "test1");
    52     </script>
    53     <div class="wrapper"><div id="test2"></div></div>
    54     <script>
    55       equalComputedDOMIO(test2, testRef2, "test2");
    56     </script>
    57     <div class="wrapper"><div id="test3"></div></div>
    58     <script>
    59       equalComputedDOMIO(test3, testRef3, "test3");
    60     </script>
    61     <div class="wrapper"><div id="test4"></div></div>
    62     <script>
    63       equalComputedDOMIO(test4, testRef4, "test4");
    64     </script>
    65   </body>
    66 </html>

mercurial