98 lines
3.1 KiB
HTML
98 lines
3.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
</head>
|
|
<body>
|
|
<p id="description"></p>
|
|
<div id="console"></div>
|
|
<script>
|
|
description('Test for .text for OPTION element');
|
|
|
|
// See http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#space-character
|
|
var HTMLSpaces = [
|
|
String.fromCharCode(0x20),
|
|
String.fromCharCode(0x09),
|
|
String.fromCharCode(0x0A),
|
|
String.fromCharCode(0x0C),
|
|
String.fromCharCode(0x0D)
|
|
];
|
|
|
|
// Unicode white spaces which are not handled as white space
|
|
// when removing spaces on option element.
|
|
// These are taken from Unicode PropList.txt
|
|
var nonHTMLSpaces = [
|
|
String.fromCharCode(0x0B),
|
|
String.fromCharCode(0x85),
|
|
String.fromCharCode(0xA0),
|
|
String.fromCharCode(0x1680),
|
|
String.fromCharCode(0x180E),
|
|
String.fromCharCode(0x2000),
|
|
String.fromCharCode(0x2001),
|
|
String.fromCharCode(0x2002),
|
|
String.fromCharCode(0x2003),
|
|
String.fromCharCode(0x2004),
|
|
String.fromCharCode(0x2005),
|
|
String.fromCharCode(0x2006),
|
|
String.fromCharCode(0x2007),
|
|
String.fromCharCode(0x2008),
|
|
String.fromCharCode(0x2009),
|
|
String.fromCharCode(0x200A),
|
|
String.fromCharCode(0x2028),
|
|
String.fromCharCode(0x2029),
|
|
String.fromCharCode(0x202F),
|
|
String.fromCharCode(0x205F),
|
|
String.fromCharCode(0x3000)
|
|
];
|
|
|
|
var parent = document.createElement('div');
|
|
document.body.appendChild(parent);
|
|
parent.innerHTML = '<select><option id=option></option></select>';
|
|
|
|
var option = document.getElementById('option');
|
|
|
|
var expected;
|
|
|
|
debug('Insert one HTMLspace before/after/between the text');
|
|
for (var i = 0; i < HTMLSpaces.length; ++i) {
|
|
option.text = HTMLSpaces[i] + 'text' + HTMLSpaces[i] + 'text' + HTMLSpaces[i];
|
|
expected = 'text text';
|
|
shouldBe('option.text', 'expected');
|
|
}
|
|
debug('');
|
|
|
|
debug('Insert multiple HTMLspaces before/after/between the text');
|
|
for (var i = 0; i < HTMLSpaces.length; ++i) {
|
|
for (var j = 0; j < HTMLSpaces.length; ++j) {
|
|
option.text = HTMLSpaces[i] + HTMLSpaces[j] + 'text' + HTMLSpaces[i] + HTMLSpaces[j] + 'text' + HTMLSpaces[i] + HTMLSpaces[j];
|
|
expected = 'text text';
|
|
shouldBe('option.text', 'expected');
|
|
}
|
|
}
|
|
debug('');
|
|
|
|
debug('');
|
|
|
|
debug('Insert one nonHTMLspace before/after/between the text');
|
|
for (var i = 0; i < nonHTMLSpaces.length; ++i) {
|
|
option.text = nonHTMLSpaces[i] + 'text' + nonHTMLSpaces[i] + 'text' + nonHTMLSpaces[i];
|
|
expected = nonHTMLSpaces[i] + 'text' + nonHTMLSpaces[i] + 'text' + nonHTMLSpaces[i];
|
|
shouldBe('option.text', 'expected');
|
|
}
|
|
debug('');
|
|
|
|
debug('Insert multiple nonHTMLspaces before/after/between the text');
|
|
for (var i = 0; i < nonHTMLSpaces.length; ++i) {
|
|
for (var j = 0; j < nonHTMLSpaces.length; ++j) {
|
|
option.text = nonHTMLSpaces[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[i] + nonHTMLSpaces[j];
|
|
expected = nonHTMLSpaces[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[i] + nonHTMLSpaces[j];
|
|
shouldBe('option.text', 'expected');
|
|
}
|
|
}
|
|
debug('');
|
|
</script>
|
|
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
</body>
|
|
</html>
|