2 <title>DOMStringList interface
</title>
3 <script src=
"../../resources/testharness.js"></script>
4 <script src=
"../../resources/testharnessreport.js"></script>
7 // Returns a promise that will resolve to a DOMStringList.
8 // Strings must be unique, and the strings will be sorted.
9 function makeDOMStringList(entries
) {
10 return new Promise(function(resolve
, reject
) {
11 var dbname
= String(self
.location
);
12 var r
= indexedDB
.open(dbname
);
13 r
.onerror = function() { reject(r
.error
); };
14 r
.onupgradeneeded = function() {
16 entries
.forEach(function(entry
) {
17 db
.createObjectStore(entry
);
20 r
.onsuccess = function() {
22 var dsl
= db
.objectStoreNames
;
24 var r2
= indexedDB
.deleteDatabase(dbname
);
25 r2
.onerror = function() { reject(r2
.error
); };
26 r2
.onsuccess = function() { resolve(dsl
); };
31 promise_test(function(t
) {
32 return makeDOMStringList(['a', 'b', 'c'])
34 assert_equals(Object
.prototype.toString
.call(dsl
),
35 '[object DOMStringList]',
36 'Object should be branded as "DOMStringList"');
37 assert_true('length' in dsl
&& typeof dsl
.length
=== 'number',
38 'DOMStringList should have length attribute');
39 assert_true('item' in dsl
&& typeof dsl
.item
=== 'function',
40 'DOMStringList should have item method');
41 assert_true('contains' in dsl
&& typeof dsl
.contains
=== 'function',
42 'DOMStringList should have contains method');
44 assert_equals(dsl
.length
, 3, 'length attribute');
46 assert_equals(dsl
.item(0), 'a', 'item method');
47 assert_equals(dsl
.item(1), 'b', 'item method');
48 assert_equals(dsl
.item(2), 'c', 'item method');
49 assert_equals(dsl
.item(3), null, 'item method out of range');
51 {name
: 'TypeError'}, function() { dsl
.item(); },
52 'item method should throw if called without enough args');
54 assert_equals(dsl
[0], 'a', 'indexed getter');
55 assert_equals(dsl
[1], 'b', 'indexed getter');
56 assert_equals(dsl
[2], 'c', 'indexed getter');
57 assert_equals(dsl
[3], undefined, 'indexed getter out of range');
59 assert_true(dsl
.contains('a'),
60 'contains method matched');
61 assert_true(dsl
.contains('b'),
62 'contains method matched');
63 assert_true(dsl
.contains('c'),
64 'contains method matched');
65 assert_false(dsl
.contains(''),
66 'contains method unmatched');
67 assert_false(dsl
.contains('d'),
68 'contains method unmatched');
70 {name
: 'TypeError'}, function(){ dsl
.contains(); },
71 'contains method should throw if called without enough args');
73 }, 'DOMStringList interface');