OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML> | |
2 <html> | |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 <p id="description"></p> | |
8 <div id="console"></div> | |
9 <script> | |
10 description('Test for .text for OPTION element'); | |
11 | |
12 // See http://www.whatwg.org/specs/web-apps/current-work/multipage/common-micros
yntaxes.html#space-character | |
13 var HTMLSpaces = [ | |
14 String.fromCharCode(0x20), | |
15 String.fromCharCode(0x09), | |
16 String.fromCharCode(0x0A), | |
17 String.fromCharCode(0x0C), | |
18 String.fromCharCode(0x0D) | |
19 ]; | |
20 | |
21 // Unicode white spaces which are not handled as white space | |
22 // when removing spaces on option element. | |
23 // These are taken from Unicode PropList.txt | |
24 var nonHTMLSpaces = [ | |
25 String.fromCharCode(0x0B), | |
26 String.fromCharCode(0x85), | |
27 String.fromCharCode(0xA0), | |
28 String.fromCharCode(0x1680), | |
29 String.fromCharCode(0x180E), | |
30 String.fromCharCode(0x2000), | |
31 String.fromCharCode(0x2001), | |
32 String.fromCharCode(0x2002), | |
33 String.fromCharCode(0x2003), | |
34 String.fromCharCode(0x2004), | |
35 String.fromCharCode(0x2005), | |
36 String.fromCharCode(0x2006), | |
37 String.fromCharCode(0x2007), | |
38 String.fromCharCode(0x2008), | |
39 String.fromCharCode(0x2009), | |
40 String.fromCharCode(0x200A), | |
41 String.fromCharCode(0x2028), | |
42 String.fromCharCode(0x2029), | |
43 String.fromCharCode(0x202F), | |
44 String.fromCharCode(0x205F), | |
45 String.fromCharCode(0x3000) | |
46 ]; | |
47 | |
48 var parent = document.createElement('div'); | |
49 document.body.appendChild(parent); | |
50 parent.innerHTML = '<select><option id=option></option></select>'; | |
51 | |
52 var option = document.getElementById('option'); | |
53 | |
54 var expected; | |
55 | |
56 debug('Insert one HTMLspace before/after/between the text'); | |
57 for (var i = 0; i < HTMLSpaces.length; ++i) { | |
58 option.text = HTMLSpaces[i] + 'text' + HTMLSpaces[i] + 'text' + HTMLSpaces[i
]; | |
59 expected = 'text text'; | |
60 shouldBe('option.text', 'expected'); | |
61 } | |
62 debug(''); | |
63 | |
64 debug('Insert multiple HTMLspaces before/after/between the text'); | |
65 for (var i = 0; i < HTMLSpaces.length; ++i) { | |
66 for (var j = 0; j < HTMLSpaces.length; ++j) { | |
67 option.text = HTMLSpaces[i] + HTMLSpaces[j] + 'text' + HTMLSpaces[i] + H
TMLSpaces[j] + 'text' + HTMLSpaces[i] + HTMLSpaces[j]; | |
68 expected = 'text text'; | |
69 shouldBe('option.text', 'expected'); | |
70 } | |
71 } | |
72 debug(''); | |
73 | |
74 debug(''); | |
75 | |
76 debug('Insert one nonHTMLspace before/after/between the text'); | |
77 for (var i = 0; i < nonHTMLSpaces.length; ++i) { | |
78 option.text = nonHTMLSpaces[i] + 'text' + nonHTMLSpaces[i] + 'text' + nonHTM
LSpaces[i]; | |
79 expected = nonHTMLSpaces[i] + 'text' + nonHTMLSpaces[i] + 'text' + nonHTMLSp
aces[i]; | |
80 shouldBe('option.text', 'expected'); | |
81 } | |
82 debug(''); | |
83 | |
84 debug('Insert multiple nonHTMLspaces before/after/between the text'); | |
85 for (var i = 0; i < nonHTMLSpaces.length; ++i) { | |
86 for (var j = 0; j < nonHTMLSpaces.length; ++j) { | |
87 option.text = nonHTMLSpaces[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpac
es[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[i] + nonHTMLSpaces[j]; | |
88 expected = nonHTMLSpaces[i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[
i] + nonHTMLSpaces[j] + 'text' + nonHTMLSpaces[i] + nonHTMLSpaces[j]; | |
89 shouldBe('option.text', 'expected'); | |
90 } | |
91 } | |
92 debug(''); | |
93 </script> | |
94 | |
95 </body> | |
96 </html> | |
OLD | NEW |