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,108 +4,79 @@ ...@@ -4,108 +4,79 @@
<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'];
});
request.onerror = t.unreached_func('request should not fail');
request.onsuccess = t.step_func(() => {
const result = request.result;
assert_false(setter_called,
'Setter should not be called for key result.');
assert_true(
result.hasOwnProperty('10'),
'Result should have own-property overriding prototype setter.');
assert_equals(result[10], 'key',
'Result should have expected property.');
t.done();
});
},
'Returning keys to script should bypass prototype setters'
);
indexeddb_test( const tx = db.transaction('store', 'readwrite');
(t, db) => { const result = await promiseForRequest(t, tx.objectStore('store').put(
'value', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'key']));
assert_false(setter_called,
'Setter should not be called for key result.');
assert_true(result.hasOwnProperty('10'),
'Result should have own-property overriding prototype setter.');
assert_equals(result[10], 'key',
'Result should have expected property.');
}, 'Returning keys to script should bypass prototype setters');
promise_test(async t => {
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'); let setter_called = false;
tx.objectStore('store').put({}); Object.defineProperty(Object.prototype, 'id', {
const request = tx.objectStore('store').get(1); configurable: true,
set: value => { setter_called = true; },
});
t.add_cleanup(() => { delete Object.prototype['id']; });
const setter_called = false; const tx = db.transaction('store', 'readwrite');
Object.defineProperty(Object.prototype, 'id', { tx.objectStore('store').put({});
configurable: true, const result = await promiseForRequest(t, tx.objectStore('store').get(1));
set: t.step_func(function(value) { setter_called = true; }),
});
t.add_cleanup(function() {
delete Object.prototype['id'];
});
request.onerror = t.unreached_func('request should not fail');
request.onsuccess = t.step_func(function() {
const result = request.result;
assert_false(setter_called,
'Setter should not be called for key result.');
assert_true(
result.hasOwnProperty('id'),
'Result should have own-property overriding prototype setter.');
assert_equals(result.id, 1,
'Own property should match primary key generator value');
t.done();
});
},
'Returning values to script should bypass prototype setters'
);
indexeddb_test( assert_false(setter_called,
(t, db) => { 'Setter should not be called for key result.');
assert_true(result.hasOwnProperty('id'),
'Result should have own-property overriding prototype setter.');
assert_equals(result.id, 1,
'Own property should match primary key generator value');
}, 'Returning values to script should bypass prototype setters');
promise_test(async t => {
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'); Object.prototype.a = {b: {c: 'on proto'}};
tx.objectStore('store').put({}); t.add_cleanup(() => { delete Object.prototype.a; });
const request = tx.objectStore('store').get(1);
Object.prototype.a = {b: {c: 'on proto'}}; const tx = db.transaction('store', 'readwrite');
t.add_cleanup(function() { tx.objectStore('store').put({});
delete Object.prototype.a; const result = await promiseForRequest(t, tx.objectStore('store').get(1));
});
assert_equals(Object.prototype.a.b.c, 'on proto',
'Prototype should be configured for test');
request.onerror = t.unreached_func('request should not fail'); assert_true(result.hasOwnProperty('a'),
request.onsuccess = t.step_func(function() { 'Result should have own-properties overriding prototype.');
const result = request.result; assert_true(result.a.hasOwnProperty('b'),
assert_true(result.hasOwnProperty('a'), 'Result should have own-properties overriding prototype.');
'Result should have own-properties overriding prototype.'); assert_true(result.a.b.hasOwnProperty('c'),
assert_true(result.a.hasOwnProperty('b'), 'Result should have own-properties overriding prototype.');
'Result should have own-properties overriding prototype.'); assert_equals(result.a.b.c, 1,
assert_true(result.a.b.hasOwnProperty('c'), 'Own property should match primary key generator value');
'Result should have own-properties overriding prototype.'); assert_equals(Object.prototype.a.b.c, 'on proto',
assert_equals(result.a.b.c, 1, 'Prototype should not be modified');
'Own property should match primary key generator value'); }, 'Returning values to script should bypass prototype chain');
assert_equals(Object.prototype.a.b.c, 'on proto',
'Prototype should not be modified');
t.done();
});
},
'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