Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / canvas-createImageBitmap-invalid-args.html
index 3007d94..cd4e021 100644 (file)
@@ -1,15 +1,14 @@
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 <html>
 <head>
-<script src="../js/resources/js-test-pre.js"></script>
+<script src="../../resources/js-test.js"></script>
 </head>
 <body>
 <script>
 description("Ensure correct behavior of createImageBitmap for invalid inputs.");
 window.jsTestIsAsync = true;
 
-var InvalidStateError = "InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.";
-var TypeError = "TypeError: Type error";
+var TypeError = "TypeError: Failed to execute 'createImageBitmap' on 'Window': No function was found that matched the signature provided.";
 var IndexSizeError = "IndexSizeError: Index or size was negative, or greater than the allowed value.";
 
 var image;
@@ -17,6 +16,8 @@ var testBitmap; // an ImageBitmap that is uncropped. We use this to test createI
 var d;          // image.imageData
 var blob;
 var invalidBlob;
+var invalidBlobTestPassed = false;
+var invalidCanvasTestPassed = false;
 
 // Draw to an auxillary canvas.
 var aCanvas = document.createElement("canvas");
@@ -24,18 +25,23 @@ aCanvas.setAttribute("width", "200");
 aCanvas.setAttribute("height", "200");
 var aCtx = aCanvas.getContext("2d");
 
+// Create a terapixel canvas to generate an invalid canvas through allocation failure
+var invalidCanvas = document.createElement("canvas");
+invalidCanvas.setAttribute("width", "1000000");
+invalidCanvas.setAttribute("height", "1000000");
+
 image = new Image();
 image.onload = imageLoaded;
 
 // Before image loads
-shouldThrow("createImageBitmap(image)", "InvalidStateError");
+shouldThrow("createImageBitmap(image)");
 image.src = aCanvas.toDataURL();
 
 video = document.createElement("video");
 video.addEventListener("canplaythrough", videoLoaded, false);
 
 // Before video loads
-shouldThrow("createImageBitmap(video)", "InvalidStateError");
+shouldThrow("createImageBitmap(video)");
 video.src = "../../compositing/resources/video.ogv";
 
 var imageLoaded = false;
@@ -76,7 +82,7 @@ xhr.onload = function() {
 }
 
 var xhr2 = new XMLHttpRequest();
-xhr2.open("GET", 'resources/repaint.js');
+xhr2.open("GET", 'resources/shadow-offset.js');
 xhr2.responseType = 'blob';
 xhr2.send();
 xhr2.onload = function() {
@@ -85,41 +91,67 @@ xhr2.onload = function() {
     loaded();
 }
 
+var finishIfDoneCallsRemaining = 2;
+function finishIfDone() {
+    finishIfDoneCallsRemaining--;
+    if (!finishIfDoneCallsRemaining) {
+        // Because promise fulfillment is asynchonous, pass/fail messages
+        // must be handled here to ensure a deterministic message order.
+        if (invalidBlobTestPassed) {
+            testPassed("createImageBitmap(invalidBlob) was rejected.");
+        } else {
+            testFailed("Invalid blob fulfilled.");
+        }
+        if (invalidCanvasTestPassed) {
+            testPassed("createImageBitmap(invalidCanvas) was rejected.");
+        } else {
+            testFailed("Invalid canvas fulfilled.");
+        }
+        finishJSTest();
+    }
+}
+
 function loaded() {
     if (imageLoaded && videoLoaded && imageBitmapLoaded && blobLoaded && invalidBlobLoaded) {
         shouldThrow("createImageBitmap(undefined)", "TypeError");
+        shouldThrow("createImageBitmap(null)", "TypeError");
 
-        shouldThrow("createImageBitmap(image, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(image, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(image, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(image, 0, 0, 0, 10)");
 
-        shouldThrow("createImageBitmap(video, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(video, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(video, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(video, 0, 0, 0, 10)");
 
-        shouldThrow("createImageBitmap(aCanvas, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(aCanvas, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(aCanvas, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(aCanvas, 0, 0, 0, 10)");
 
-        shouldThrow("createImageBitmap(d, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(d, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(d, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(d, 0, 0, 0, 10)");
 
-        shouldThrow("createImageBitmap(aCtx, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(aCtx, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(aCtx, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(aCtx, 0, 0, 0, 10)");
 
-        shouldThrow("createImageBitmap(testBitmap, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(testBitmap, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(testBitmap, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(testBitmap, 0, 0, 0, 10)");
 
-        shouldThrow("createImageBitmap(blob, 0, 0, 10, 0)", "IndexSizeError");
-        shouldThrow("createImageBitmap(blob, 0, 0, 0, 10)", "IndexSizeError");
+        shouldThrow("createImageBitmap(blob, 0, 0, 10, 0)");
+        shouldThrow("createImageBitmap(blob, 0, 0, 0, 10)");
 
         createImageBitmap(invalidBlob).then(function() {
-            testFailed("Invalid blob fulfilled.");
-            finishJSTest();
+            finishIfDone();
         }, function() {
-            testPassed("createImageBitmap(invalidBlob) was rejected.");
-            finishJSTest();
+            invalidBlobTestPassed = true;
+            finishIfDone();
         });
-    }
-}
 
+        createImageBitmap(invalidCanvas).then(function() {
+            finishIfDone();
+        }, function() {
+            invalidCanvasTestPassed = true;
+            finishIfDone();
+        });
+        }
+}
 </script>
 </body>
 </html>