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

Upstream an assortment of IndexedDB tests to WPT. #4659

Merged
merged 1 commit into from Jan 31, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions IndexedDB/error-attributes.html
@@ -0,0 +1,38 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: Error attributes are DOMExceptions</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#idbrequest">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
function(t, db) {
db.createObjectStore('store');
},
function(t, db) {
var tx = db.transaction('store', 'readwrite');
var store = tx.objectStore('store');
var r1 = store.add('value', 'key');
r1.onerror = t.unreached_func('first add should succeed');

var r2 = store.add('value', 'key');
r2.onsuccess = t.unreached_func('second add should fail');

r2.onerror = t.step_func(function() {
assert_true(r2.error instanceof DOMException);
assert_equals(r2.error.name, 'ConstraintError');
});

tx.oncomplete = t.unreached_func('transaction should not complete');
tx.onabort = t.step_func(function() {
assert_true(tx.error instanceof DOMException);
assert_equals(tx.error.name, 'ConstraintError');
t.done();
});
},
'IDBRequest and IDBTransaction error properties should be DOMExceptions'
);

</script>
91 changes: 91 additions & 0 deletions IndexedDB/idbcursor-advance-exception-order.html
@@ -0,0 +1,91 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBCursor advance() Exception Ordering</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#dom-idbcursor-advance">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('s');
store.put('value', 'key');
},
(t, db) => {
const tx = db.transaction('s');
const store = tx.objectStore('s');

const r = store.openKeyCursor();
r.onsuccess = t.step_func(() => {
r.onsuccess = null;

const cursor = r.result;

setTimeout(t.step_func(() => {
assert_throws(new TypeError, () => { cursor.advance(0); },
'"zero" check (TypeError) should precede ' +
'"not active" check (TransactionInactiveError)');
t.done();
}), 0);
});
},
'IDBCursor.advance exception order: TypeError vs. TransactionInactiveError'
);

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('s');

const s = db.createObjectStore('s2');
s.put('value', 'key');

const r = s.openKeyCursor();
r.onsuccess = t.step_func(() => {
r.onsuccess = null;

const cursor = r.result;
db.deleteObjectStore('s2');

setTimeout(t.step_func(() => {
assert_throws('TransactionInactiveError', () => { cursor.advance(1); },
'"not active" check (TransactionInactiveError) ' +
'should precede "deleted" check (InvalidStateError)');
t.done();
}), 0);
});
},
(t, db) => {},
'IDBCursor.advance exception order: ' +
'TransactionInactiveError vs. InvalidStateError #1'
);

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('s');
store.put('value', 'key');
},
(t, db) => {
const tx = db.transaction('s');
const store = tx.objectStore('s');

const r = store.openKeyCursor();
r.onsuccess = t.step_func(() => {
r.onsuccess = null;

const cursor = r.result;
cursor.advance(1);

setTimeout(t.step_func(() => {
assert_throws('TransactionInactiveError', () => { cursor.advance(1); },
'"not active" check (TransactionInactiveError) ' +
'should precede "got value" check (InvalidStateError)');
t.done();
}), 0);
});
},
'IDBCursor.advance exception order: ' +
'TransactionInactiveError vs. InvalidStateError #2'
);

</script>
27 changes: 27 additions & 0 deletions IndexedDB/idbindex-getAll-enforcerange.html
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBIndex getAll() uses [EnforceRange]</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#index-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('store');
const index = store.createIndex('index', 'keyPath');
},
(t, db) => {
const tx = db.transaction('store');
const store = tx.objectStore('store');
const index = store.index('index');
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => {
assert_throws(TypeError(), () => { index.getAll(null, count); },
`getAll with count ${count} count should throw TypeError`);
});
t.done();
},
`IDBIndex.getAll() uses [EnforceRange]`
);
</script>
27 changes: 27 additions & 0 deletions IndexedDB/idbindex-getAllKeys-enforcerange.html
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBIndex getAllKeys() uses [EnforceRange]</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#index-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('store');
const index = store.createIndex('index', 'keyPath');
},
(t, db) => {
const tx = db.transaction('store');
const store = tx.objectStore('store');
const index = store.index('index');
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => {
assert_throws(TypeError(), () => { index.getAllKeys(null, count); },
`getAllKeys with count ${count} count should throw TypeError`);
});
t.done();
},
`IDBIndex.getAllKeys() uses [EnforceRange]`
);
</script>
25 changes: 25 additions & 0 deletions IndexedDB/idbobjectstore-getAll-enforcerange.html
@@ -0,0 +1,25 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBObjectStore getAll() uses [EnforceRange]</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#object-store-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('store');
},
(t, db) => {
const tx = db.transaction('store');
const store = tx.objectStore('store');
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => {
assert_throws(TypeError(), () => { store.getAll(null, count); },
`getAll with count ${count} count should throw TypeError`);
});
t.done();
},
`IDBObjectStore.getAll() uses [EnforceRange]`
);
</script>
25 changes: 25 additions & 0 deletions IndexedDB/idbobjectstore-getAllKeys-enforcerange.html
@@ -0,0 +1,25 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: IDBIObjectStore getAllKeys() uses [EnforceRange]</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#object-store-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

indexeddb_test(
(t, db) => {
const store = db.createObjectStore('store');
},
(t, db) => {
const tx = db.transaction('store');
const store = tx.objectStore('store');
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => {
assert_throws(TypeError(), () => { store.getAllKeys(null, count); },
`getAllKeys with count ${count} count should throw TypeError`);
});
t.done();
},
`IDBObjectStore.getAllKeys() uses [EnforceRange]`
);
</script>
63 changes: 63 additions & 0 deletions IndexedDB/open-request-queue.html
@@ -0,0 +1,63 @@
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: open and delete requests are processed as a FIFO queue</title>
<link rel="help" href="https://w3c.github.io/IndexedDB/#request-connection-queue">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>

async_test(t => {
let db_name = 'db' + self.location.pathname + '-' + t.name;
indexedDB.deleteDatabase(db_name);

// Open and hold connection while other requests are queued up.
let r = indexedDB.open(db_name, 1);
r.onerror = t.unreached_func('open should succeed');
r.onsuccess = t.step_func(e => {
let db = r.result;

let saw = expect(t, [
'open1 success',
'open1 versionchange',
'delete1 blocked',
'delete1 success',
'open2 success',
'open2 versionchange',
'delete2 blocked',
'delete2 success'
]);

function open(token, version) {
let r = indexedDB.open(db_name, version);
r.onsuccess = t.step_func(e => {
saw(token + ' success');
let db = r.result;
db.onversionchange = t.step_func(e => {
saw(token + ' versionchange');
setTimeout(t.step_func(() => db.close()), 0);
});
});
r.onblocked = t.step_func(e => saw(token + ' blocked'));
r.onerror = t.unreached_func('open should succeed');
}

function deleteDatabase(token) {
let r = indexedDB.deleteDatabase(db_name);
r.onsuccess = t.step_func(e => saw(token + ' success'));
r.onblocked = t.step_func(e => saw(token + ' blocked'));
r.onerror = t.unreached_func('deleteDatabase should succeed');
}

open('open1', 2);
deleteDatabase('delete1');
open('open2', 3);
deleteDatabase('delete2');

// Now unblock the queue.
db.close();
});

}, 'Opens and deletes are processed in order');

</script>
15 changes: 15 additions & 0 deletions IndexedDB/support.js
Expand Up @@ -128,3 +128,18 @@ function indexeddb_test(upgrade_func, open_func, description, options) {
});
}, description);
}

// Call with a Test and an array of expected results in order. Returns
// a function; call the function when a result arrives and when the
// expected number appear the order will be asserted and test
// completed.
function expect(t, expected) {
var results = [];
return result => {
results.push(result);
if (results.length === expected.length) {
assert_array_equals(results, expected);
t.done();
}
};
}