Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>OffscreenCanvas test: 2d.text.measure.selection-rects-exceptions.tentative</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<h1>2d.text.measure.selection-rects-exceptions.tentative</h1>
<p class="desc">Check that TextMetrics::getSelectionRects() throws when using invalid indexes.</p>
<script>
var t = async_test("Check that TextMetrics::getSelectionRects() throws when using invalid indexes.");
var t_pass = t.done.bind(t);
var t_fail = t.step_func(function(reason) {
throw reason;
});
t.step(function() {
var canvas = new OffscreenCanvas(100, 50);
var ctx = canvas.getContext('2d');
const kTexts = [
'UNAVAILABLE',
'🏁🎶🏁',
')(あ)(',
'-abcd_',
'اين المكتبة؟',
'bidiالرياضيات'
]
for (const text of kTexts) {
const tm = ctx.measureText(text);
// Handled by the IDL binding.
assert_throws_js(TypeError, () => tm.getSelectionRects(-1, 0) );
assert_throws_js(TypeError, () => tm.getSelectionRects(0, -1) );
assert_throws_js(TypeError, () => tm.getSelectionRects(-1, -1) );
// Thrown in TextMetrics.
assert_throws_dom("IndexSizeError",
() => tm.getSelectionRects(text.length + 1, 0) );
assert_throws_dom("IndexSizeError",
() => tm.getSelectionRects(0, text.length + 1) );
assert_throws_dom("IndexSizeError",
() => tm.getSelectionRects(text.length + 1, text.length + 1) );
}
t.done();
});
</script>