Bug 1420223 - createImageBitmap must work with nsIAsyncInputStream - part 1 - tests, r=aosmond
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 27 Nov 2017 17:05:56 +0100
changeset 438265 5bb11906e60260156dddd94dad2feb49a96371a6
parent 438264 c0245a5ba4ba74b16c24771dae0e50fe22443898
child 438266 bb774ad4ae66b44e7d42fb32e8a706dac08ae64f
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersaosmond
bugs1420223
milestone59.0a1
Bug 1420223 - createImageBitmap must work with nsIAsyncInputStream - part 1 - tests, r=aosmond
dom/file/ipc/tests/green.jpg
dom/file/ipc/tests/mochitest.ini
dom/file/ipc/tests/test_ipcBlob_createImageBitmap.html
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..48c454d27c9c46574597f80fdd64ecd4d254577d
GIT binary patch
literal 361
zc$}S%Jr2S!427SY62(c{IxR3UaS;ZjN^lMi!+jW87&rt!3pWYQNSWZXWLZz|+0M88
zg6zlL2%-urE#xP*Fjb*+qtv!8IBRE?o%igRee9wSZD4Lv({>_BeC&r_2A!oWp^`MU
z)1U+n@-z8@<Z!^j&>B@DlPF)Y&{y$^Re3H`6{;?Yrf$c@oxa@<L_>PVBy4b|?sS}5
I{)F=V4K5EK<NyEw
--- a/dom/file/ipc/tests/mochitest.ini
+++ b/dom/file/ipc/tests/mochitest.ini
@@ -1,6 +1,8 @@
 [DEFAULT]
 support-files =
-  script_file.js
 
 [test_ipcBlob_fileReaderSync.html]
+support-files = script_file.js
 [test_ipcBlob_workers.html]
+[test_ipcBlob_createImageBitmap.html]
+support-files = green.jpg
new file mode 100644
--- /dev/null
+++ b/dom/file/ipc/tests/test_ipcBlob_createImageBitmap.html
@@ -0,0 +1,84 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test IPCBlob and CreateImageBitmap</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function test_mainThread() {
+  let bc = new BroadcastChannel('testMainThread');
+  bc.onmessage = e => {
+    createImageBitmap(e.data).then(image => {
+      ok(image.height, "this image has a valid size.");
+    }, () => {
+      ok(false, "error creating the image!");
+    }).then(next);
+  }
+
+  fetch('green.jpg').then(r => r.blob()).then(blob => {
+    let bc = new BroadcastChannel('testMainThread');
+    bc.postMessage(blob);
+  });
+}
+
+function test_worker() {
+  function workerScript() {
+    function ok(a, msg) { postMessage({ type: 'test', status: !!a, msg }); };
+    function finish() { postMessage({ type: 'finish' }); };
+
+    let bc = new BroadcastChannel('testWorker');
+    bc.onmessage = e => {
+      createImageBitmap(e.data).then(image => {
+        ok(image.height, "this image has a valid size.");
+      }, () => {
+        ok(false, "error creating the image!");
+      }).then(finish);
+    }
+
+    fetch('http://mochi.test:8888/tests/dom/file/ipc/tests/green.jpg').then(r => r.blob()).then(blob => {
+      let bc = new BroadcastChannel('testWorker');
+      bc.postMessage(blob);
+    });
+  }
+  let workerUrl = URL.createObjectURL(new Blob(["(", workerScript.toSource(), ")()"]));
+  let worker = new Worker(workerUrl);
+
+  worker.onmessage = event => {
+    if (event.data.type == 'test') {
+      ok(event.data.status, event.data.msg);
+      return;
+    }
+
+    if (event.data.type == 'finish') {
+      next();
+    }
+  }
+}
+
+let tests = [
+  test_mainThread,
+  test_worker,
+];
+
+function next() {
+  if (!tests.length) {
+    SimpleTest.finish();
+    return;
+  }
+
+  let test = tests.shift();
+  test();
+}
+
+next();
+
+</script>
+</pre>
+</body>
+</html>