-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4691 from w3c/chromium-export-try
Upstream extra IndexedDB test cases into WPT.
- Loading branch information
Showing
2 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: 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> | ||
|
||
let saw; | ||
indexeddb_test( | ||
(t, db) => { | ||
saw = expect(t, ['delete1', 'delete2']); | ||
let r = indexedDB.deleteDatabase(db.name); | ||
r.onerror = t.unreached_func('delete should succeed'); | ||
r.onsuccess = t.step_func(e => saw('delete1')); | ||
}, | ||
(t, db) => { | ||
let r = indexedDB.deleteDatabase(db.name); | ||
r.onerror = t.unreached_func('delete should succeed'); | ||
r.onsuccess = t.step_func(e => saw('delete2')); | ||
|
||
db.close(); | ||
}, | ||
'Deletes are processed in order'); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: UpgradeNeeded Tests</title> | ||
<meta name="help" href="https://w3c.github.io/IndexedDB/#commit-transaction"> | ||
<meta name="help" href="https://w3c.github.io/IndexedDB/#dom-idbfactory-open"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
|
||
function upgradeneeded_test(upgrade_func, success_func, error_func, description) { | ||
async_test(function(t) { | ||
var dbName = 'db' + self.location.pathname + '-' + description; | ||
var delete_request = indexedDB.deleteDatabase(dbName); | ||
delete_request.onerror = t.unreached_func('deleteDatabase should not fail'); | ||
delete_request.onsuccess = t.step_func(function() { | ||
var open_request = indexedDB.open(dbName); | ||
|
||
open_request.onupgradeneeded = t.step_func(function() { | ||
upgrade_func(t, open_request); | ||
}); | ||
open_request.onsuccess = t.step_func(function() { | ||
success_func(t, open_request); | ||
}); | ||
if (error_func) { | ||
open_request.onerror = function() { error_func(t, open_request); }; | ||
} else { | ||
open_request.onerror = t.unreached_func('open failed'); | ||
} | ||
}); | ||
}, description); | ||
} | ||
|
||
(function() { | ||
var order = []; | ||
upgradeneeded_test( | ||
function upgrade(t, request) { | ||
order.push('Upgrade'); | ||
var db = request.result; | ||
var deleteRequest = indexedDB.deleteDatabase(db.name); | ||
deleteRequest.onsuccess = t.step_func(function() { | ||
assert_array_equals(order, ['Upgrade', 'Open Success']); | ||
t.done(); | ||
}); | ||
deleteRequest.onerror = t.unreached_func('delete failed'); | ||
}, | ||
function success(t, request) { | ||
var db = request.result; | ||
db.close(); | ||
order.push('Open Success'); | ||
}, | ||
null, | ||
'indexedDB.delete called from upgradeneeded handler' | ||
); | ||
}()); | ||
|
||
(function() { | ||
var order = []; | ||
upgradeneeded_test( | ||
function upgrade(t, request) { | ||
order.push('Upgrade'); | ||
request.transaction.abort(); | ||
order.push('Upgrade Transaction Aborted'); | ||
var db = request.result; | ||
var deleteRequest = indexedDB.deleteDatabase(db.name); | ||
deleteRequest.onsuccess = t.step_func(function() { | ||
assert_array_equals( | ||
order, ['Upgrade', 'Upgrade Transaction Aborted', 'Open Error']); | ||
t.done(); | ||
}); | ||
deleteRequest.onerror = t.unreached_func('delete failed'); | ||
}, | ||
function success(t, request) { | ||
t.unreached_func('open should not succeed'); | ||
}, | ||
function error_func(t, request) { | ||
assert_array_equals(order, ['Upgrade', 'Upgrade Transaction Aborted']); | ||
order.push('Open Error'); | ||
}, | ||
'Abort transaction before deleting database in upgradeneeded handler' | ||
); | ||
}()); | ||
|
||
(function() { | ||
var order = []; | ||
upgradeneeded_test( | ||
function upgrade(t, request) { | ||
order.push('Upgrade'); | ||
var db = request.result; | ||
var deleteRequest = indexedDB.deleteDatabase(db.name); | ||
request.transaction.abort(); | ||
order.push('Upgrade Transaction Aborted'); | ||
deleteRequest.onsuccess = t.step_func(function() { | ||
assert_array_equals( | ||
order, ['Upgrade', 'Upgrade Transaction Aborted', 'Open Error']); | ||
t.done(); | ||
}); | ||
deleteRequest.onerror = t.unreached_func('delete failed'); | ||
}, | ||
function success(t, request) { | ||
t.unreached_func('open should not succeed'); | ||
}, | ||
function error_func(t, request) { | ||
assert_array_equals(order, ['Upgrade', 'Upgrade Transaction Aborted']); | ||
order.push('Open Error'); | ||
}, | ||
'Abort transaction after deleting database in upgradeneeded event handler' | ||
); | ||
}()); | ||
|
||
(function() { | ||
var order = []; | ||
upgradeneeded_test( | ||
function upgrade(t, request) { | ||
order.push('Upgrade'); | ||
var db = request.result; | ||
db.createObjectStore('store'); | ||
request.transaction.oncomplete = t.step_func(function() { | ||
order.push('Upgrade transaction complete'); | ||
var txn = db.transaction('store', 'readwrite'); | ||
var store = txn.objectStore('store'); | ||
store.put('value', 'key'); | ||
txn.oncomplete = t.step_func(function() { | ||
assert_array_equals( | ||
order, | ||
['Upgrade', 'Upgrade transaction complete', 'Open Success']); | ||
t.done(); | ||
}); | ||
txn.onerror = t.unreached_func('error on transaction'); | ||
txn.onabort = t.unreached_func('aborting transaction'); | ||
}); | ||
}, | ||
function success(t, request) { | ||
order.push('Open Success'); | ||
}, | ||
null, | ||
'transaction oncomplete ordering relative to open request onsuccess' | ||
); | ||
}()); | ||
|
||
</script> |