Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Test for checking that the lookup table is applied on image load.

Mike McGann498e0db8349e
diff --git a/build.xml b/build.xml
index 30079f157..1cf453569 100644
--- a/build.xml
+++ b/build.xml
@@ -180,26 +180,28 @@
<arg value="jsTestDriver-prod.conf"/>
</exec>
</target>
-
- <target name="test-devel" description="Test development js files">
- <delete dir="${build.test.dir}/min"/>
- <mkdir dir="${build.test.dir}/min"/>
- <exec executable="java">
+
+ <target name="start-test-server">
+ <exec executable="java" spawn="true">
<arg value="-jar"/>
<arg value="${js-test-driver.jar.path}"/>
<arg value="--port"/>
<arg value="${js-test-driver.port}"/>
- <arg value="--browser"/>
- <arg value="${js-test-driver.macosx.browsers}"/>
+ </exec>
+ <echo message="Capture browser at http://localhost:${js-test-driver.port}"/>
+ </target>
+
+ <target name="test-devel">
+ <exec executable="java">
+ <arg value="-jar"/>
+ <arg value="${js-test-driver.jar.path}"/>
<arg value="--tests"/>
<arg value="all"/>
- <arg value="--testOutput"/>
- <arg value="${build.test.dir}"/>
<arg value="--config"/>
<arg value="jsTestDriver-devel.conf"/>
</exec>
</target>
-
+
<target name="test" depends="test-prod,test-devel"
description="Run test suite on production and development files"/>
diff --git a/js/OpenLayers/Tile/Canvas.js b/js/OpenLayers/Tile/Canvas.js
index e69cb728c..4c913bbab 100644
--- a/js/OpenLayers/Tile/Canvas.js
+++ b/js/OpenLayers/Tile/Canvas.js
@@ -163,16 +163,9 @@ OpenLayers.Tile.Canvas = OpenLayers.Class(OpenLayers.Tile.Image,
*
* @private
*/
- onImageLoad: function() {
- var i;
- var imageData;
- var lookup;
- var lookupTable;
- var pixels;
- var color;
-
+ onImageLoad: function() {
var graphics = this.canvas.getContext("2d");
-
+
OpenLayers.Event.stopObservingElement(this.imgDiv);
this.canvas.width = this.imgDiv.width;
@@ -180,16 +173,25 @@ OpenLayers.Tile.Canvas = OpenLayers.Class(OpenLayers.Tile.Image,
graphics.drawImage(this.imgDiv, 0, 0);
- if ( this.layer.lookUpTable ) {
- lookupTable = this.layer.lookUpTable;
- imageData = graphics.getImageData(0, 0, this.canvas.width,
+ if ( this.layer.lookupTable ) {
+ var lookupTable = this.layer.lookupTable;
+ var imageData = graphics.getImageData(0, 0, this.canvas.width,
this.canvas.height);
- pixels = new Uint32Array(imageData.data);
-
- for ( i = 0; i < pixels.length; i++ ) {
- color = lookupTable[pixels[i]];
+ var pixels = imageData.data;
+
+ for ( var i = 0; i < pixels.length; i += 4 ) {
+ var lookup =
+ (pixels[0] << 24) |
+ (pixels[1] << 16) |
+ (pixels[2] << 8) |
+ pixels[3];
+
+ var color = lookupTable[lookup];
if ( color ) {
- pixels[i] = color;
+ pixels[0] = color >> 24 & 0xff;
+ pixels[1] = color >> 16 & 0xff;
+ pixels[2] = color >> 8 & 0xff;
+ pixels[3] = color & 0xff;
}
}
}
diff --git a/jsTestDriver-devel.conf b/jsTestDriver-devel.conf
index 2594a4eca..91f544e92 100644
--- a/jsTestDriver-devel.conf
+++ b/jsTestDriver-devel.conf
@@ -33,3 +33,4 @@ test:
- test/OpenLayers/Tile/*.js
timeout: 30
+
\ No newline at end of file
diff --git a/test/OpenLayers/Tile/testCanvas.js b/test/OpenLayers/Tile/testCanvas.js
index eac0c0359..a170a349b 100644
--- a/test/OpenLayers/Tile/testCanvas.js
+++ b/test/OpenLayers/Tile/testCanvas.js
@@ -9,10 +9,13 @@
* All Rights Reserved.
*/
-TestCase("Test.OpenLayers.Tile.Canvas", {
+TestCase("CanvasTile", {
tile: null,
-
+ mockImageData: null,
+ mockGraphics: null,
+ mockCanvas: null,
+
setUp: function() {
var mockLayer = mock(OpenLayers.Layer.WMS);
var mockMap = mock(OpenLayers.Map);
@@ -24,7 +27,34 @@ TestCase("Test.OpenLayers.Tile.Canvas", {
new OpenLayers.Bounds(0, 0, 1, 1), // lat/lon bb
"http://example.com/wms",
new OpenLayers.Size(512, 512) // tile size
- );
+ );
+
+ // Image of one pixel
+ mockImageData = new Uint8ClampedArray([1, 2, 3, 4]);
+
+ // Canvas graphics context of the mock image
+ mockGraphics = {
+ drawImage: function() {
+ },
+
+ getImageData: function() {
+ return {
+ length: 4,
+ data: mockImageData
+ }
+ }
+ };
+
+ // Canvas that holds the mock image
+ mockCanvas = {
+ width: 1,
+ height: 1,
+ style: {},
+
+ getContext: function() {
+ return mockGraphics;
+ }
+ };
},
testDestroyRemovesCanvas: function() {
@@ -54,5 +84,24 @@ TestCase("Test.OpenLayers.Tile.Canvas", {
assertNotNull(tile.canvas);
},
+ testOnImageLoadUsesLookupTable: function() {
+ tile.canvas = mockCanvas;
+
+ // Make the image dimenesions the same as the mock canvas
+ tile.imgDiv = {
+ width: 1,
+ height: 1
+ };
+
+ tile.layer.lookupTable = {
+ 0x01020304: 0x05060708
+ };
+
+ tile.onImageLoad();
+ assertEquals(0x05, mockImageData[0]);
+ assertEquals(0x06, mockImageData[1]);
+ assertEquals(0x07, mockImageData[2]);
+ assertEquals(0x08, mockImageData[3]);
+ },
});