Bug 1239752 - Clean up test files. r=roc
authorKaku Kuo <tkuo@mozilla.com>
Tue, 26 Jan 2016 10:53:46 +0800
changeset 324993 e4a9a3c7181a086cde9b96fd479bb446bf982db0
parent 324992 cc9415599767db66effe14268b0b7690916f8602
child 324994 71c56930fb7f513b43cee52966dae20159f07b41
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1239752
milestone47.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 1239752 - Clean up test files. r=roc MozReview-Commit-ID: S7mYwGDKk5
dom/canvas/test/imagebitmap_structuredclone.js
dom/canvas/test/imagebitmap_structuredclone_utils.js
dom/canvas/test/mochitest.ini
dom/canvas/test/test_imagebitmap_structuredclone.html
dom/canvas/test/test_imagebitmap_structuredclone_iframe.html
dom/canvas/test/test_imagebitmap_structuredclone_window.html
dom/canvas/test/test_imagebitmap_transfer.html
--- a/dom/canvas/test/imagebitmap_structuredclone.js
+++ b/dom/canvas/test/imagebitmap_structuredclone.js
@@ -1,15 +1,15 @@
 function ok(expect, msg) {
   postMessage({"type": "status", status: !!expect, msg: msg});
 }
 
 onmessage = function(event) {
   ok(!!event.data.bitmap1, "Get the 1st ImageBitmap from the main script.");
-  ok(!!event.data.bitmap2, "Get the 2st ImageBitmap from the main script.");
+  ok(!!event.data.bitmap2, "Get the 2nd ImageBitmap from the main script.");
 
   // send the first original ImageBitmap back to the main-thread
   postMessage({"type":"bitmap1",
                "bitmap":event.data.bitmap1});
 
   // create a new ImageBitmap from the 2nd original ImageBitmap
   // and then send the newly created ImageBitmap back to the main-thread
   var promise = createImageBitmap(event.data.bitmap2);
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/imagebitmap_structuredclone_utils.js
@@ -0,0 +1,95 @@
+var gImage1;
+var gImage2;
+var gImageBitmap1;
+var gImageBitmap2;
+
+function comparePixelColor(testImgageData, groundTruthImageData, x, y, tolerance, info) {
+  ok(testImgageData.width == groundTruthImageData.width && testImgageData.height == groundTruthImageData.height,
+     "testImgageData and groundTruthImageData should have the same dimension.");
+
+  var index = (groundTruthImageData.width * y + x) * 4;
+  var r = groundTruthImageData.data[index + 0];
+  var g = groundTruthImageData.data[index + 1];
+  var b = groundTruthImageData.data[index + 2];
+  var a = groundTruthImageData.data[index + 3];
+  var newR = testImgageData.data[index + 0];
+  var newG = testImgageData.data[index + 1];
+  var newB = testImgageData.data[index + 2];
+  var newA = testImgageData.data[index + 3];
+  var isTheSame = Math.abs(r - newR) <= tolerance &&
+                  Math.abs(g - newG) <= tolerance &&
+                  Math.abs(b - newB) <= tolerance &&
+                  Math.abs(a - newA) <= tolerance;
+  ok(isTheSame, "[" + info + "] " +
+                "newImageData(" + newR + "," + newG + "," + newB + "," + newA +
+                ") should equal to imageData(" + r + "," + g + "," + b + "," + a + ").");
+}
+
+function compareImageBitmapWithImageElement(imageBitmap, imageElement) {
+  var canvas1 = document.createElement('canvas');
+  var canvas2 = document.createElement('canvas');
+
+  canvas1.width  = imageElement.naturalWidth;
+  canvas1.height = imageElement.naturalHeight;
+  canvas2.width  = imageElement.naturalWidth;
+  canvas2.height = imageElement.naturalHeight;
+
+  var ctx1 = canvas1.getContext('2d');
+  var ctx2 = canvas2.getContext('2d');
+
+  ctx1.drawImage(imageElement, 0, 0);
+  ctx2.drawImage(imageBitmap, 0, 0);
+
+  document.body.appendChild(canvas1);
+  document.body.appendChild(canvas2);
+
+  var imageData1 = ctx1.getImageData(0, 0, canvas1.width, canvas1.height);
+  var imageData2 = ctx2.getImageData(0, 0, canvas2.width, canvas2.height);
+
+  // Create an array of pixels that is going to be tested.
+  var pixels = [];
+  var xGap = imageElement.naturalWidth / 4;
+  var yGap = imageElement.naturalHeight / 4;
+  for (var y = 0; y < imageElement.naturalHeight; y += yGap) {
+    for (var x = 0; x < imageElement.naturalWidth; x += xGap) {
+      pixels.push({"x":x, "y":y});
+    }
+  }
+
+  // Also, put the button-right pixel into pixels.
+  pixels.push({"x":imageElement.naturalWidth-1, "y":imageElement.naturalHeight-1});
+
+  // Do the test.
+  for (var pixel of pixels) {
+    comparePixelColor(imageData2, imageData1, pixel.x, pixel.y, 0);
+  }
+}
+
+function prepareImageBitmaps() {
+  gImage1 = document.createElement('img');
+  gImage2 = document.createElement('img');
+  gImage1.src = "image_rgrg-256x256.png";
+  gImage2.src = "image_yellow.png";
+
+  var p1 = new Promise(function(resolve, reject) {
+    gImage1.onload = function() {
+      var promise = createImageBitmap(gImage1);
+      promise.then(function(bitmap) {
+        gImageBitmap1 = bitmap;
+        resolve(true);
+      });
+    }
+  });
+
+  var p2 = new Promise(function(resolve, reject) {
+    gImage2.onload = function() {
+      var promise = createImageBitmap(gImage2);
+      promise.then(function(bitmap) {
+        gImageBitmap2 = bitmap;
+        resolve(true);
+      });
+    }
+  });
+
+  return Promise.all([p1, p2]);
+}
\ No newline at end of file
--- a/dom/canvas/test/mochitest.ini
+++ b/dom/canvas/test/mochitest.ini
@@ -25,16 +25,17 @@ support-files =
   image_transparent50.png
   image_yellow.png
   image_yellow75.png
   imagebitmap_bug1239300.js
   imagebitmap_bug1239752.js
   imagebitmap_on_worker.js
   imagebitmap_structuredclone.js
   imagebitmap_structuredclone_iframe.html
+  imagebitmap_structuredclone_utils.js
   offscreencanvas.js
   offscreencanvas_mask.svg
   offscreencanvas_neuter.js
   offscreencanvas_serviceworker_inner.html
 
 [test_2d.clearRect.image.offscreen.html]
 [test_2d.clip.winding.html]
 [test_2d.composite.canvas.color-burn.html]
--- a/dom/canvas/test/test_imagebitmap_structuredclone.html
+++ b/dom/canvas/test/test_imagebitmap_structuredclone.html
@@ -1,104 +1,35 @@
 <!DOCTYPE HTML>
 <title>Test ImageBitmap : Structured Clone</title>
 <meta charset="utf-8">
 <script src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 <body>
+<script src="imagebitmap_structuredclone_utils.js"></script>
 <script type="text/javascript">
 
-var gImage1;
-var gImage2;
-var gImageBitmap1;
-var gImageBitmap2;
-
-function isPixel(ctx1, ctx2, x, y) {
-  var pixel1 = ctx1.getImageData(x, y, 1, 1);
-  var pixel2 = ctx2.getImageData(x, y, 1, 1);
-  ok(pixel1.data[0] == pixel2.data[0] &&
-     pixel1.data[1] == pixel2.data[1] &&
-     pixel1.data[2] == pixel2.data[2] &&
-     pixel1.data[3] == pixel2.data[3],
-    "Color(" + pixel1.data[0] + ", " + pixel1.data[1] + ", " + pixel1.data[2] + ", " + pixel1.data[3] + ") should qual to Color(" + pixel2.data[0] + ", " + pixel2.data[1] + ", " + pixel2.data[2] + ", " + pixel2.data[3] +  ")");
-}
-
-function compareImageBitmapWithImageElement(imageBitmap, imageElement) {
-  var canvas1 = document.createElement('canvas');
-  var canvas2 = document.createElement('canvas');
-
-  canvas1.width  = imageElement.naturalWidth;
-  canvas1.height = imageElement.naturalHeight;
-  canvas2.width  = imageElement.naturalWidth;
-  canvas2.height = imageElement.naturalHeight;
-
-  var ctx1 = canvas1.getContext('2d');
-  var ctx2 = canvas2.getContext('2d');
-
-  ctx1.drawImage(imageElement, 0, 0);
-  ctx2.drawImage(imageBitmap, 0, 0);
-
-  document.body.appendChild(canvas1);
-  document.body.appendChild(canvas2);
-
-  for (var t = 0; t < 20; ++t) {
-    // check one random pixel
-    var randomX = Math.floor(Math.random() * imageElement.naturalWidth);
-    var randomY = Math.floor(Math.random() * imageElement.naturalHeight);
-    isPixel(ctx1, ctx2, randomX, randomY);
-  }
-}
-
 var worker = new Worker("imagebitmap_structuredclone.js");
 worker.onmessage = function(event) {
 
   if (event.data.type == "status") {
     ok(event.data.status, event.data.msg);
   } else if (event.data.type == "finish") {
     SimpleTest.finish();
   } else if (event.data.type == "bitmap1") {
     compareImageBitmapWithImageElement(event.data.bitmap, gImage1);
   } else if (event.data.type == "bitmap2") {
     compareImageBitmapWithImageElement(event.data.bitmap, gImage2);
   }
 }
 
-function prepareTwoImageBitmap() {
-  gImage1 = document.createElement('img');
-  gImage2 = document.createElement('img');
-  gImage1.src = "image_rgrg-256x256.png";
-  gImage2.src = "image_yellow.png";
-
-  var p1 = new Promise(function(resolve, reject) {
-    gImage1.onload = function() {
-      var promise = createImageBitmap(gImage1);
-      promise.then(function(bitmap) {
-        gImageBitmap1 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  var p2 = new Promise(function(resolve, reject) {
-    gImage2.onload = function() {
-      var promise = createImageBitmap(gImage2);
-      promise.then(function(bitmap) {
-        gImageBitmap2 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  return Promise.all([p1, p2]);
-}
-
 function runTests() {
   ok(worker, "Worker created successfully.");
 
-  prepareTwoImageBitmap().then(function(){
+  prepareImageBitmaps().then(function(){
     worker.postMessage({"bitmap1":gImageBitmap1, "bitmap2":gImageBitmap2});
   });
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTests);
 
 </script>
--- a/dom/canvas/test/test_imagebitmap_structuredclone_iframe.html
+++ b/dom/canvas/test/test_imagebitmap_structuredclone_iframe.html
@@ -1,87 +1,18 @@
 <!DOCTYPE HTML>
 <title>Test ImageBitmap : StructuredClone between main window and iframe</title>
 <meta charset="utf-8">
 <script src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 <body>
 <div id="content"></div>
+<script src="imagebitmap_structuredclone_utils.js"></script>
 <script type="text/javascript">
 
-var gImage1;
-var gImage2;
-var gImageBitmap1;
-var gImageBitmap2;
-
-function isPixel(ctx1, ctx2, x, y) {
-  var pixel1 = ctx1.getImageData(x, y, 1, 1);
-  var pixel2 = ctx2.getImageData(x, y, 1, 1);
-  ok(pixel1.data[0] == pixel2.data[0] &&
-     pixel1.data[1] == pixel2.data[1] &&
-     pixel1.data[2] == pixel2.data[2] &&
-     pixel1.data[3] == pixel2.data[3],
-    "Color(" + pixel1.data[0] + ", " + pixel1.data[1] + ", " + pixel1.data[2] + ", " + pixel1.data[3] + ") should qual to Color(" + pixel2.data[0] + ", " + pixel2.data[1] + ", " + pixel2.data[2] + ", " + pixel2.data[3] +  ")");
-}
-
-function compareImageBitmapWithImageElement(imageBitmap, imageElement) {
-  var canvas1 = document.createElement('canvas');
-  var canvas2 = document.createElement('canvas');
-
-  canvas1.width  = imageElement.naturalWidth;
-  canvas1.height = imageElement.naturalHeight;
-  canvas2.width  = imageElement.naturalWidth;
-  canvas2.height = imageElement.naturalHeight;
-
-  var ctx1 = canvas1.getContext('2d');
-  var ctx2 = canvas2.getContext('2d');
-
-  ctx1.drawImage(imageElement, 0, 0);
-  ctx2.drawImage(imageBitmap, 0, 0);
-
-  document.body.appendChild(canvas1);
-  document.body.appendChild(canvas2);
-
-  for (var t = 0; t < 20; ++t) {
-    // check one random pixel
-    var randomX = Math.floor(Math.random() * imageElement.naturalWidth);
-    var randomY = Math.floor(Math.random() * imageElement.naturalHeight);
-    isPixel(ctx1, ctx2, randomX, randomY);
-  }
-}
-
-function prepareTwoImageBitmap() {
-  gImage1 = document.createElement('img');
-  gImage2 = document.createElement('img');
-  gImage1.src = "image_rgrg-256x256.png";
-  gImage2.src = "image_yellow.png";
-
-  var p1 = new Promise(function(resolve, reject) {
-    gImage1.onload = function() {
-      var promise = createImageBitmap(gImage1);
-      promise.then(function(bitmap) {
-        gImageBitmap1 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  var p2 = new Promise(function(resolve, reject) {
-    gImage2.onload = function() {
-      var promise = createImageBitmap(gImage2);
-      promise.then(function(bitmap) {
-        gImageBitmap2 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  return Promise.all([p1, p2]);
-}
-
 function runTests() {
   window.onmessage = function(event) {
     if (event.data.type == "status") {
       ok(event.data.status, event.data.msg);
     } else if (event.data.type == "finish") {
       SimpleTest.finish();
     } else if (event.data.type == "bitmap1") {
       compareImageBitmapWithImageElement(event.data.bitmap, gImage1);
@@ -94,17 +25,17 @@ function runTests() {
   ok(div, "Parent exists");
 
   var ifr = document.createElement("iframe");
   ifr.addEventListener("load", iframeLoaded, false);
   ifr.setAttribute('src', "imagebitmap_structuredclone_iframe.html");
   div.appendChild(ifr);
 
   function iframeLoaded() {
-    prepareTwoImageBitmap().then(function(){
+    prepareImageBitmaps().then(function(){
       ifr.contentWindow.postMessage({"bitmap1":gImageBitmap1, "bitmap2":gImageBitmap2}, "*");
     });
   }
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTests);
 
--- a/dom/canvas/test/test_imagebitmap_structuredclone_window.html
+++ b/dom/canvas/test/test_imagebitmap_structuredclone_window.html
@@ -1,94 +1,25 @@
 <!DOCTYPE HTML>
 <title>Test ImageBitmap : StructuredClone main window to main window</title>
 <meta charset="utf-8">
 <script src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 <body>
+<script src="imagebitmap_structuredclone_utils.js"></script>
 <script type="text/javascript">
 
-var gImage1;
-var gImage2;
-var gImageBitmap1;
-var gImageBitmap2;
-
-function isPixel(ctx1, ctx2, x, y) {
-  var pixel1 = ctx1.getImageData(x, y, 1, 1);
-  var pixel2 = ctx2.getImageData(x, y, 1, 1);
-  ok(pixel1.data[0] == pixel2.data[0] &&
-     pixel1.data[1] == pixel2.data[1] &&
-     pixel1.data[2] == pixel2.data[2] &&
-     pixel1.data[3] == pixel2.data[3],
-    "Color(" + pixel1.data[0] + ", " + pixel1.data[1] + ", " + pixel1.data[2] + ", " + pixel1.data[3] + ") should qual to Color(" + pixel2.data[0] + ", " + pixel2.data[1] + ", " + pixel2.data[2] + ", " + pixel2.data[3] +  ")");
-}
-
-function compareImageBitmapWithImageElement(imageBitmap, imageElement) {
-  var canvas1 = document.createElement('canvas');
-  var canvas2 = document.createElement('canvas');
-
-  canvas1.width  = imageElement.naturalWidth;
-  canvas1.height = imageElement.naturalHeight;
-  canvas2.width  = imageElement.naturalWidth;
-  canvas2.height = imageElement.naturalHeight;
-
-  var ctx1 = canvas1.getContext('2d');
-  var ctx2 = canvas2.getContext('2d');
-
-  ctx1.drawImage(imageElement, 0, 0);
-  ctx2.drawImage(imageBitmap, 0, 0);
-
-  document.body.appendChild(canvas1);
-  document.body.appendChild(canvas2);
-
-  for (var t = 0; t < 20; ++t) {
-    // check one random pixel
-    var randomX = Math.floor(Math.random() * imageElement.naturalWidth);
-    var randomY = Math.floor(Math.random() * imageElement.naturalHeight);
-    isPixel(ctx1, ctx2, randomX, randomY);
-  }
-}
-
 window.onmessage = function(event) {
   compareImageBitmapWithImageElement(event.data.bitmap1, gImage1);
   compareImageBitmapWithImageElement(event.data.bitmap2, gImage2);
   SimpleTest.finish();
 }
 
-function prepareTwoImageBitmap() {
-  gImage1 = document.createElement('img');
-  gImage2 = document.createElement('img');
-  gImage1.src = "image_rgrg-256x256.png";
-  gImage2.src = "image_yellow.png";
-
-  var p1 = new Promise(function(resolve, reject) {
-    gImage1.onload = function() {
-      var promise = createImageBitmap(gImage1);
-      promise.then(function(bitmap) {
-        gImageBitmap1 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  var p2 = new Promise(function(resolve, reject) {
-    gImage2.onload = function() {
-      var promise = createImageBitmap(gImage2);
-      promise.then(function(bitmap) {
-        gImageBitmap2 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  return Promise.all([p1, p2]);
-}
-
 function runTests() {
-  prepareTwoImageBitmap().then(function(){
+  prepareImageBitmaps().then(function(){
     window.postMessage({"bitmap1":gImageBitmap1, "bitmap2":gImageBitmap2}, "*");
   });
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTests);
 
 </script>
--- a/dom/canvas/test/test_imagebitmap_transfer.html
+++ b/dom/canvas/test/test_imagebitmap_transfer.html
@@ -1,104 +1,35 @@
 <!DOCTYPE HTML>
 <title>Test ImageBitmap : Transfer</title>
 <meta charset="utf-8">
 <script src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
 <body>
+<script src="imagebitmap_structuredclone_utils.js"></script>
 <script type="text/javascript">
 
-var gImage1;
-var gImage2;
-var gImageBitmap1;
-var gImageBitmap2;
-
-function isPixel(ctx1, ctx2, x, y) {
-  var pixel1 = ctx1.getImageData(x, y, 1, 1);
-  var pixel2 = ctx2.getImageData(x, y, 1, 1);
-  ok(pixel1.data[0] == pixel2.data[0] &&
-     pixel1.data[1] == pixel2.data[1] &&
-     pixel1.data[2] == pixel2.data[2] &&
-     pixel1.data[3] == pixel2.data[3],
-    "Color(" + pixel1.data[0] + ", " + pixel1.data[1] + ", " + pixel1.data[2] + ", " + pixel1.data[3] + ") should qual to Color(" + pixel2.data[0] + ", " + pixel2.data[1] + ", " + pixel2.data[2] + ", " + pixel2.data[3] +  ")");
-}
-
-function compareImageBitmapWithImageElement(imageBitmap, imageElement) {
-  var canvas1 = document.createElement('canvas');
-  var canvas2 = document.createElement('canvas');
-
-  canvas1.width  = imageElement.naturalWidth;
-  canvas1.height = imageElement.naturalHeight;
-  canvas2.width  = imageElement.naturalWidth;
-  canvas2.height = imageElement.naturalHeight;
-
-  var ctx1 = canvas1.getContext('2d');
-  var ctx2 = canvas2.getContext('2d');
-
-  ctx1.drawImage(imageElement, 0, 0);
-  ctx2.drawImage(imageBitmap, 0, 0);
-
-  document.body.appendChild(canvas1);
-  document.body.appendChild(canvas2);
-
-  for (var t = 0; t < 20; ++t) {
-    // check one random pixel
-    var randomX = Math.floor(Math.random() * imageElement.naturalWidth);
-    var randomY = Math.floor(Math.random() * imageElement.naturalHeight);
-    isPixel(ctx1, ctx2, randomX, randomY);
-  }
-}
-
 var worker = new Worker("imagebitmap_structuredclone.js");
 worker.onmessage = function(event) {
 
   if (event.data.type == "status") {
     ok(event.data.status, event.data.msg);
   } else if (event.data.type == "finish") {
     SimpleTest.finish();
   } else if (event.data.type == "bitmap1") {
     compareImageBitmapWithImageElement(event.data.bitmap, gImage1);
   } else if (event.data.type == "bitmap2") {
     compareImageBitmapWithImageElement(event.data.bitmap, gImage2);
   }
 }
 
-function prepareTwoImageBitmap() {
-  gImage1 = document.createElement('img');
-  gImage2 = document.createElement('img');
-  gImage1.src = "image_rgrg-256x256.png";
-  gImage2.src = "image_yellow.png";
-
-  var p1 = new Promise(function(resolve, reject) {
-    gImage1.onload = function() {
-      var promise = createImageBitmap(gImage1);
-      promise.then(function(bitmap) {
-        gImageBitmap1 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  var p2 = new Promise(function(resolve, reject) {
-    gImage2.onload = function() {
-      var promise = createImageBitmap(gImage2);
-      promise.then(function(bitmap) {
-        gImageBitmap2 = bitmap;
-        resolve(true);
-      });
-    }
-  });
-
-  return Promise.all([p1, p2]);
-}
-
 function runTests() {
   ok(worker, "Worker created successfully.");
 
-  prepareTwoImageBitmap().then(function(){
+  prepareImageBitmaps().then(function(){
     worker.postMessage({"bitmap1":gImageBitmap1, "bitmap2":gImageBitmap2},
                        [gImageBitmap1, gImageBitmap2]);
 
     ok(gImageBitmap1.width == 0 && gImageBitmap1.height == 0,
        "After transfer, ImageBitmap become neutered");
     ok(gImageBitmap2.width == 0 && gImageBitmap2.height == 0,
        "After transfer, ImageBitmap become neutered");
   });