Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html

Issue 2689243002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Addressing comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html
index 9ff47f9b399ec809ab5cc8889ca936f2c22d6545..c61e268b2a89caa40fe93fbcb0bcb6ef30ab6f06 100644
--- a/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip.html
@@ -1,9 +1,75 @@
-<!doctype html>
-<html>
-<head>
-<script src="../../resources/js-test.js"></script>
-</head>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
<body>
<canvas id="canvas" width="200" height="200"></canvas>
-<script src="script-tests/canvas-path-context-clip.js"></script>
+<script>
+
+var ctx = document.getElementById('canvas').getContext('2d');
+
+function checkResult(expectedColors, sigma) {
+ data = ctx.getImageData(50, 50, 1, 1).data;
+ for (var i = 0; i < 4; i++)
+ assert_approx_equals(data[i], expectedColors[i], sigma);
+}
+
+function drawRectanglesOn(contextOrPath) {
+ contextOrPath.rect(0, 0, 100, 100);
+ contextOrPath.rect(25, 25, 50, 50);
+}
+
+function testClipWith(fillRule, path) {
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.fillStyle = 'rgb(0,255,0)';
+ if (path) {
+ if (fillRule) {
+ ctx.clip(path, fillRule);
+ } else {
+ ctx.clip(path);
+ }
+ } else {
+ ctx.beginPath();
+ drawRectanglesOn(ctx);
+ if (fillRule) {
+ ctx.clip(fillRule);
+ } else {
+ ctx.clip();
+ }
+ }
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ if (fillRule == 'evenodd') {
+ checkResult([255, 0, 0, 255], 5);
+ } else {
+ checkResult([0, 255, 0, 255], 5);
+ }
+}
+
+test(function(t) {
+ fillRules = [undefined, 'nonzero', 'evenodd'];
+ path = new Path2D();
+ drawRectanglesOn(path);
+
+ for (var i = 0; i < fillRules.length; i++) {
+ testClipWith(fillRules[i]);
+ testClipWith(fillRules[i], path);
+ }
+
+ // Test exception cases.
+ assert_throws(null, function() {ctx.clip(null);});
+ assert_throws(null, function() {ctx.clip(null, null);});
+ assert_throws(null, function() {ctx.clip(null, 'nonzero');});
+ assert_throws(null, function() {ctx.clip(path, null);});
+ assert_throws(null, function() {ctx.clip([], 'nonzero');});
+ assert_throws(null, function() {ctx.clip({}, 'nonzero');});
+ assert_throws(null, function() {ctx.clip(null, 'evenodd');});
+ assert_throws(null, function() {ctx.clip([], 'evenodd');});
+ assert_throws(null, function() {ctx.clip({}, 'evenodd');});
+ assert_throws(null, function() {ctx.clip('gazonk');});
+ assert_throws(null, function() {ctx.clip(path, 'gazonk');});
+ assert_throws(null, function() {ctx.clip(undefined, undefined);});
+ assert_throws(null, function() {ctx.clip(undefined, 'nonzero');});
+}, 'Series of tests to ensure clip() works with path and winding rule parameters.');
+</script>
</body>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/canvas/canvas-path-context-clip-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698