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