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

Side by Side Diff: LayoutTests/fast/canvas/canvas-direction.html

Issue 468483003: Implement canvas2d direction attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <head>
3 <style>
4 .pass {
5 color: green;
6 font-weight: bold;
7 }
8
9 .fail {
10 color: red;
11 font-weight: bold;
12 }
13 </style>
14 </head>
15 <body>
16 <span>Tests that canvas 2d context supports 'direction' attribute: <span id="sup ported"></span></span>
17 <div>
18 <span>Tests that context.direction is 'ltr' with parent element having unspecifi ed direction: <span id="result1"></span></span><br>
19 <canvas id="canvas1" width=400 height=20 style="border:1px solid black"></canvas >
20 </div>
21 <div dir="rtl">
22 <span>Tests that context.direction is 'rtl' with parent element having direction as rtl: <span id="result2"></span></span><br>
23 <canvas id="canvas2" width=400 height=20 style="border:1px solid black"></canvas >
24 </div>
25 <div>
26 <span>Tests that context.direction is overridden by 'rtl' with parent element ha ving unspecified direction: <span id="result3"></span></span><br>
27 <canvas id="canvas3" width=400 height=20 style="border:1px solid black"></canvas >
28 </div>
29 <div dir="rtl">
30 <span>Tests that context.direction is overridden by 'ltr' with parent element ha ving direction as rtl: <span id="result4"></span></span><br>
31 <canvas id="canvas4" width=400 height=20 style="border:1px solid black"></canvas >
32 </div>
33 <div>
34 <span>Tests that context.direction is overridden by 'inherit' with parent elemen t having unspecified direction: <span id="result5"></span></span><br>
35 <canvas id="canvas5" width=400 height=20 style="border:1px solid black"></canvas >
36 </div>
37 <div dir="rtl">
38 <span>Tests that context.direction is overridden by 'inherit' with parent elemen t having direction as rtl: <span id="result6"></span></span><br>
39 <canvas id="canvas6" width=400 height=20 style="border:1px solid black"></canvas >
40 </div>
41 <div>
42 <span>Tests that context.reset sets the direction as ltr<span id="result7"></spa n></span><br>
43 <canvas id="canvas7" width=400 height=20 style="border:1px solid black"></canvas >
44 </div>
45 <div dir="rtl">
46 <span>Tests that context.reset sets the direction as rtl<span id="result8"></spa n></span><br>
47 <canvas id="canvas8" width=400 height=20 style="border:1px solid black"></canvas >
48 </div>
49 <div id="results">
50 </div>
51 <script>
52 if (window.testRunner)
53 testRunner.dumpAsText();
54
55 var newCanvasElement = document.createElement('canvas');
56 document.getElementById('supported').textContent = newCanvasElement.getContext(' 2d').direction ? 'PASS' : 'FAIL';
57 document.getElementById('supported').className = newCanvasElement.getContext('2d ').direction ? 'pass' : 'fail';
58
59 var fontSettings = "12px 'Arial'";
60
61 function appendResult(description, result)
62 {
63 var descriptionElement = document.createElement('span');
64 var resultElement = document.createElement('span');
65 descriptionElement.innerHTML = description;
66 resultElement.textContent = result;
67 resultElement.className = (result === 'PASS') ? 'pass' : 'fail';
68 descriptionElement.appendChild(resultElement);
69 document.getElementById("results").appendChild(descriptionElement);
70 document.getElementById("results").appendChild(document.createElement('br')) ;
71 }
72
73 function verifyDrawText(canvasId, resultId, text, expectedDirection)
74 {
75 var canvasElement = document.getElementById(canvasId);
76 var resultElement = document.getElementById(resultId);
77 var ctx = canvasElement.getContext('2d');
78 var width = canvasElement.width/2;
79 var height = canvasElement.height;
80 resultElement.textContent = (ctx.direction == expectedDirection) ? 'PASS' : 'FAIL';
81 resultElement.className = (ctx.direction == expectedDirection) ? 'pass' : 'f ail';
82 ctx.moveTo(width, 0);
83 ctx.lineTo(width, height);
84 ctx.stroke();
85 ctx.font = fontSettings;
86 ctx.fillText(text, width, height/2);
87 }
88
89 function verifyDrawTextWithSpecifiedDirection(canvasId, resultId, text, directio n, expectedDirection)
90 {
91 var canvasElement = document.getElementById(canvasId);
92 var resultElement = document.getElementById(resultId);
93 var ctx = canvasElement.getContext('2d');
94 var width = canvasElement.width/2;
95 var height = canvasElement.height;
96 var currentDirection = ctx.direction;
97 ctx.direction = direction;
98 resultElement.textContent = (currentDirection && ctx.direction == expectedDi rection) ? 'PASS' : 'FAIL';
99 resultElement.className = (currentDirection && ctx.direction == expectedDire ction) ? 'pass' : 'fail';
100 ctx.moveTo(width, 0);
101 ctx.lineTo(width, height);
102 ctx.stroke();
103 ctx.font = fontSettings;
104 ctx.fillText(text, width, height/2);
105 }
106
107 function verifyDirectionAfterReset(canvasId, text, direction, expectedDirection)
108 {
109 var canvasElement = document.getElementById(canvasId);
110 var width = canvasElement.width/2;
111 var height = canvasElement.height;
112 var ctx = canvasElement.getContext('2d');
113 ctx.direction = direction;
114 ctx.moveTo(width, 0);
115 ctx.lineTo(width, height);
116 ctx.stroke();
117 ctx.font = fontSettings;
118 ctx.fillText(text, width, height/2);
119 canvasElement.width = canvasElement.width + 1;
120 var description = 'Tests that context.reset() sets the context.direction to ' + expectedDirection + ': ';
121 var result = (ctx.direction == expectedDirection) ? 'PASS' : 'FAIL';
122 appendResult(description, result);
123 document.body.removeChild(canvasElement.parentElement);
124 }
125
126 function verifyInvalidDirection(direction)
127 {
128 var ctx = document.createElement('canvas').getContext('2d');
129 var currentDirection = ctx.direction;
130 ctx.direction = direction;
131 var description = 'Tests that invalid direction value ' + direction + ' has no effect on the context.direction: ';
132 var result = (ctx.direction == currentDirection) ? 'PASS' : 'FAIL';
133 appendResult(description, result);
134 }
135
136 verifyDrawText('canvas1', 'result1', 'Left-to-Right text', 'ltr');
137 verifyDrawText('canvas2', 'result2', 'Right-to-Left text', 'rtl');
138
139 verifyDrawTextWithSpecifiedDirection('canvas3', 'result3', 'Right-to-Left text', 'rtl', 'rtl');
140 verifyDrawTextWithSpecifiedDirection('canvas4', 'result4', 'Left-to-Right text', 'ltr', 'ltr');
141 verifyDrawTextWithSpecifiedDirection('canvas5', 'result5', 'Left-to-Right text', 'inherit', 'ltr');
142 verifyDrawTextWithSpecifiedDirection('canvas6', 'result6', 'Right-to-Left text', 'inherit', 'rtl');
143
144 verifyDirectionAfterReset('canvas7', 'Right-to-Left', 'rtl', 'ltr');
145 verifyDirectionAfterReset('canvas8', 'Right-to-Left', 'ltr', 'rtl');
146
147 verifyInvalidDirection('RTL');
148 verifyInvalidDirection('LTR');
149 verifyInvalidDirection('INHERIT');
150 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698