-
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.
IDB WPTs: Extend several IDB WPTs to run on workers (Part 8)
This set of IndexedDB WPTs currently only run in a window environment. This change extends them to also run in dedicated, shared, and service worker environments. Bug: 41455766 Change-Id: I76a29b8b5a583f1bdbed2cba1c39981a05aedb48 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6222486 Reviewed-by: Steve Becker <[email protected]> Commit-Queue: Rahul Singh <[email protected]> Cr-Commit-Position: refs/heads/main@{#1415963}
- Loading branch information
1 parent
0d69262
commit ebccc9d
Showing
4 changed files
with
142 additions
and
171 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,51 @@ | ||
// META: title=IndexedDB: recursive value | ||
// META: global=window,worker | ||
// META: script=resources/support.js | ||
|
||
'use strict'; | ||
|
||
function recursive_value(desc, value) { | ||
let db; | ||
const t = async_test('Recursive value - ' + desc); | ||
|
||
createdb(t).onupgradeneeded = t.step_func((e) => { | ||
db = e.target.result; | ||
db.createObjectStore('store').add(value, 1); | ||
|
||
e.target.onsuccess = t.step_func((e) => { | ||
db.transaction('store', 'readonly') | ||
.objectStore('store') | ||
.get(1) | ||
.onsuccess = t.step_func((e) => { | ||
try { | ||
JSON.stringify(value); | ||
assert_unreached( | ||
'The test case is incorrect. It must provide a recursive value that JSON cannot stringify.'); | ||
} catch (e) { | ||
if (e.name == 'TypeError') { | ||
try { | ||
JSON.stringify(e.target.result); | ||
assert_unreached( | ||
'Expected a non-JSON-serializable value back, didn\'t get that.'); | ||
} catch (e) { | ||
t.done(); | ||
return; | ||
} | ||
} else | ||
throw e; | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
const recursive = []; | ||
recursive.push(recursive); | ||
recursive_value('array directly contains self', recursive); | ||
|
||
const recursive2 = []; | ||
recursive2.push([recursive2]); | ||
recursive_value('array indirectly contains self', recursive2); | ||
|
||
const recursive3 = [recursive]; | ||
recursive_value('array member contains self', recursive3); |
This file was deleted.
Oops, something went wrong.
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,91 @@ | ||
// META: title=IndexedDB writer starvation test | ||
// META: global=window,worker | ||
// META: script=resources/support.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
async_test(t => { | ||
let db; | ||
let read_request_count = 0; | ||
let read_success_count = 0; | ||
let write_request_count = 0; | ||
let write_success_count = 0; | ||
const RQ_COUNT = 25; | ||
|
||
const open_rq = createdb(t); | ||
open_rq.onupgradeneeded = t.step_func((e) => { | ||
db = e.target.result; | ||
db.createObjectStore('s').add('1', 1); | ||
}); | ||
|
||
open_rq.onsuccess = t.step_func((e) => { | ||
let i = 0; | ||
|
||
// Pre-fill some read requests. | ||
for (i = 0; i < RQ_COUNT; i++) { | ||
read_request_count++; | ||
|
||
db.transaction('s', 'readonly').objectStore('s').get(1).onsuccess = | ||
t.step_func((e) => { | ||
read_success_count++; | ||
assert_equals(e.target.transaction.mode, 'readonly'); | ||
}); | ||
} | ||
|
||
t.step(loop); | ||
|
||
function loop() { | ||
read_request_count++; | ||
|
||
db.transaction('s', 'readonly').objectStore('s').get(1).onsuccess = | ||
t.step_func((e) => { | ||
read_success_count++; | ||
assert_equals(e.target.transaction.mode, 'readonly'); | ||
|
||
if (read_success_count >= RQ_COUNT && write_request_count == 0) { | ||
write_request_count++; | ||
|
||
db.transaction('s', 'readwrite') | ||
.objectStore('s') | ||
.add('written', read_request_count) | ||
.onsuccess = t.step_func((e) => { | ||
write_success_count++; | ||
assert_equals(e.target.transaction.mode, 'readwrite'); | ||
assert_equals( | ||
e.target.result, read_success_count, | ||
'write cb came before later read cb\'s'); | ||
}); | ||
|
||
// Reads done after the write. | ||
for (i = 0; i < 5; i++) { | ||
read_request_count++; | ||
|
||
db.transaction('s', 'readonly') | ||
.objectStore('s') | ||
.get(1) | ||
.onsuccess = t.step_func((e) => { | ||
read_success_count++; | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
if (read_success_count < RQ_COUNT + 5) { | ||
step_timeout(t.step_func(loop), write_request_count ? 1000 : 100); | ||
} else { | ||
// This runs finish() once `read_success_count` >= RQ_COUNT + 5. | ||
db.transaction('s', 'readonly').objectStore('s').count().onsuccess = | ||
t.step_func(() => { | ||
step_timeout(t.step_func(finish), 100); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
function finish() { | ||
assert_equals(read_request_count, read_success_count, 'read counts'); | ||
assert_equals(write_request_count, write_success_count, 'write counts'); | ||
t.done(); | ||
} | ||
}, 'IDB read requests should not starve write requests'); |
This file was deleted.
Oops, something went wrong.