test_error_events.html 1.6 KB

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