layout/style/test/test_load_events_on_stylesheets.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial