Bug 1473224 - Use blob URL instead of data URL for image data in clipboard test. r=yulia
authorTom Schuster <evilpies@gmail.com>
Mon, 19 Nov 2018 09:53:36 +0000
changeset 503390 df938148d900a6010c1a31471e7939d7282a53b5
parent 503389 3ebe77971c61f5d535272ebfde2616d8b01ac696
child 503391 0aa2cbe139c38c0b61066d96a53da6fde3d253ae
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1473224
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1473224 - Use blob URL instead of data URL for image data in clipboard test. r=yulia String.fromCharCode(...charCodes) is limited by the maximum number of arguments that SpiderMonkey can pass on the stack, if the screenshot gets to large this can easily fail. Differential Revision: https://phabricator.services.mozilla.com/D12218
devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command_clipboard.js
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command_clipboard.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command_clipboard.js
@@ -167,48 +167,49 @@ async function getImageSizeFromClipboard
   const data = {};
   const dataLength = {};
   trans.getTransferData(flavor, data, dataLength);
 
   ok(data.value, "screenshot exists");
   ok(dataLength.value > 0, "screenshot has length");
 
   let image = data.value;
-  let dataURI = `data:${flavor};base64,`;
 
   // Due to the differences in how images could be stored in the clipboard the
   // checks below are needed. The clipboard could already provide the image as
   // byte streams or as image container. If it's not possible obtain a
   // byte stream, the function throws.
 
   if (image instanceof Ci.imgIContainer) {
     image = Cc["@mozilla.org/image/tools;1"]
               .getService(Ci.imgITools)
               .encodeImage(image, flavor);
   }
 
+  let url;
   if (image instanceof Ci.nsIInputStream) {
     const binaryStream = Cc["@mozilla.org/binaryinputstream;1"]
                          .createInstance(Ci.nsIBinaryInputStream);
     binaryStream.setInputStream(image);
-    const rawData = binaryStream.readBytes(binaryStream.available());
-    const charCodes = Array.from(rawData, c => c.charCodeAt(0) & 0xff);
-    let encodedData = String.fromCharCode(...charCodes);
-    encodedData = btoa(encodedData);
-    dataURI = dataURI + encodedData;
+    const available = binaryStream.available();
+    const buffer = new ArrayBuffer(available);
+    is(binaryStream.readArrayBuffer(available, buffer), available,
+       "Read expected amount of data");
+    url = URL.createObjectURL(new Blob([buffer], {type: flavor}));
   } else {
     throw new Error("Unable to read image data");
   }
 
   const img = document.createElementNS("http://www.w3.org/1999/xhtml", "img");
 
   const loaded =  once(img, "load");
 
-  img.src = dataURI;
+  img.src = url;
   document.documentElement.appendChild(img);
   await loaded;
   img.remove();
+  URL.revokeObjectURL(url);
 
   return {
     width: img.width,
     height: img.height,
   };
 }