Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for DOMStringList #4534

Merged
merged 3 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<meta charset=utf-8>
<title>DOMStringList IDL tests</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/WebIDLParser.js></script>
<script src=/resources/idlharness.js></script>

<h1>DOMStringList IDL tests</h1>
<div id=log></div>

<script>
"use strict";
async_test(function(t) {
var request = new XMLHttpRequest();
request.open("GET", "domstringlist.idl");
request.send();
request.onload = t.step_func(function() {
var idlArray = new IdlArray();
var idls = request.responseText;

idlArray.add_idls(idls);

idlArray.add_objects({
DOMStringList: ['location.ancestorOrigins'],
});

idlArray.test();
t.done();
});
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

importScripts("/resources/testharness.js");
importScripts("/resources/WebIDLParser.js", "/resources/idlharness.js");

async_test(function(t) {
var request = new XMLHttpRequest();
request.open("GET", "domstringlist.idl");
request.send();
request.onload = t.step_func(function() {
var idlArray = new IdlArray();
var idls = request.responseText;

idlArray.add_idls(idls);

idlArray.add_objects({
DOMStringList: [],
});
idlArray.test();
t.done();
});
});

done();
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<title>DOMStringList</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

// Returns a promise that resolves to a DOMStringList with
// the requested entries. Relies on Indexed DB.
function createDOMStringList(entries) {
return new Promise((resolve, reject) => {
const dbname = String(self.location + Math.random());
const request = indexedDB.open(dbname);
request.onerror = () => reject(request.error);
request.onupgradeneeded = () => {
const db = request.result;
entries.forEach(entry => db.createObjectStore(entry));
const dsl = db.objectStoreNames;
resolve(dsl);
request.transaction.abort();
}
});
}

function dsl_test(entries, func, description) {
promise_test(t => createDOMStringList(entries).then(dsl => func(t, dsl)),
description);
}

dsl_test(['a', 'b', 'c'], (t, dsl) => {
assert_equals(dsl.length, 3, 'length attribute');
}, 'DOMStringList: length attribute');

dsl_test(['a', 'b', 'c'], (t, dsl) => {
assert_equals(dsl.item(0), 'a', 'item method');
assert_equals(dsl.item(1), 'b', 'item method');
assert_equals(dsl.item(2), 'c', 'item method');
assert_equals(dsl.item(3), null, 'item method out of range');
assert_equals(dsl.item(-1), null, 'item method out of range');
assert_throws(TypeError(), () => dsl.item(),
'item method should throw if called without enough args');
}, 'DOMStringList: item() method');

dsl_test(['a', 'b', 'c'], (t, dsl) => {
assert_equals(dsl[0], 'a', 'indexed getter');
assert_equals(dsl[1], 'b', 'indexed getter');
assert_equals(dsl[2], 'c', 'indexed getter');
assert_equals(dsl[3], undefined, 'indexed getter out of range');
assert_equals(dsl[-1], undefined, 'indexed getter out of range');
}, 'DOMStringList: indexed getter');

dsl_test(['a', 'b', 'c'], (t, dsl) => {
assert_true(dsl.contains('a'), 'contains method matched');
assert_true(dsl.contains('b'), 'contains method matched');
assert_true(dsl.contains('c'), 'contains method matched');
assert_false(dsl.contains(''), 'contains method unmatched');
assert_false(dsl.contains('d'), 'contains method unmatched');
assert_throws(TypeError(), () => dsl.contains(),
'contains method should throw if called without enough args');
}, 'DOMStringList: contains() method');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Exposed=(Window,Worker)]
interface DOMStringList {
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);
boolean contains(DOMString string);
};