Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / context / premultiplyalpha-test.html
index ecb370a..8c3aea1 100644 (file)
@@ -156,90 +156,106 @@ var gl;
 var canvas;
 var premultipliedAlpha;
 
+enableJSTestPreVerboseLogging();
 description("Test the WebGL premultipliedAlpha context creation flag.");
 doNextTest();
 function doNextTest() {
   if (g_count < tests.length) {
-     var test = tests[g_count++];
-     canvas = document.createElement("canvas");
-     // Need to preserve drawing buffer to load it in a callback
-     test.creationAttributes.preserveDrawingBuffer = true;
-     gl = wtu.create3DContext(canvas, test.creationAttributes);
-     var premultipliedAlpha = test.creationAttributes.premultipliedAlpha != false;
-     var antialias = test.creationAttributes.antialias == true;
-     debug("")
-     debug("testing: premultipliedAlpha: " + premultipliedAlpha
-         + ", antialias: " + antialias
-         + ", imageFormat: " + test.imageFormat);
-
-     shouldBe('gl.getContextAttributes().premultipliedAlpha', premultipliedAlpha.toString());
-     shouldBeTrue('gl.getContextAttributes().preserveDrawingBuffer');
-
-     wtu.log(gl.getContextAttributes());
-     var program = wtu.setupTexturedQuad(gl);
-
-     wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
-     var tex = gl.createTexture();
-     wtu.fillTexture(gl, tex, 2, 2, test.sentColor, 0);
-     var loc = gl.getUniformLocation(program, "tex");
-     gl.uniform1i(loc, 0);
-     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
-     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
-     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
-     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
-
-     wtu.clearAndDrawUnitQuad(gl);
-     wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from drawing.");
-
-     var loadTexture = function() {
-       var pngTex = gl.createTexture();
-       // not needed as it's the default
-       // gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
-       gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
-       gl.bindTexture(gl.TEXTURE_2D, pngTex);
-       if (test.imageFormat) {
-          // create texture from image
-          gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this);
-       } else {
-          // create texture from canvas
-          gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
-       }
-       gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
-       gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
-       gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
-       gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
-       wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from creating copy.");
-       wtu.clearAndDrawUnitQuad(gl);
-       wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from 2nd drawing.");
-       wtu.checkCanvas(
-          gl, test.expectedColor,
-          "should draw with " + test.expectedColor, test.errorRange);
-
-       doNextTest();
-     }
-
-     if (test.imageFormat) {
-        // Load canvas into string using toDataURL
-        var imageUrl = canvas.toDataURL(test.imageFormat);
-        if (test.imageFormat != "image/png" &&
-            (imageUrl.indexOf("data:image/png,") == 0 ||
-             imageUrl.indexOf("data:image/png;") == 0)) {
-          debug("Image format " + test.imageFormat + " not supported; skipping");
-          setTimeout(doNextTest, 0);
-        } else {
-          // Load string into the texture
-          var input = document.createElement("img");
-          input.onload = loadTexture;
-          input.src = imageUrl;
-        }
-     } else {
-        // Load canvas into the texture asynchronously (to prevent unbounded stack consumption)
-        setTimeout(loadTexture, 0);
-     }
-   } else {
-      var successfullyParsed = true;
+    var test = tests[g_count++];
+    canvas = document.createElement("canvas");
+    // Need to preserve drawing buffer to load it in a callback
+    test.creationAttributes.preserveDrawingBuffer = true;
+    gl = wtu.create3DContext(canvas, test.creationAttributes);
+    var premultipliedAlpha = test.creationAttributes.premultipliedAlpha != false;
+    var antialias = test.creationAttributes.antialias == true;
+    debug("")
+    debug("testing: premultipliedAlpha: " + premultipliedAlpha
+        + ", antialias: " + antialias
+        + ", imageFormat: " + test.imageFormat);
+
+    shouldBe('gl.getContextAttributes().premultipliedAlpha', premultipliedAlpha.toString());
+    shouldBeTrue('gl.getContextAttributes().preserveDrawingBuffer');
+
+    wtu.log(gl.getContextAttributes());
+    var program = wtu.setupTexturedQuad(gl);
+
+    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
+    var tex = gl.createTexture();
+    wtu.fillTexture(gl, tex, 2, 2, test.sentColor, 0);
+    var loc = gl.getUniformLocation(program, "tex");
+    gl.uniform1i(loc, 0);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+
+    wtu.clearAndDrawUnitQuad(gl);
+    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from drawing.");
+
+    var loadTexture = function() {
+      debug("loadTexture called");
+      var pngTex = gl.createTexture();
+      // not needed as it's the default
+      // gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
+      gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
+      gl.bindTexture(gl.TEXTURE_2D, pngTex);
+      if (test.imageFormat) {
+         // create texture from image
+         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this);
+      } else {
+         // create texture from canvas
+         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
+      }
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+      wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from creating copy.");
+      wtu.clearAndDrawUnitQuad(gl);
+      wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from 2nd drawing.");
+      wtu.checkCanvas(
+         gl, test.expectedColor,
+         "should draw with " + test.expectedColor, test.errorRange);
+
+      doNextTest();
+    }
+
+    var loadTextureError = function() {
+      testFailed("Creating image from canvas failed. Image src: " + this.src);
       finishTest();
-   }
+    }
+
+    var shrinkString = function(string) {
+      if (string.length < 63) {
+        return string;
+      }
+      return string.substr(0, 30) + "..." + string.substr(string.length - 30);
+    }
+
+    if (test.imageFormat) {
+      // Load canvas into string using toDataURL
+      debug("Calling canvas.toDataURL('" + test.imageFormat + "')");
+      var imageUrl = canvas.toDataURL(test.imageFormat);
+      debug("imageUrl = '" + shrinkString(imageUrl) + "'");
+      if (test.imageFormat != "image/png" &&
+          (imageUrl.indexOf("data:image/png,") == 0 ||
+           imageUrl.indexOf("data:image/png;") == 0)) {
+        debug("Image format " + test.imageFormat + " not supported; skipping");
+        setTimeout(doNextTest, 0);
+      } else {
+        // Load string into the texture
+        debug("Waiting for image.onload");
+        var input = wtu.makeImage(imageUrl, loadTexture, loadTextureError);
+      }
+    } else {
+      // Load canvas into the texture asynchronously (to prevent unbounded stack consumption)
+      debug("Waiting for setTimeout");
+      setTimeout(loadTexture, 0);
+    }
+  } else {
+    var successfullyParsed = true;
+    finishTest();
+  }
 }
 
 </script>