Commit 4f032dd8 authored by Chase Phillips's avatar Chase Phillips Committed by Commit Bot

IndexedDB: Convert bindings-inject-key.html to promise-based

Update bindings-inject-key.html from an async test to promise-based.
This allows the test to run so that each subtest is run serially.

Patch by Joshua Bell <jsbell@chromium.org>.

Bug: 934844
Change-Id: If9834a35fcb964a6fe15776e3e091d326f3f8a0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504458Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Chase Phillips <cmp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638268}
parent 4e6251e4
...@@ -4,94 +4,69 @@ ...@@ -4,94 +4,69 @@
<meta name="help" href="https://w3c.github.io/IndexedDB/#inject-key-into-value"> <meta name="help" href="https://w3c.github.io/IndexedDB/#inject-key-into-value">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script> <script src="support-promises.js"></script>
<script> <script>
indexeddb_test( promise_test(async t => {
(t, db) => { const db = await createDatabase(t, db => {
db.createObjectStore('store'); db.createObjectStore('store');
}, });
(t, db) => {
const tx = db.transaction('store', 'readwrite');
const request = tx.objectStore('store').put(
'value', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'key']);
const setter_called = false; let setter_called = false;
Object.defineProperty(Object.prototype, '10', { Object.defineProperty(Object.prototype, '10', {
configurable: true, configurable: true,
set: t.step_func((value) => { setter_called = true; }), set: value => { setter_called = true; },
}); });
t.add_cleanup(function() { t.add_cleanup(() => { delete Object.prototype['10']; });
delete Object.prototype['10'];
}); const tx = db.transaction('store', 'readwrite');
request.onerror = t.unreached_func('request should not fail'); const result = await promiseForRequest(t, tx.objectStore('store').put(
request.onsuccess = t.step_func(() => { 'value', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'key']));
const result = request.result;
assert_false(setter_called, assert_false(setter_called,
'Setter should not be called for key result.'); 'Setter should not be called for key result.');
assert_true( assert_true(result.hasOwnProperty('10'),
result.hasOwnProperty('10'),
'Result should have own-property overriding prototype setter.'); 'Result should have own-property overriding prototype setter.');
assert_equals(result[10], 'key', assert_equals(result[10], 'key',
'Result should have expected property.'); 'Result should have expected property.');
t.done(); }, 'Returning keys to script should bypass prototype setters');
});
},
'Returning keys to script should bypass prototype setters'
);
indexeddb_test( promise_test(async t => {
(t, db) => { const db = await createDatabase(t, db => {
db.createObjectStore('store', {autoIncrement: true, keyPath: 'id'}); db.createObjectStore('store', {autoIncrement: true, keyPath: 'id'});
}, });
(t, db) => {
const tx = db.transaction('store', 'readwrite');
tx.objectStore('store').put({});
const request = tx.objectStore('store').get(1);
const setter_called = false; let setter_called = false;
Object.defineProperty(Object.prototype, 'id', { Object.defineProperty(Object.prototype, 'id', {
configurable: true, configurable: true,
set: t.step_func(function(value) { setter_called = true; }), set: value => { setter_called = true; },
}); });
t.add_cleanup(function() { t.add_cleanup(() => { delete Object.prototype['id']; });
delete Object.prototype['id'];
}); const tx = db.transaction('store', 'readwrite');
request.onerror = t.unreached_func('request should not fail'); tx.objectStore('store').put({});
request.onsuccess = t.step_func(function() { const result = await promiseForRequest(t, tx.objectStore('store').get(1));
const result = request.result;
assert_false(setter_called, assert_false(setter_called,
'Setter should not be called for key result.'); 'Setter should not be called for key result.');
assert_true( assert_true(result.hasOwnProperty('id'),
result.hasOwnProperty('id'),
'Result should have own-property overriding prototype setter.'); 'Result should have own-property overriding prototype setter.');
assert_equals(result.id, 1, assert_equals(result.id, 1,
'Own property should match primary key generator value'); 'Own property should match primary key generator value');
t.done(); }, 'Returning values to script should bypass prototype setters');
});
},
'Returning values to script should bypass prototype setters'
);
indexeddb_test( promise_test(async t => {
(t, db) => { const db = await createDatabase(t, db => {
db.createObjectStore('store', {autoIncrement: true, keyPath: 'a.b.c'}); db.createObjectStore('store', {autoIncrement: true, keyPath: 'a.b.c'});
}, });
(t, db) => {
const tx = db.transaction('store', 'readwrite');
tx.objectStore('store').put({});
const request = tx.objectStore('store').get(1);
Object.prototype.a = {b: {c: 'on proto'}}; Object.prototype.a = {b: {c: 'on proto'}};
t.add_cleanup(function() { t.add_cleanup(() => { delete Object.prototype.a; });
delete Object.prototype.a;
}); const tx = db.transaction('store', 'readwrite');
assert_equals(Object.prototype.a.b.c, 'on proto', tx.objectStore('store').put({});
'Prototype should be configured for test'); const result = await promiseForRequest(t, tx.objectStore('store').get(1));
request.onerror = t.unreached_func('request should not fail');
request.onsuccess = t.step_func(function() {
const result = request.result;
assert_true(result.hasOwnProperty('a'), assert_true(result.hasOwnProperty('a'),
'Result should have own-properties overriding prototype.'); 'Result should have own-properties overriding prototype.');
assert_true(result.a.hasOwnProperty('b'), assert_true(result.a.hasOwnProperty('b'),
...@@ -102,10 +77,6 @@ indexeddb_test( ...@@ -102,10 +77,6 @@ indexeddb_test(
'Own property should match primary key generator value'); 'Own property should match primary key generator value');
assert_equals(Object.prototype.a.b.c, 'on proto', assert_equals(Object.prototype.a.b.c, 'on proto',
'Prototype should not be modified'); 'Prototype should not be modified');
t.done(); }, 'Returning values to script should bypass prototype chain');
});
},
'Returning values to script should bypass prototype chain'
);
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment