layout/style/test/test_load_events_on_stylesheets.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=185236
     5 -->
     6 <head>
     7   <title>Test for Bug 185236</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10   <script>
    11     var pendingEventCounter = 0;
    12     var messagePosted = false;
    13     SimpleTest.waitForExplicitFinish();
    14     addLoadEvent(function() {
    15       is(messagePosted, true, "Should have gotten onmessage event");
    16       is(pendingEventCounter, 0,
    17          "How did onload for the page fire before onload for all the stylesheets?");
    18       SimpleTest.finish();
    19     });
    20     // Count the link we're about to parse
    21     pendingEventCounter = 1;
    22   </script>
    23   <link rel="stylesheet" href="data:text/css,*{}"
    24         onload="--pendingEventCounter;
    25                 ok(true, 'Load event firing on basic stylesheet')"
    26         onerror="--pendingEventCounter;
    27                  ok(false, 'Error event firing on basic stylesheet')">
    28 </head>
    29 <body>
    30 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=185236">Mozilla Bug 185236</a>
    31 <p id="display"></p>
    32 <div id="content" style="display: none">
    34 </div>
    35 <pre id="test">
    36 <script type="application/javascript">
    37 /** Test for Bug 185236 **/
    38 // Verify that there are no in-flight sheet loads right now; we should have
    39 // waited for them when we hit the script tag
    40 is(pendingEventCounter, 0, "There should be no pending events");
    42 // Test sheet that will already be complete when we write it out
    43 ++pendingEventCounter;
    45 // Make sure that a postMessage we do right now fires after the onload handler
    46 // for the stylesheet.  If we ever change the timing of sheet onload, we will
    47 // need to change that.
    48 window.onmessage = function() {
    49   messagePosted = true;
    50   // There are 4 pending events: two from the two direct example.com loads,
    51   // and 2 from the two data:text/css loads that import things
    52   is(pendingEventCounter, 4, "Load event for sheet should have fired");
    53 }
    54 window.postMessage("", "*");
    56 document.write('<link rel="stylesheet" href="data:text/css,*{}"\
    57                 onload="--pendingEventCounter;\
    58                         ok(true, \'Load event firing on basic stylesheet\')"\
    59                 onerror="--pendingEventCounter;\
    60                         ok(false, \'Error event firing on basic stylesheet\')">');
    62 // Make sure we have that second stylesheet
    63 is(document.styleSheets.length, 3, "Should have three stylesheets");
    65 // Make sure that the second stylesheet is all loaded
    66 // If we ever switch away from sync loading of already-complete sheets, this
    67 // test will need adjusting
    68 is(document.styleSheets[2].cssRules.length, 1, "Should have one rule");
    70 // Make sure the load event for that stylesheet has not fired yet
    71 is(pendingEventCounter, 1, "There should be one pending event");
    73 ++pendingEventCounter;
    74 document.write('<style\
    75                 onload="--pendingEventCounter;\
    76                         ok(true, \'Load event firing on inline stylesheet\')"\
    77                 onerror="--pendingEventCounter;\
    78                         ok(false, \'Error event firing on inline stylesheet\')"></style>');
    80 // Make sure the load event for that second stylesheet has not fired yet
    81 is(pendingEventCounter, 2, "There should be two pending events");
    83 ++pendingEventCounter;
    84 document.write('<link rel="stylesheet" href="http://www.example.com"\
    85                 onload="--pendingEventCounter;\
    86                         ok(false, \'Load event firing on broken stylesheet\')"\
    87                 onerror="--pendingEventCounter;\
    88                         ok(true, \'Error event firing on broken stylesheet\')">');
    90 ++pendingEventCounter;
    91 var link = document.createElement("link");
    92 link.rel = "stylesheet";
    93 link.href = "http://www.example.com";
    94 link.onload = function() { --pendingEventCounter;
    95   ok(false, 'Load event firing on broken stylesheet');
    96 };
    97 link.onerror = function() { --pendingEventCounter;
    98   ok(true, 'Error event firing on broken stylesheet');
    99 }
   100 document.body.appendChild(link);
   102 ++pendingEventCounter;
   103 link = document.createElement("link");
   104 link.rel = "stylesheet";
   105 link.href = "data:text/css,*{}";
   106 link.onload = function() { --pendingEventCounter;
   107   ok(true, 'Load event firing on external stylesheet');
   108 };
   109 link.onerror = function() { --pendingEventCounter;
   110   ok(false, 'Error event firing on external stylesheet');
   111 }
   112 document.body.appendChild(link);
   114 // Make sure we have that last stylesheet
   115 is(document.styleSheets.length, 7, "Should have seven stylesheets here");
   117 // Make sure that the sixth stylesheet is all loaded
   118 // If we ever switch away from sync loading of already-complete sheets, this
   119 // test will need adjusting
   120 is(document.styleSheets[6].cssRules.length, 1, "Should have one rule");
   122 ++pendingEventCounter;
   123 link = document.createElement("link");
   124 link.rel = "stylesheet";
   125 link.href = "data:text/css,@import url('data:text/css,*{}')";
   126 link.onload = function() { --pendingEventCounter;
   127   ok(true, 'Load event firing on external stylesheet');
   128 };
   129 link.onerror = function() { --pendingEventCounter;
   130   ok(false, 'Error event firing on external stylesheet');
   131 }
   132 document.body.appendChild(link);
   134 ++pendingEventCounter;
   135 link = document.createElement("link");
   136 link.rel = "stylesheet";
   137 link.href = "data:text/css,@import url('http://www.example.com')";
   138 link.onload = function() { --pendingEventCounter;
   139   ok(false, 'Load event firing on broken stylesheet');
   140 };
   141 link.onerror = function() { --pendingEventCounter;
   142   ok(true, 'Error event firing on broken stylesheet');
   143 }
   144 document.body.appendChild(link);
   146 // Make sure the load events for all those stylesheets have not fired yet
   147 is(pendingEventCounter, 7, "There should be one pending event");
   149 </script>
   150 </pre>
   151 </body>
   152 </html>

mercurial