OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
3 <script> | 3 <script> |
4 description('IDL dictionary unittest'); | 4 description('IDL dictionary unittest'); |
5 | 5 |
6 var testObject1 = { foo: 'x' }; | 6 var testObject1 = { foo: 'x' }; |
7 var testObject2 = { bar: 'y' }; | 7 var testObject2 = { bar: 'y' }; |
8 | 8 |
9 if (window.internals && internals.dictionaryTest) { | 9 if (window.internals && internals.dictionaryTest) { |
10 var dictionaryTest = window.internals.dictionaryTest(); | 10 var dictionaryTest = window.internals.dictionaryTest(); |
11 | 11 |
12 debug('Test for setting an empty dictionary'); | 12 debug('Test for setting an empty dictionary'); |
13 dictionaryTest.set({}); | 13 dictionaryTest.set({}); |
14 dict = dictionaryTest.get(); | 14 dict = dictionaryTest.get(); |
15 shouldBeUndefined('dict.longMember'); | 15 shouldBeUndefined('dict.longMember'); |
16 shouldBe('dict.longMemberWithDefault', '42'); | 16 shouldBe('dict.longMemberWithDefault', '42'); |
17 shouldBeUndefined('dict.longOrNullMember'); | 17 shouldBeUndefined('dict.longOrNullMember'); |
18 shouldBeNull('dict.longOrNullMemberWithDefault'); | 18 shouldBeNull('dict.longOrNullMemberWithDefault'); |
19 shouldBeUndefined('dict.booleanMember'); | 19 shouldBeUndefined('dict.booleanMember'); |
20 shouldBeUndefined('dict.doubleMember'); | 20 shouldBeUndefined('dict.doubleMember'); |
| 21 shouldBeUndefined('dict.unrestrictedDoubleMember'); |
21 shouldBeUndefined('dict.stringMember'); | 22 shouldBeUndefined('dict.stringMember'); |
22 shouldBeEqualToString('dict.stringMemberWithDefault', 'defaultStringValue'); | 23 shouldBeEqualToString('dict.stringMemberWithDefault', 'defaultStringValue'); |
23 shouldBeUndefined('dict.byteStringMember'); | 24 shouldBeUndefined('dict.byteStringMember'); |
24 shouldBeUndefined('dict.usvStringMember'); | 25 shouldBeUndefined('dict.usvStringMember'); |
25 shouldBeUndefined('dict.stringSequenceMember'); | 26 shouldBeUndefined('dict.stringSequenceMember'); |
26 shouldBeUndefined('dict.stringSequenceOrNullMember'); | 27 shouldBeUndefined('dict.stringSequenceOrNullMember'); |
27 shouldBeUndefined('dict.elementMember'); | 28 shouldBeUndefined('dict.elementMember'); |
28 shouldBeUndefined('dict.elementOrNullMember'); | 29 shouldBeUndefined('dict.elementOrNullMember'); |
29 shouldBeUndefined('dict.enumMember'); | 30 shouldBeUndefined('dict.enumMember'); |
30 shouldBeEqualToString('dict.enumMemberWithDefault', 'foo'); | 31 shouldBeEqualToString('dict.enumMemberWithDefault', 'foo'); |
31 shouldBeUndefined('dict.enumOrNullMember'); | 32 shouldBeUndefined('dict.enumOrNullMember'); |
32 shouldBeUndefined('dict.objectMember'); | 33 shouldBeUndefined('dict.objectMember'); |
33 shouldBeNull('dict.objectOrNullMemberWithDefault'); | 34 shouldBeNull('dict.objectOrNullMemberWithDefault'); |
34 shouldBeUndefined('dict.doubleOrStringMember'); | 35 shouldBeUndefined('dict.doubleOrStringMember'); |
35 shouldBeNull('dict.eventTargetOrNullMember'); | 36 shouldBeNull('dict.eventTargetOrNullMember'); |
36 debug(''); | 37 debug(''); |
37 | 38 |
38 debug('Test for setting undefined'); | 39 debug('Test for setting undefined'); |
39 dictionaryTest.set(undefined); | 40 dictionaryTest.set(undefined); |
40 dict = dictionaryTest.get(); | 41 dict = dictionaryTest.get(); |
41 shouldBeUndefined('dict.longMember'); | 42 shouldBeUndefined('dict.longMember'); |
42 shouldBe('dict.longMemberWithDefault', '42'); | 43 shouldBe('dict.longMemberWithDefault', '42'); |
43 shouldBeUndefined('dict.longOrNullMember'); | 44 shouldBeUndefined('dict.longOrNullMember'); |
44 shouldBeNull('dict.longOrNullMemberWithDefault'); | 45 shouldBeNull('dict.longOrNullMemberWithDefault'); |
45 shouldBeUndefined('dict.booleanMember'); | 46 shouldBeUndefined('dict.booleanMember'); |
46 shouldBeUndefined('dict.doubleMember'); | 47 shouldBeUndefined('dict.doubleMember'); |
| 48 shouldBeUndefined('dict.unrestrictedDoubleMember'); |
47 shouldBeUndefined('dict.stringMember'); | 49 shouldBeUndefined('dict.stringMember'); |
48 shouldBeUndefined('dict.byteStringMember'); | 50 shouldBeUndefined('dict.byteStringMember'); |
49 shouldBeUndefined('dict.usvStringMember'); | 51 shouldBeUndefined('dict.usvStringMember'); |
50 shouldBeEqualToString('dict.stringMemberWithDefault', 'defaultStringValue'); | 52 shouldBeEqualToString('dict.stringMemberWithDefault', 'defaultStringValue'); |
51 shouldBeUndefined('dict.stringSequenceMember'); | 53 shouldBeUndefined('dict.stringSequenceMember'); |
52 shouldBeUndefined('dict.stringSequenceOrNullMember'); | 54 shouldBeUndefined('dict.stringSequenceOrNullMember'); |
53 shouldBeUndefined('dict.elementMember'); | 55 shouldBeUndefined('dict.elementMember'); |
54 shouldBeUndefined('dict.elementOrNullMember'); | 56 shouldBeUndefined('dict.elementOrNullMember'); |
55 shouldBeUndefined('dict.objectMember'); | 57 shouldBeUndefined('dict.objectMember'); |
56 shouldBeNull('dict.objectOrNullMemberWithDefault'); | 58 shouldBeNull('dict.objectOrNullMemberWithDefault'); |
57 shouldBeNull('dict.eventTargetOrNullMember'); | 59 shouldBeNull('dict.eventTargetOrNullMember'); |
58 debug(''); | 60 debug(''); |
59 | 61 |
60 var element1 = document.createElement('div'); | 62 var element1 = document.createElement('div'); |
61 | 63 |
62 debug('Test for setting valid values'); | 64 debug('Test for setting valid values'); |
63 dictionaryTest.set({ | 65 dictionaryTest.set({ |
64 longMember: 1, | 66 longMember: 1, |
65 longMemberWithDefault: 2, | 67 longMemberWithDefault: 2, |
66 longOrNullMember: 3, | 68 longOrNullMember: 3, |
67 longOrNullMemberWithDefault: 4, | 69 longOrNullMemberWithDefault: 4, |
68 stringMember: 'modifiedString1', | 70 stringMember: 'modifiedString1', |
69 stringMemberWithDefault: 'modifiedString2', | 71 stringMemberWithDefault: 'modifiedString2', |
70 byteStringMember: '\x00\x01\xFE\xFF', | 72 byteStringMember: '\x00\x01\xFE\xFF', |
71 usvStringMember: '!@#123ABCabc\xA0\uD800\uDC00', | 73 usvStringMember: '!@#123ABCabc\xA0\uD800\uDC00', |
72 booleanMember: true, | 74 booleanMember: true, |
73 doubleMember: 3.14, | 75 doubleMember: 3.14, |
| 76 unrestrictedDoubleMember: NaN, |
74 stringSequenceMember: ['foo', 'bar', 'baz'], | 77 stringSequenceMember: ['foo', 'bar', 'baz'], |
75 stringSequenceOrNullMember: [], | 78 stringSequenceOrNullMember: [], |
76 elementMember: element1, | 79 elementMember: element1, |
77 elementOrNullMember: null, | 80 elementOrNullMember: null, |
78 enumMember: 'foo', | 81 enumMember: 'foo', |
79 enumMemberWithDefault: 'bar', | 82 enumMemberWithDefault: 'bar', |
80 enumOrNullMember: 'baz', | 83 enumOrNullMember: 'baz', |
81 objectMember: testObject1, | 84 objectMember: testObject1, |
82 objectOrNullMemberWithDefault: testObject2, | 85 objectOrNullMemberWithDefault: testObject2, |
83 doubleOrStringMember: 3.14, | 86 doubleOrStringMember: 3.14, |
84 eventTargetOrNullMember: element1 | 87 eventTargetOrNullMember: element1 |
85 }); | 88 }); |
86 dict = dictionaryTest.get(); | 89 dict = dictionaryTest.get(); |
87 shouldBe('dict.longMember', '1'); | 90 shouldBe('dict.longMember', '1'); |
88 shouldBe('dict.longMemberWithDefault', '2'); | 91 shouldBe('dict.longMemberWithDefault', '2'); |
89 shouldBe('dict.longOrNullMember', '3'); | 92 shouldBe('dict.longOrNullMember', '3'); |
90 shouldBe('dict.longOrNullMemberWithDefault', '4'); | 93 shouldBe('dict.longOrNullMemberWithDefault', '4'); |
91 shouldBeEqualToString('dict.stringMember', 'modifiedString1'); | 94 shouldBeEqualToString('dict.stringMember', 'modifiedString1'); |
92 shouldBeEqualToString('dict.stringMemberWithDefault', 'modifiedString2'); | 95 shouldBeEqualToString('dict.stringMemberWithDefault', 'modifiedString2'); |
93 shouldBeEqualToString('dict.byteStringMember', '\x00\x01\xFE\xFF'); | 96 shouldBeEqualToString('dict.byteStringMember', '\x00\x01\xFE\xFF'); |
94 shouldBeEqualToString('dict.usvStringMember', '!@#123ABCabc\xA0\uD800\uDC00'
); | 97 shouldBeEqualToString('dict.usvStringMember', '!@#123ABCabc\xA0\uD800\uDC00'
); |
95 shouldBeTrue('dict.booleanMember'); | 98 shouldBeTrue('dict.booleanMember'); |
96 shouldBe('dict.doubleMember', '3.14'); | 99 shouldBe('dict.doubleMember', '3.14'); |
| 100 shouldBe('dict.unrestrictedDoubleMember', 'NaN'); |
97 shouldBe('dict.stringSequenceMember', '["foo", "bar", "baz"]'); | 101 shouldBe('dict.stringSequenceMember', '["foo", "bar", "baz"]'); |
98 shouldBe('dict.stringSequenceOrNullMember', '[]'); | 102 shouldBe('dict.stringSequenceOrNullMember', '[]'); |
99 shouldBe('dict.elementMember', 'element1'); | 103 shouldBe('dict.elementMember', 'element1'); |
100 // This will be undefined as the spec says | 104 // This will be undefined as the spec says |
101 shouldBeUndefined('dict.elementOrNullMember'); | 105 shouldBeUndefined('dict.elementOrNullMember'); |
102 shouldBeEqualToString('dict.enumMember', 'foo'); | 106 shouldBeEqualToString('dict.enumMember', 'foo'); |
103 shouldBeEqualToString('dict.enumMemberWithDefault', 'bar'); | 107 shouldBeEqualToString('dict.enumMemberWithDefault', 'bar'); |
104 shouldBeEqualToString('dict.enumOrNullMember', 'baz'); | 108 shouldBeEqualToString('dict.enumOrNullMember', 'baz'); |
105 shouldBe('dict.objectMember', 'testObject1'); | 109 shouldBe('dict.objectMember', 'testObject1'); |
106 shouldBe('dict.objectOrNullMemberWithDefault', 'testObject2'); | 110 shouldBe('dict.objectOrNullMemberWithDefault', 'testObject2'); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Nullable and its default value is null | 157 // Nullable and its default value is null |
154 shouldBeNull('dict.longOrNullMemberWithDefault'); | 158 shouldBeNull('dict.longOrNullMemberWithDefault'); |
155 debug(''); | 159 debug(''); |
156 | 160 |
157 debug('Test for setting invalid member'); | 161 debug('Test for setting invalid member'); |
158 dictionaryTest.set({invalidMember: 'shouldNotBeSet'}); | 162 dictionaryTest.set({invalidMember: 'shouldNotBeSet'}); |
159 dict = dictionaryTest.get(); | 163 dict = dictionaryTest.get(); |
160 shouldBeUndefined('dict.invalidMember'); | 164 shouldBeUndefined('dict.invalidMember'); |
161 debug(''); | 165 debug(''); |
162 | 166 |
| 167 debug('Test for setting invalid double value'); |
| 168 shouldThrow("dictionaryTest.set({doubleMember: NaN})"); |
| 169 shouldThrow("dictionaryTest.set({doubleMember: Infinity})"); |
| 170 shouldThrow("dictionaryTest.set({doubleMember: -Infinity})"); |
| 171 shouldThrow("dictionaryTest.set({doubleMember: 'invalid'})"); |
| 172 debug(''); |
| 173 |
163 debug('Test for setting invalid ByteString value'); | 174 debug('Test for setting invalid ByteString value'); |
164 shouldThrow("dictionaryTest.set({byteStringMember: '\u0100'})"); | 175 shouldThrow("dictionaryTest.set({byteStringMember: '\u0100'})"); |
165 debug(''); | 176 debug(''); |
166 | 177 |
167 debug('Test for setting invalid USVString value'); | 178 debug('Test for setting invalid USVString value'); |
168 dictionaryTest.set({usvStringMember: '_\uDC00_\uD800_\uDC00\uD800_'}); | 179 dictionaryTest.set({usvStringMember: '_\uDC00_\uD800_\uDC00\uD800_'}); |
169 dict = dictionaryTest.get(); | 180 dict = dictionaryTest.get(); |
170 shouldBeEqualToString('dict.usvStringMember', '_\uFFFD_\uFFFD_\uFFFD\uFFFD_'
); | 181 shouldBeEqualToString('dict.usvStringMember', '_\uFFFD_\uFFFD_\uFFFD\uFFFD_'
); |
171 | 182 |
172 debug('Test for setting invalid enum value'); | 183 debug('Test for setting invalid enum value'); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 shouldBe('derived.longMember', '1'); | 277 shouldBe('derived.longMember', '1'); |
267 shouldBeEqualToString('derived.stringMemberWithDefault', 'modifiedString'); | 278 shouldBeEqualToString('derived.stringMemberWithDefault', 'modifiedString'); |
268 shouldBeEqualToString('derived.derivedStringMember', 'modifiedString2'); | 279 shouldBeEqualToString('derived.derivedStringMember', 'modifiedString2'); |
269 shouldBeEqualToString('derived.derivedStringMemberWithDefault', 'modifiedStr
ing3'); | 280 shouldBeEqualToString('derived.derivedStringMemberWithDefault', 'modifiedStr
ing3'); |
270 shouldBeUndefined('derived.invalidMember'); | 281 shouldBeUndefined('derived.invalidMember'); |
271 | 282 |
272 debug(''); | 283 debug(''); |
273 shouldThrow("dictionaryTest.setDerived({objectMember: 42})"); | 284 shouldThrow("dictionaryTest.setDerived({objectMember: 42})"); |
274 } | 285 } |
275 </script> | 286 </script> |
OLD | NEW |