Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/external/wpt/IndexedDB/keygenerator-explicit.html |
| diff --git a/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/keygenerator-explicit.html b/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/keygenerator-explicit.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..847265a36e2d6fcb756485f59d271e3f3be4fd4e |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/external/wpt/IndexedDB/keygenerator-explicit.html |
| @@ -0,0 +1,142 @@ |
| +<!DOCTYPE html> |
| +<meta charset="utf-8"> |
| +<title>Key Generator behavior with explicit keys generator overflow</title> |
| +<link rel=help href="https://w3c.github.io/IndexedDB/#key-generator-construct"> |
| +<script src="/resources/testharness.js"></script> |
| +<script src="/resources/testharnessreport.js"></script> |
| +<script src="support.js"></script> |
| +<script> |
| + |
| +function big_key_test(key, description) { |
| + indexeddb_test( |
| + (t, db) => { |
| + assert_equals(indexedDB.cmp(key, key), 0, 'Key is valid'); |
| + |
| + db.createObjectStore('store', {autoIncrement: true}); |
| + }, |
| + (t, db) => { |
| + const tx = db.transaction('store', 'readwrite'); |
| + const store = tx.objectStore('store'); |
| + const value = 0; |
| + let request; |
| + |
| + request = store.put(value); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, 1, |
| + 'Key generator should initially be 1'); |
| + }); |
| + |
| + request = store.put(value); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, 2, |
| + 'Key generator should increment'); |
| + }); |
| + |
| + request = store.put(value, 1000); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, 1000, |
| + 'Explicit key should be used'); |
| + }); |
| + |
| + request = store.put(value); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, 1001, |
| + 'Key generator should have updated'); |
| + }); |
| + |
| + request = store.put(value, key); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, key, |
| + 'Explicit key should be used'); |
| + }); |
| + |
| + if (key >= 0) { |
| + // Large positive values will max out the key generator, so it |
| + // can no longer produce keys. |
| + request = store.put(value); |
| + request.onsuccess = t.unreached_func('put should fail'); |
| + request.onerror = t.step_func(e => { |
| + e.preventDefault(); |
| + assert_equals(e.target.error.name, 'ConstraintError', |
| + 'Key generator should have returned failure'); |
| + }); |
| + } else { |
| + // Large negative values are always lower than the key generator's |
| + // current number, so have no effect on the generator. |
| + request = store.put(value); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, 1002, |
| + 'Key generator should have updated'); |
| + }); |
| + } |
| + |
| + request = store.put(value, 2000); |
| + request.onerror = t.unreached_func('put should succeed'); |
| + request.onsuccess = t.step_func(e => { |
| + assert_equals(e.target.result, 2000, |
| + 'Explicit key should be used'); |
| + }); |
| + |
| + tx.onabort = t.step_func(() => { |
| + assert_unreached(`Transaction aborted: ${tx.error.message}`); |
| + }); |
| + tx.oncomplete = t.step_func(() => { t.done(); }); |
| + }, |
| + description); |
| +} |
| + |
| +[ |
| + { |
|
pwnall
2017/03/07 19:42:41
Would it make sense to have two tests around the e
jsbell
2017/03/07 20:27:57
keygenerator-overflow.htm tests this, in theory. I
|
| + key: Math.pow(2, 60), |
| + description: 'greater than 53 bits, less than 64 bits' |
| + }, |
| + { |
| + key: -Math.pow(2, 60), |
| + description: 'greater than 53 bits, less than 64 bits (negative)' |
| + }, |
| + { |
| + key: Math.pow(2, 63), |
| + description: '63 bits' |
| + }, |
| + { |
| + key: -Math.pow(2, 63), |
| + description: '63 bits (negative)' |
| + }, |
| + { |
| + key: Math.pow(2, 64), |
| + description: '64 bits' |
| + }, |
| + { |
| + key: -Math.pow(2, 64), |
| + description: '64 bits (negative)' |
| + }, |
| + { |
| + key: Math.pow(2, 70), |
| + description: 'greater than 64 bits, but still finite' |
| + }, |
| + { |
| + key: -Math.pow(2, 70), |
| + description: 'greater than 64 bits, but still finite (negative)' |
| + }, |
| + { |
| + key: Infinity, |
| + description: 'equal to Infinity' |
| + }, |
| + { |
| + key: -Infinity, |
| + description: 'equal to -Infinity' |
| + } |
| +].forEach(function(testCase) { |
| + big_key_test(testCase.key, |
| + `Key generator vs. explicit key ${testCase.description}`); |
| +}); |
| + |
| + |
| + |
| +</script> |