summaryrefslogtreecommitdiffstats
path: root/image/test/mochitest/test_removal_ondecode.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /image/test/mochitest/test_removal_ondecode.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'image/test/mochitest/test_removal_ondecode.html')
-rw-r--r--image/test/mochitest/test_removal_ondecode.html160
1 files changed, 160 insertions, 0 deletions
diff --git a/image/test/mochitest/test_removal_ondecode.html b/image/test/mochitest/test_removal_ondecode.html
new file mode 100644
index 0000000000..4ce7555757
--- /dev/null
+++ b/image/test/mochitest/test_removal_ondecode.html
@@ -0,0 +1,160 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=841579
+-->
+<head>
+ <title>Test for Bug 841579</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
+ <script type="application/javascript" src="imgutils.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=841579">Mozilla Bug 841579</a>
+<p id="display"></p>
+<div id="content">
+</div>
+<pre id="test">
+<script type="application/javascript">
+/** Test for Bug 841579**/
+
+SimpleTest.requestFlakyTimeout("Early failure timeout");
+SimpleTest.waitForExplicitFinish();
+
+const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
+
+const Cc = SpecialPowers.Cc;
+const Ci = SpecialPowers.Ci;
+const gContent = document.getElementById("content");
+
+var gImg;
+var gMyDecoderObserver;
+var gIsTestFinished = false;
+var gFiles;
+var gNotifications = 0;
+var gLoads = 0;
+var gRemovals = 0;
+var gExpected = 5;
+
+function* fileToLoad() {
+ yield "red.png";
+ yield "invalid.jpg";
+ yield "lime100x100.svg";
+ yield "bad.jpg";
+ yield "rillybad.jpg";
+}
+
+function onSizeAvailable(aRequest) {
+ ok(true, "AfterLoad.onSizeAvailable called for " + gImg.src);
+}
+function onLoadComplete(aRequest) {
+ ok(gExpected > gLoads, "AfterLoad.onLoadComplete called for " + gImg.src);
+ gLoads++;
+
+ // We aren't going to get a decode complete event if the metadata decoding
+ // failed (i.e. for invalid.jpg). By definition we should have the size or
+ // an error once we get a load complete event, so check if the size is valid
+ // and if not, trigger a decode complete event manually.
+ var hasSize = false;
+ try {
+ hasSize = aRequest.image.width > 0 && aRequest.image.height > 0;
+ } catch(e) {}
+
+ if (hasSize) {
+ maybeAdvance();
+ } else {
+ onDecodeComplete(aRequest);
+ }
+}
+
+function onDecodeComplete(aRequest) {
+ ok(gExpected > gRemovals, "AfterLoad.onDecodeComplete called for " + gImg.src);
+ SimpleTest.executeSoon(function() {
+ try {
+ gContent.removeChild(gImg);
+ }
+ catch (e) {}
+ gRemovals++;
+ maybeAdvance();
+ });
+}
+
+function failTest() {
+ ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " +
+ "currently displaying " + gImg.src);
+ cleanUpAndFinish();
+}
+
+function onNotification()
+{
+ ok(gExpected > gNotifications, "AfterLoad.onNotification called for " + gImg.src);
+ gNotifications++;
+ maybeAdvance();
+}
+
+function maybeAdvance()
+{
+ if (gNotifications != gLoads || gNotifications != gRemovals) {
+ return;
+ }
+
+ let {done, value} = gFiles.next();
+ if (done) {
+ cleanUpAndFinish();
+ return;
+ }
+ gImg.src = value;
+ gContent.appendChild(gImg);
+}
+
+function cleanUpAndFinish() {
+ // On the off chance that failTest and myOnStopFrame are triggered
+ // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
+ if (gIsTestFinished) {
+ return;
+ }
+ let imgLoadingContent = SpecialPowers.wrap(gImg);
+ imgLoadingContent.removeObserver(gMyDecoderObserver);
+ // TODO - this isn't the case until post-bug 716140's refactorings
+ // ok(gNotifications == gLoads, "Should be notified the same number of times as loads");
+ SimpleTest.finish();
+ gIsTestFinished = true;
+}
+
+function main() {
+ gFiles = fileToLoad();
+ gImg = new Image();
+ gImg.onload = onNotification;
+ gImg.onerror = onNotification;
+
+ // Create, customize & attach decoder observer
+ var observer = new ImageDecoderObserverStub();
+ observer.sizeAvailable = onSizeAvailable;
+ observer.loadComplete = onLoadComplete;
+ observer.decodeComplete = onDecodeComplete;
+ gMyDecoderObserver =
+ Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
+ .createScriptedObserver(SpecialPowers.wrapCallbackObject(observer));
+ let imgLoadingContent = SpecialPowers.wrap(gImg);
+ imgLoadingContent.addObserver(gMyDecoderObserver);
+
+ // We want to test the cold loading behavior, so clear cache in case an
+ // earlier test got our image in there already.
+ clearAllImageCaches();
+
+ // kick off image-loading! myOnStopFrame handles the rest.
+ gImg.setAttribute("src", gFiles.next().value);
+ gContent.appendChild(gImg);
+
+ // In case something goes wrong, fail earlier than mochitest timeout,
+ // and with more information.
+ setTimeout(failTest, FAILURE_TIMEOUT);
+}
+
+window.onload = main;
+
+</script>
+</pre>
+</body>
+</html>