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

Unified Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html

Issue 1630683002: Canvas2d: addHitRegion() should take clipping region into account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 11 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/Source/modules/canvas2d/CanvasRenderingContext2D.cpp » ('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-hit-regions-clip-test.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html
new file mode 100644
index 0000000000000000000000000000000000000000..1eae955a659893375dfe1251ba46a24fdb7b6044
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-hit-regions-clip-test.html
@@ -0,0 +1,126 @@
+<!DOCTYPE html>
+<title>HitRegion Clip Test</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="./resources/test-helpers.js"></script>
+<canvas width="400" height="400"></canvas>
+<style>
+
+body {
+ margin : 0px;
+ padding : 0px;
+}
+
+</style>
+<script>
+
+var canvas = document.querySelector('canvas');
+var context = canvas.getContext('2d');
+
+function create_simple_rect_region_with_clip() {
+ context.clearRect(0, 0, 400, 400);
+ context.save();
+ context.beginPath();
+ context.rect(0, 0, 100, 100);
+ context.clip();
+ context.beginPath();
+ context.rect(50, 50, 100, 100);
+ context.fill();
+ context.addHitRegion({ id : 'clip' });
+ context.restore();
+}
+
+function create_non_rect_region_with_clip() {
+ context.clearRect(0, 0, 400, 400);
+ context.save();
+ context.beginPath();
+ context.arc(50, 50, 50, 0, Math.PI * 2);
+ context.clip();
+ context.beginPath();
+ context.rect(0, 0, 100, 100);
+ context.fill();
+ context.addHitRegion({ id : 'clip' });
+ context.restore();
+}
+
+function create_non_rect_region_with_multiple_clips() {
+ context.clearRect(0, 0, 400, 400);
+ context.save();
+ context.beginPath();
+ context.rect(0, 0, 100, 100);
+ context.clip();
+ context.beginPath();
+ context.arc(100, 50, 50, 0, Math.PI * 2);
+ context.clip();
+ context.beginPath();
+ context.rect(0, 0, 150, 50);
+ context.fill();
+ context.addHitRegion({ id : "clip" });
+ context.restore();
+}
+
+function no_pixel_test1() {
+ context.clearRect(0, 0, 400, 400);
+ context.save();
+ context.beginPath();
+ context.rect(0, 0, 100, 100);
+ context.clip();
+ context.beginPath();
+ context.rect(100, 100, 100, 100);
+ context.addHitRegion({ id : 'clip' });
+ context.restore();
+}
+
+function no_pixel_test2() {
+ context.save();
+ context.beginPath();
+ context.rect(0, 0, 50, 50);
+ context.rect(100, 0, 50, 50);
+ context.clip();
+ context.beginPath();
+ context.arc(75, 75, 30, 0, Math.PI * 2);
+ context.addHitRegion({ id : 'clip' });
+ context.restore();
+}
+
+coroutine(function*() {
+ setup({ explicit_done : true, explicit_timeout : true });
+
+ create_simple_rect_region_with_clip();
+ generate_tests(assert_equals, [
+ [ 'null', yield clickOrTouch(10, 10), null ],
+ [ 'clip', yield clickOrTouch(60, 60), 'clip' ]
+ ]);
+
+ create_non_rect_region_with_clip();
+ generate_tests(assert_equals, [
+ [ 'null', yield clickOrTouch(0, 0), null ],
+ [ 'null', yield clickOrTouch(100, 0), null ],
+ [ 'null', yield clickOrTouch(100, 100), null ],
+ [ 'null', yield clickOrTouch(0, 100), null ],
+ [ 'clip', yield clickOrTouch(50, 50), 'clip' ]
+ ]);
+
+ create_non_rect_region_with_multiple_clips();
+ generate_tests(assert_equals, [
+ [ 'null', yield clickOrTouch(00, 0), null ],
+ [ 'clip', yield clickOrTouch(100, 0), 'clip' ],
+ [ 'null', yield clickOrTouch(100, 100), null ],
+ [ 'null', yield clickOrTouch(0, 100), null ],
+ [ 'null', yield clickOrTouch(50, 0), null ],
+ [ 'null', yield clickOrTouch(150, 0), null ],
+ [ 'null', yield clickOrTouch(150, 100), null ],
+ [ 'null', yield clickOrTouch(50, 100), null ],
+ [ 'clip', yield clickOrTouch(50, 50), 'clip' ],
+ [ 'clip', yield clickOrTouch(100, 50), 'clip' ],
+ ]);
+
+ generate_tests(assert_throws, [
+ [ 'no pixel test1', { name : 'NotSupportedError' }, no_pixel_test1 ],
+ [ 'no pixel test2', { name : 'NotSupportedError' }, no_pixel_test2 ],
+ ]);
+
+ done();
+});
+
+</script>
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698