Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: LayoutTests/http/tests/misc/image-onerror-no-load-event.html

Issue 113633005: Cancel load event on a failed image resource fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add test for broken images Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/misc/image-onerror-no-load-event-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/misc/image-onerror-no-load-event.html
diff --git a/LayoutTests/http/tests/misc/image-onerror-no-load-event.html b/LayoutTests/http/tests/misc/image-onerror-no-load-event.html
new file mode 100644
index 0000000000000000000000000000000000000000..a7861cb5a86c00155c72d4a4a344d48d70af16e4
--- /dev/null
+++ b/LayoutTests/http/tests/misc/image-onerror-no-load-event.html
@@ -0,0 +1,64 @@
+<!doctype html>
+<html>
+<head>
+<script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+description("Tests if repeated loading of non-existent img.src resources doesn't deliver onload.");
+
+window.jsTestIsAsync = true;
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+}
+
+function finish(final)
+{
+ // Test handling for missing image resources and
+ // ones that load, but with status 404.
+ if (!final) {
+ testImageOnError(true);
+ return;
+ }
+ window.finishJSTest();
+}
+
+function testImageOnError(broken)
+{
+ var img = new Image();
+ img.expectOnLoad = broken;
+ img.onload = function() {
+ if (img.expectOnLoad)
+ testPassed("Received onload for broken img.src");
+ else
+ testFailed("Received onload for non-existent img.src");
+
+ finish(img.expectOnLoad);
+ };
+ img.onerror = function () {
+ if (img.expectOnLoad) {
+ img.onerror = null;
+ testFailed("Received onload for boken img.src");
+ finish(img.expectOnLoad);
+ return;
+ }
+ else
+ testPassed("Received onerror for non-existent img.src");
+
+ if (img.haveFailedAlready) {
+ img.onerror = null;
+ testPassed("Received error event repeatedly.");
+ finish(img.expectOnLoad);
+ return;
+ }
+ img.haveFailedAlready = true;
+ img.src = "invalidinvalid2.jpg";
+ };
+ img.src = broken ? "resources/404image.php" : "resources/non-existent.png";
+}
+testImageOnError(false);
+</script>
+<div id="console"></div>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/http/tests/misc/image-onerror-no-load-event-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698