-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[presentation-api] Stop using EventWatcher for IndexedDB #9046
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ | |
modal.textContent = 'confirm()'; | ||
confirm(message); | ||
modal.textContent = 'print()'; | ||
//print(); | ||
print(); | ||
modal.textContent = 'prompt()'; | ||
prompt(message); | ||
notice.style.display = 'none'; | ||
|
@@ -61,31 +61,43 @@ | |
|
||
// Indexed Database | ||
let db; | ||
const storeName = 'store-controlling-ua'; | ||
const checkIndexedDB = () => { | ||
if ('indexedDB' in window) { | ||
message = 'Indexed Database is shared by top-level and nested browsing contexts.'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this required by same-origin policy? Do we need to test this here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The intention of this is to check if both top-level and nested browsing contexts share the same storage, according to the following spec described in Creating a receiving browsing context:
|
||
let req = indexedDB.open('db-presentation-api', 1), store; | ||
let eventWatcher = new EventWatcher(t, req, 'success'); | ||
return eventWatcher.wait_for('success').then(() => { | ||
db = req.result; | ||
const transaction = db.transaction('store-controlling-ua', 'readwrite'); | ||
store = transaction.objectStore('store-controlling-ua'); | ||
req = store.openCursor(); | ||
eventWatcher = new EventWatcher(t, req, 'success'); | ||
return eventWatcher.wait_for('success'); | ||
}).then(() => { | ||
assert_true(req.result instanceof IDBCursorWithValue, message); | ||
const cursor = req.result; | ||
const item = cursor.value; | ||
return new Promise((resolve, reject) => { | ||
req.onsuccess = () => { | ||
let results = []; | ||
db = req.result; | ||
const transaction = db.transaction(storeName, 'readwrite'); | ||
store = transaction.objectStore(storeName); | ||
req = store.openCursor(); | ||
req.onsuccess = () => { | ||
if (req.result) { | ||
const item = req.result.value; | ||
results.push(item); | ||
req.result.continue(); | ||
} | ||
else | ||
resolve(results); | ||
}; | ||
req.onerror = reject; | ||
}; | ||
req.onerror = reject; | ||
}).then(results => { | ||
assert_equals(results.length, 1, message); | ||
const item = results[0]; | ||
assert_equals(item.id, 'parent', message); | ||
assert_equals(item.data, 'receiving user agent', message); | ||
cursor.continue(); | ||
return eventWatcher.wait_for('success'); | ||
}).then(() => { | ||
assert_equals(req.result, null, message); | ||
req = store.put({ id: 'child', data: 'nested browsing context' }); | ||
eventWatcher = new EventWatcher(t, req, 'success'); | ||
return eventWatcher.wait_for('success'); | ||
|
||
return new Promise((resolve, reject) => { | ||
const transaction = db.transaction(storeName, 'readwrite'); | ||
store = transaction.objectStore(storeName); | ||
req = store.put({ id: 'child', data: 'nested browsing context' }); | ||
req.onsuccess = resolve; | ||
req.onerror = reject; | ||
}); | ||
}).then(() => { | ||
db.close(); | ||
db = null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the IndexedDB spec, you can test for existence of a database by a non-empty version property on the result object.
https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase
Perhaps the test would be simpler by just checking whether a database already exists (thus indicating whether the database was leaked across receiving browsing contexts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. Regarding IndexedDB, we can simply check version of a database. I'll simplify and submit these codes later.
BTW, I'm afraid that the MDN article might be incorrect. With regard to
indexedDB.open
, the IndexedDB spec says:Anyway, we can still check whether the database has been previously created or not by looking at version of the database.