image/test/mochitest/test_error_events.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.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=715308
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 715308 comment 93</title>
michael@0 8 <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13
michael@0 14 <!-- Test for Bug 715308 comment 93:
michael@0 15
michael@0 16 - For a valid image, onload is fired and onerror is never fired.
michael@0 17 - For an image with errors, onerror is fired, but onload is never fired.
michael@0 18 - For any image, either onload or onerror is fired, but never both.
michael@0 19
michael@0 20 -->
michael@0 21 <script type="text/javascript;version=1.8">
michael@0 22 "use strict";
michael@0 23
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 var numCallbacks = 0;
michael@0 27
michael@0 28 function image_error(name)
michael@0 29 {
michael@0 30 numCallbacks++;
michael@0 31 ok(name == 'error-early', "Got onerror for " + name);
michael@0 32 }
michael@0 33
michael@0 34 function image_load(name)
michael@0 35 {
michael@0 36 numCallbacks++;
michael@0 37 ok(name == 'shaver', "Got onload for " + name);
michael@0 38 }
michael@0 39
michael@0 40 function page_load()
michael@0 41 {
michael@0 42 ok(numCallbacks == 2, 'Got page load before all onload/onerror callbacks?');
michael@0 43
michael@0 44 // Spin the event loop a few times to let image_error run if it's going to,
michael@0 45 // then finish the test.
michael@0 46 SimpleTest.executeSoon(function() {
michael@0 47 SimpleTest.executeSoon(function() {
michael@0 48 SimpleTest.executeSoon(function() {
michael@0 49 SimpleTest.finish();
michael@0 50 });
michael@0 51 });
michael@0 52 });
michael@0 53 }
michael@0 54
michael@0 55 addEventListener('load', page_load);
michael@0 56
michael@0 57 </script>
michael@0 58
michael@0 59 <div id="content">
michael@0 60 <img src='shaver.png' onerror='image_error("shaver")' onload='image_load("shaver")'>
michael@0 61 <img src='error-early.png' onerror='image_error("error-early")' onload='image_load("error-early")'>
michael@0 62 </div>
michael@0 63
michael@0 64 </pre>
michael@0 65 </body>
michael@0 66 </html>
michael@0 67

mercurial