Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-path-addpath.js
index c2fa3f2..4e8b5db 100644 (file)
@@ -1,7 +1,9 @@
 description("Test addPath() method.");
-var ctx = document.createElement('canvas').getContext('2d');
+var canvas = document.createElement('canvas');
+var ctx = canvas.getContext('2d');
 
 debug("Test addPath() with transform as identity matrix.")
+ctx.clearRect(0, 0, canvas.width, canvas.height);
 ctx.beginPath();
 var p1 = new Path2D();
 p1.rect(0,0,100,100);
@@ -10,8 +12,7 @@ p2.rect(0,100,100,100);
 var m = ctx.currentTransform;
 p1.addPath(p2, m);
 ctx.fillStyle = 'yellow';
-ctx.currentPath = p1;
-ctx.fill();
+ctx.fill(p1);
 var imageData = ctx.getImageData(0, 100, 100, 100);
 var imgdata = imageData.data;
 shouldBe("imgdata[4]", "255");
@@ -21,6 +22,7 @@ shouldBe("imgdata[7]", "255");
 debug("");
 
 debug("Test addPath() with transform as translate(100, -100).")
+ctx.clearRect(0, 0, canvas.width, canvas.height);
 ctx.beginPath();
 var p3 = new Path2D();
 p3.rect(0,0,100,100);
@@ -31,8 +33,7 @@ m.c = 0; m.d = 1;
 m.e = 100; m.f = -100;
 p3.addPath(p4, m);
 ctx.fillStyle = 'yellow';
-ctx.currentPath = p3;
-ctx.fill();
+ctx.fill(p3);
 imageData = ctx.getImageData(100, 0, 100, 100);
 imgdata = imageData.data;
 shouldBe("imgdata[4]", "255");
@@ -42,6 +43,7 @@ shouldBe("imgdata[7]", "255");
 debug("");
 
 debug("Test addPath() with non-invertible transform.")
+ctx.clearRect(0, 0, canvas.width, canvas.height);
 ctx.beginPath();
 var p5 = new Path2D();
 p5.rect(0,0,100,100);
@@ -52,8 +54,7 @@ m.c = 0; m.d = 0;
 m.e = 0; m.f = 0;
 p5.addPath(p6, m);
 ctx.fillStyle = 'yellow';
-ctx.currentPath = p5;
-ctx.fill();
+ctx.fill(p5);
 imageData = ctx.getImageData(100, 100, 100, 100);
 imgdata = imageData.data;
 shouldNotBe("imgdata[4]", "255");
@@ -63,17 +64,17 @@ shouldNotBe("imgdata[7]", "255");
 debug("");
 
 debug("Test addPath() with transform as null or invalid type.")
+ctx.clearRect(0, 0, canvas.width, canvas.height);
 ctx.beginPath();
 var p7 = new Path2D();
 p7.rect(0,0,100,100);
 var p8 = new Path2D();
 p8.rect(100,100,100,100);
 p7.addPath(p8, null);
-p7.addPath(p8, []);
-p7.addPath(p8, {});
+shouldThrow("p7.addPath(p8, [])");
+shouldThrow("p7.addPath(p8, {})");
 ctx.fillStyle = 'red';
-ctx.currentPath = p7;
-ctx.fill();
+ctx.fill(p7);
 imageData = ctx.getImageData(100, 100, 100, 100);
 imgdata = imageData.data;
 shouldBe("imgdata[4]", "255");
@@ -82,6 +83,23 @@ shouldBe("imgdata[6]", "0");
 shouldBe("imgdata[7]", "255");
 debug("");
 
+debug("Test addPath() with transform omitted.")
+ctx.clearRect(0, 0, canvas.width, canvas.height);
+ctx.beginPath();
+var p9 = new Path2D();
+var p10 = new Path2D();
+p9.rect(0,0,10,10);
+p10.addPath(p9);
+ctx.fillStyle = 'red';
+ctx.fill(p10);
+imageData = ctx.getImageData(1, 1, 1, 1);
+imgdata = imageData.data;
+shouldBe("imgdata[0]", "255");
+shouldBe("imgdata[1]", "0");
+shouldBe("imgdata[2]", "0");
+shouldBe("imgdata[3]", "255");
+debug("");
+
 debug("Test addPath() with path as null and invalid type");
 var p9 = new Path2D();
 p9.rect(0,0,100,100);