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.

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

mercurial