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

Side by Side Diff: LayoutTests/imported/csswg-test/css-writing-modes-3/support/text-orientation/text-orientation.js

Issue 1161223002: Import csswg-test/css-writing-modes-3/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comments updated Created 5 years, 6 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 (function () {
2 function OrientationTester(container, orientation) {
3 this.container = container;
4 this.setOrientation(orientation);
5 }
6 extend(OrientationTester.prototype, {
7 setOrientation: function (orientation) {
8 this.orientation = orientation;
9 },
10 measure: function (results) {
11 this.results = results;
12 this._measureNode(this.container);
13 },
14 _measureNode: function (node) {
15 switch (node.nodeType) {
16 case Node.ELEMENT_NODE:
17 var nodes = node.childNodes;
18 for (var i = 0; i < nodes.length; i++)
19 this._measureNode(nodes[i]);
20 return;
21 case Node.TEXT_NODE:
22 break;
23 default:
24 return;
25 }
26
27 if (this.orientation == "R") {
28 var advanceExpected = 8;
29 var advanceFailed = 4;
30 } else {
31 advanceExpected = 4;
32 advanceFailed = 8;
33 }
34
35 var range = document.createRange();
36 var text = node.textContent;
37 for (var ich = 0; ich < text.length; ich++) {
38 var code = text.charCodeAt(ich);
39 if (code == 10 || code == 13)
40 continue;
41 range.setStart(node, ich);
42 if (code >= 0xD800 && code <= 0xDBFF) {
43 var next = text.charCodeAt(ich+1);
44 if (next >= 0xDC00 && next <= 0xDFFF) {
45 ich++;
46 code = ((code & 0x3FF) << 10) + (next & 0x3FF) + 0x10000 ;
47 }
48 }
49 range.setEnd(node, ich + 1);
50 rect = range.getBoundingClientRect();
51 if (rect.width == 16) {
52 if (rect.height == advanceExpected) {
53 this.results.passCount++;
54 continue;
55 }
56 //log("U+" + stringFromUnicode(code) + " " + rect.width + "x " + rect.height);
57 if (rect.height == advanceFailed) {
58 this.results.failed(this, code);
59 continue;
60 }
61 }
62 this.results.inconclusive(this, code, rect);
63 }
64 }});
65
66 function Results(name) {
67 var block = document.createElement("details");
68 this.summary = appendChildElement(block, "summary");
69 this.summary.textContent = name;
70 var typeList = appendChildElement(block, "ul");
71 this.failList = appendChildElement(appendChildElement(typeList, "li", "F ailures"), "ol");
72 this.inconclusiveList = appendChildElement(appendChildElement(typeList, "li", "Inconclusives"), "ol");
73 details.appendChild(block);
74 this.passCount = 0;
75 this.failCount = 0;
76 this.inconclusiveCount = 0;
77 }
78 extend(Results.prototype, {
79 failed: function (test, code) {
80 this.failCount++;
81 this.append(this.failList, test, code);
82 },
83 inconclusive: function (test, code, rect) {
84 this.inconclusiveCount++;
85 this.append(this.inconclusiveList, test, code, " but inconclusive (r endered as " + rect.width + "x" + rect.height + ")");
86 },
87 append: function (list, test, code, message) {
88 var text = stringFromUnicode(code) + " should be " + test.orientatio n;
89 if (message)
90 text += message;
91 appendChildElement(list, "li", text);
92 },
93 done: function (test) {
94 this.summary.textContent += " (" + this.passCount + " passes, " +
95 this.failCount + " fails, " +
96 this.inconclusiveCount + " inconclusives)";
97 assert_equals(this.failCount, 0, "Fail count");
98 assert_greater_than(this.passCount, 0, "Pass count");
99 test.done();
100 }});
101
102 function Runner() {
103 var nodes = document.querySelectorAll("div[data-vo]");
104 this.testers = [];
105 for (var i = 0; i < nodes.length; i++) {
106 var node = nodes[i];
107 var vo = node.dataset.vo;
108 var tester = new OrientationTester(node, vo);
109 tester.test = async_test("Default orientation for vo=" + vo);
110 this.testers.push(tester);
111 }
112 this.testU = async_test("Orientation=Upright");
113 this.testR = async_test("Orientation=Rotated");
114 }
115 extend(Runner.prototype, {
116 run: function () {
117 log("Started");
118 var start = new Date;
119
120 for (var i = 0; i < this.testers.length; i++) {
121 var tester = this.testers[i];
122 var test = tester.test;
123 test.step(function () {
124 var results = new Results(test.name);
125 tester.measure(results);
126 results.done(test);
127 });
128 }
129 this.runOrientation(this.testU, "U");
130 this.runOrientation(this.testR, "R");
131
132 log("Elapsed " + (new Date() - start));
133 done();
134 },
135 runOrientation: function (test, orientation) {
136 container.classList.add(orientation);
137 var results = new Results(test.name);
138 var me = this;
139 test.step(function () {
140 for (var i = 0; i < me.testers.length; i++) {
141 var tester = me.testers[i];
142 tester.setOrientation(orientation);
143 tester.measure(results);
144 }
145 results.done(test);
146 })
147 container.classList.remove(orientation);
148 }});
149
150 setup({explicit_done:true, explicit_timeout:true});
151 var blocks = arrayFromRangesByValue(rangesByBlock);
152 var runner = new Runner();
153 window.onload = function () {
154 if (window.location.search == "?wait") {
155 log("Sleeping 5 secs for debug purpose");
156 return setTimeout(run, 5000);
157 }
158 run();
159 }
160
161 function run() {
162 onFontReady("16px orientation", function () { runner.run(); });
163 }
164
165 function onFontReady(font, func) {
166 log("Waiting test fonts to load");
167 if (document.fonts) {
168 if ('load' in document.fonts)
169 return document.fonts.load(font).then(func);
170 if ('ready' in document.fonts)
171 return document.fonts.ready.then(func);
172 }
173 document.offsetTop; // last resort to load @font-face
174 func();
175 }
176
177 function arrayFromRangesByValue(dict) {
178 var array = [];
179 for (var value in dict) {
180 var ranges = dict[value];
181 for (var i = 0; i < ranges.length; i += 2) {
182 var to = ranges[i+1];
183 for (var code = ranges[i]; code <= to; code++)
184 array[code] = value;
185 }
186 }
187 return array;
188 };
189
190 function stringFromUnicode(code) {
191 var hex = code.toString(16).toUpperCase();
192 if (hex.length < 4) {
193 hex = "0000" + hex;
194 hex = hex.substr(hex.length - 4);
195 }
196 return blocks[code] + ": " + hex + ' "' + String.fromCharCode(code) + '" ';
197 }
198
199 function appendChildElement(parent, tag, text) {
200 var node = document.createElement(tag);
201 if (text)
202 node.textContent = text;
203 parent.appendChild(node);
204 return node;
205 }
206
207 function extend(target, dict) {
208 for (var key in dict)
209 target[key] = dict[key];
210 }
211
212 function log(text) {
213 console.log(text);
214 }
215 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698