Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / misc / image-onerror-no-load-event.html
bloba7861cb5a86c00155c72d4a4a344d48d70af16e4
1 <!doctype html>
2 <html>
3 <head>
4 <script src="/js-test-resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Tests if repeated loading of non-existent img.src resources doesn't deliver onload.");
10 window.jsTestIsAsync = true;
11 if (window.testRunner) {
12 testRunner.dumpAsText();
13 testRunner.waitUntilDone();
16 function finish(final)
18 // Test handling for missing image resources and
19 // ones that load, but with status 404.
20 if (!final) {
21 testImageOnError(true);
22 return;
24 window.finishJSTest();
27 function testImageOnError(broken)
29 var img = new Image();
30 img.expectOnLoad = broken;
31 img.onload = function() {
32 if (img.expectOnLoad)
33 testPassed("Received onload for broken img.src");
34 else
35 testFailed("Received onload for non-existent img.src");
37 finish(img.expectOnLoad);
39 img.onerror = function () {
40 if (img.expectOnLoad) {
41 img.onerror = null;
42 testFailed("Received onload for boken img.src");
43 finish(img.expectOnLoad);
44 return;
46 else
47 testPassed("Received onerror for non-existent img.src");
49 if (img.haveFailedAlready) {
50 img.onerror = null;
51 testPassed("Received error event repeatedly.");
52 finish(img.expectOnLoad);
53 return;
55 img.haveFailedAlready = true;
56 img.src = "invalidinvalid2.jpg";
58 img.src = broken ? "resources/404image.php" : "resources/non-existent.png";
60 testImageOnError(false);
61 </script>
62 <div id="console"></div>
63 </body>
64 </html>