Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / server / tests / chrome / test_inspector_getImageDataFromURL.html
blob451c49dcc344e760b1cbae712592e51bf3bfd402
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 Tests for InspectorActor.getImageDataFromURL() in following cases:
5 * Normal case, image loads after a small delay.
6 * Image takes too long to load (the method rejects after a timeout).
7 * Image fails to load.
9 https://bugzilla.mozilla.org/show_bug.cgi?id=1192536
10 -->
11 <head>
12 <meta charset="utf-8">
13 <title>Test for Bug 1192536</title>
15 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
16 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
17 <script type="application/javascript" src="inspector-helpers.js"></script>
18 <script type="application/javascript">
19 "use strict";
21 const PATH = "https://example.com/chrome/devtools/server/tests/chrome/";
22 const BASE_IMAGE = PATH + "inspector-delay-image-response.sjs";
23 const DELAYED_IMAGE = BASE_IMAGE + "?delay=300";
24 const TIMEOUT_IMAGE = BASE_IMAGE + "?delay=50000";
25 const NONEXISTENT_IMAGE = PATH + "this-does-not-exist.png";
27 window.onload = function() {
28 SimpleTest.waitForExplicitFinish();
29 runNextTest();
32 function pushPref(preferenceName, value) {
33 return new Promise(resolve => {
34 const options = {"set": [[preferenceName, value]]};
35 SpecialPowers.pushPrefEnv(options, resolve);
36 });
39 let gInspector = null;
41 addTest(async function setup() {
42 const url = document.getElementById("inspectorContent").href;
43 const { target } = await attachURL(url);
44 gInspector = await target.getFront("inspector");
45 runNextTest();
46 });
48 addTest(async function testTimeout() {
49 info("Testing that the method aborts if the image takes too long to load.");
51 // imageToImageData() only times out when flags.testing is not set.
52 await pushPref("devtools.testing", false);
54 ensureRejects(gInspector.getImageDataFromURL(TIMEOUT_IMAGE),
55 "Image that loads for too long").then(runNextTest);
56 });
58 addTest(async function testNonExistentImage() {
59 info("Testing that non-existent image causes a rejection.");
61 // This test shouldn't hit the timeout.
62 await pushPref("devtools.testing", true);
64 ensureRejects(gInspector.getImageDataFromURL(NONEXISTENT_IMAGE),
65 "Non-existent image").then(runNextTest);
66 });
68 addTest(async function testNormalImage() {
69 info("Testing that the method waits for an image to load.");
71 // This test shouldn't hit the timeout.
72 await pushPref("devtools.testing", true);
74 checkImageData(gInspector.getImageDataFromURL(DELAYED_IMAGE)).then(runNextTest);
75 });
77 addTest(function cleanup() {
78 gInspector = null;
79 runNextTest();
80 });
82 /**
83 * Asserts that the given promise rejects.
85 function ensureRejects(promise, desc) {
86 return promise.then(() => {
87 ok(false, desc + ": promise resolved unexpectedly.");
88 }, () => {
89 ok(true, desc + ": promise rejected as expected.");
90 });
93 /**
94 * Waits for the call to getImageData() the resolve and checks that the image
95 * size is reported correctly.
97 function checkImageData(promise, { width, height } = { width: 1, height: 1 }) {
98 return promise.then(({ size }) => {
99 is(size.naturalWidth, width, "The width is correct.");
100 is(size.naturalHeight, height, "The height is correct.");
104 </script>
105 </head>
106 <body>
107 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1192536">Mozilla Bug 1192536</a>
108 <a id="inspectorContent" target="_blank" href="inspector_getImageData.html">Test Document</a>
109 <p id="display"></p>
110 <div id="content" style="display: none">
112 </div>
113 <pre id="test">
114 </pre>
115 </body>
116 </html>