1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_inspector_getImageData.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=932937 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 932937</title> 1.12 + 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.15 + <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script> 1.16 + <script type="application/javascript;version=1.8"> 1.17 +Components.utils.import("resource://gre/modules/devtools/Loader.jsm"); 1.18 +const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {}); 1.19 + 1.20 +const inspector = devtools.require("devtools/server/actors/inspector"); 1.21 + 1.22 +window.onload = function() { 1.23 + SimpleTest.waitForExplicitFinish(); 1.24 + runNextTest(); 1.25 +} 1.26 + 1.27 +var gWalker = null; 1.28 + 1.29 +addTest(function setup() { 1.30 + let url = document.getElementById("inspectorContent").href; 1.31 + attachURL(url, function(err, client, tab, doc) { 1.32 + let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); 1.33 + let inspector = InspectorFront(client, tab); 1.34 + 1.35 + promiseDone(inspector.getWalker().then(walker => { 1.36 + gWalker = walker; 1.37 + }).then(runNextTest)); 1.38 + }); 1.39 +}); 1.40 + 1.41 +addTest(function testLargeImage() { 1.42 + // Select the image node from the test page 1.43 + gWalker.querySelector(gWalker.rootNode, ".big-horizontal").then(img => { 1.44 + ok(img, "Image node found in the test page"); 1.45 + ok(img.getImageData, "Image node has the getImageData function"); 1.46 + 1.47 + img.getImageData(100).then(imageData => { 1.48 + ok(imageData.data, "Image data actor was sent back"); 1.49 + ok(imageData.size, "Image size info was sent back too"); 1.50 + is(imageData.size.naturalWidth, 5333, "Natural width of the image correct"); 1.51 + is(imageData.size.naturalHeight, 3000, "Natural width of the image correct"); 1.52 + ok(imageData.size.resized, "Image was resized"); 1.53 + 1.54 + imageData.data.string().then(str => { 1.55 + ok(str, "We have an image data string!"); 1.56 + runNextTest(); 1.57 + }); 1.58 + }); 1.59 + }); 1.60 +}); 1.61 + 1.62 +addTest(function testLargeCanvas() { 1.63 + // Select the canvas node from the test page 1.64 + gWalker.querySelector(gWalker.rootNode, ".big-vertical").then(canvas => { 1.65 + ok(canvas, "Image node found in the test page"); 1.66 + ok(canvas.getImageData, "Image node has the getImageData function"); 1.67 + 1.68 + canvas.getImageData(350).then(imageData => { 1.69 + ok(imageData.data, "Image data actor was sent back"); 1.70 + ok(imageData.size, "Image size info was sent back too"); 1.71 + is(imageData.size.naturalWidth, 1000, "Natural width of the image correct"); 1.72 + is(imageData.size.naturalHeight, 2000, "Natural width of the image correct"); 1.73 + ok(imageData.size.resized, "Image was resized"); 1.74 + 1.75 + imageData.data.string().then(str => { 1.76 + ok(str, "We have an image data string!"); 1.77 + runNextTest(); 1.78 + }); 1.79 + }); 1.80 + }); 1.81 +}); 1.82 + 1.83 +addTest(function testSmallImage() { 1.84 + // Select the small image node from the test page 1.85 + gWalker.querySelector(gWalker.rootNode, ".small").then(img => { 1.86 + ok(img, "Image node found in the test page"); 1.87 + ok(img.getImageData, "Image node has the getImageData function"); 1.88 + 1.89 + img.getImageData().then(imageData => { 1.90 + ok(imageData.data, "Image data actor was sent back"); 1.91 + ok(imageData.size, "Image size info was sent back too"); 1.92 + is(imageData.size.naturalWidth, 245, "Natural width of the image correct"); 1.93 + is(imageData.size.naturalHeight, 240, "Natural width of the image correct"); 1.94 + ok(!imageData.size.resized, "Image was NOT resized"); 1.95 + 1.96 + imageData.data.string().then(str => { 1.97 + ok(str, "We have an image data string!"); 1.98 + runNextTest(); 1.99 + }); 1.100 + }); 1.101 + }); 1.102 +}); 1.103 + 1.104 +addTest(function cleanup() { 1.105 + delete gWalker; 1.106 + runNextTest(); 1.107 +}); 1.108 + </script> 1.109 +</head> 1.110 +<body> 1.111 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=932937">Mozilla Bug 932937</a> 1.112 +<a id="inspectorContent" target="_blank" href="inspector_getImageData.html">Test Document</a> 1.113 +<p id="display"></p> 1.114 +<div id="content" style="display: none"> 1.115 + 1.116 +</div> 1.117 +<pre id="test"> 1.118 +</pre> 1.119 +</body> 1.120 +</html>