layout/style/test/test_redundant_font_download.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=879963 -->
     4 <head>
     5   <meta charset="utf-8">
     6   <title>Test for bug 879963</title>
     7   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     8   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     9 </head>
    11 <body>
    12   <!-- Two <style> elements with identical @font-face rules.
    13        Although multiple @font-face at-rules for the same family are legal,
    14        and add faces to the family, we should NOT download the same resource
    15        twice just because we have a duplicate face entry. -->
    16   <style type="text/css">
    17     @font-face {
    18       font-family: foo;
    19       src: url("redundant_font_download.sjs?q=font");
    20     }
    21     .test {
    22       font-family: foo;
    23     }
    24   </style>
    26   <style type="text/css">
    27     @font-face {
    28       font-family: foo;
    29       src: url("redundant_font_download.sjs?q=font");
    30     }
    31     .test {
    32       font-family: foo;
    33     }
    34   </style>
    36   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=879963">Mozilla Bug 879963</a>
    38   <div>
    39     <!-- the 'init' request returns an image (just so we can see it's working)
    40          and initializes the request logging in our sjs server -->
    41     <img src="redundant_font_download.sjs?q=init">
    42   </div>
    44   <div id="test">
    45     Test
    46   </div>
    48   <div>
    49     <img id="image2" src="">
    50   </div>
    52   <script type="application/javascript">
    53     // helper to retrieve the server's request log as text
    54     function getRequestLog() {
    55       var xmlHttp = new XMLHttpRequest();
    56       xmlHttp.open("GET", "redundant_font_download.sjs?q=report", false);
    57       xmlHttp.send(null);
    58       return xmlHttp.responseText;
    59     }
    61     // retrieve just the most recent request the server has seen
    62     function getLastRequest() {
    63       return getRequestLog().split(";").pop();
    64     }
    66     // poll the server at intervals of 'delay' ms until it has seen a specific request,
    67     // or until maxTime ms have passed
    68     function waitForRequest(request, delay, maxTime, func) {
    69       timeLimit = Date.now() + maxTime;
    70       var intervalId = window.setInterval(function() {
    71         var req = getLastRequest();
    72         if (req == request || Date.now() > timeLimit) {
    73           window.clearInterval(intervalId);
    74           func();
    75         }
    76       }.bind(this), delay);
    77     }
    79     // initially disable the second of the <style> elements,
    80     // so we only have a single copy of the font-face
    81     document.getElementsByTagName("style")[1].disabled = true;
    83     SimpleTest.waitForExplicitFinish();
    85     // We perform a series of actions that trigger requests to the .sjs server,
    86     // and poll the server's request log at each stage to check that it has
    87     // seen the request we expected before we proceed to the next step.
    88     function startTest() {
    89       is(getRequestLog(), "init", "request log has been initialized");
    91       // this should trigger a font download
    92       document.getElementById("test").className = "test";
    94       // wait to confirm that the server has received the request
    95       waitForRequest("font", 10, 5000, continueTest1);
    96     }
    98     function continueTest1() {
    99       is(getRequestLog(), "init;font", "server received font request");
   101       // trigger a request for the second image, to provide an explicit
   102       // delimiter in the log before we enable the second @font-face rule
   103       document.getElementById("image2").src = "redundant_font_download.sjs?q=image";
   105       waitForRequest("image", 10, 5000, continueTest2);
   106     }
   108     function continueTest2() {
   109       is(getRequestLog(), "init;font;image", "server received image request");
   111       // enable the second <style> element: we should NOT see a second font request,
   112       // we expect waitForRequest to time out instead
   113       document.getElementsByTagName("style")[1].disabled = false;
   115       waitForRequest("font", 10, 1000, continueTest3);
   116     }
   118     function continueTest3() {
   119       is(getRequestLog(), "init;font;image", "should NOT have re-requested the font");
   121       SimpleTest.finish();
   122     }
   124     waitForRequest("init", 10, 5000, startTest);
   126   </script>
   128 </body>
   130 </html>

mercurial