Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/IndexedDB/keygenerator-explicit.html

Issue 2735213002: Indexed DB: Ensure large explicit keys consistently max out generator (Closed)
Patch Set: Incorporate review feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>Key Generator behavior with explicit keys generator overflow</title>
4 <link rel=help href="https://w3c.github.io/IndexedDB/#key-generator-construct">
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 <script src="support.js"></script>
8 <script>
9
10 function big_key_test(key, description) {
11 indexeddb_test(
12 (t, db) => {
13 assert_equals(indexedDB.cmp(key, key), 0, 'Key is valid');
14
15 db.createObjectStore('store', {autoIncrement: true});
16 },
17 (t, db) => {
18 const tx = db.transaction('store', 'readwrite');
19 const store = tx.objectStore('store');
20 const value = 0;
21 let request;
22
23 request = store.put(value);
24 request.onerror = t.unreached_func('put should succeed');
25 request.onsuccess = t.step_func(e => {
26 assert_equals(e.target.result, 1,
27 'Key generator should initially be 1');
28 });
29
30 request = store.put(value);
31 request.onerror = t.unreached_func('put should succeed');
32 request.onsuccess = t.step_func(e => {
33 assert_equals(e.target.result, 2,
34 'Key generator should increment');
35 });
36
37 request = store.put(value, 1000);
38 request.onerror = t.unreached_func('put should succeed');
39 request.onsuccess = t.step_func(e => {
40 assert_equals(e.target.result, 1000,
41 'Explicit key should be used');
42 });
43
44 request = store.put(value);
45 request.onerror = t.unreached_func('put should succeed');
46 request.onsuccess = t.step_func(e => {
47 assert_equals(e.target.result, 1001,
48 'Key generator should have updated');
49 });
50
51 request = store.put(value, key);
52 request.onerror = t.unreached_func('put should succeed');
53 request.onsuccess = t.step_func(e => {
54 assert_equals(e.target.result, key,
55 'Explicit key should be used');
56 });
57
58 if (key >= 0) {
59 // Large positive values will max out the key generator, so it
60 // can no longer produce keys.
61 request = store.put(value);
62 request.onsuccess = t.unreached_func('put should fail');
63 request.onerror = t.step_func(e => {
64 e.preventDefault();
65 assert_equals(e.target.error.name, 'ConstraintError',
66 'Key generator should have returned failure');
67 });
68 } else {
69 // Large negative values are always lower than the key generator's
70 // current number, so have no effect on the generator.
71 request = store.put(value);
72 request.onerror = t.unreached_func('put should succeed');
73 request.onsuccess = t.step_func(e => {
74 assert_equals(e.target.result, 1002,
75 'Key generator should have updated');
76 });
77 }
78
79 request = store.put(value, 2000);
80 request.onerror = t.unreached_func('put should succeed');
81 request.onsuccess = t.step_func(e => {
82 assert_equals(e.target.result, 2000,
83 'Explicit key should be used');
84 });
85
86 tx.onabort = t.step_func(() => {
87 assert_unreached(`Transaction aborted: ${tx.error.message}`);
88 });
89 tx.oncomplete = t.step_func(() => { t.done(); });
90 },
91 description);
92 }
93
94 [
95 {
96 key: Number.MAX_SAFE_INTEGER + 1,
97 description: '53 bits'
98 },
99 {
100 key: Math.pow(2, 60),
101 description: 'greater than 53 bits, less than 64 bits'
102 },
103 {
104 key: -Math.pow(2, 60),
105 description: 'greater than 53 bits, less than 64 bits (negative)'
106 },
107 {
108 key: Math.pow(2, 63),
109 description: '63 bits'
110 },
111 {
112 key: -Math.pow(2, 63),
113 description: '63 bits (negative)'
114 },
115 {
116 key: Math.pow(2, 64),
117 description: '64 bits'
118 },
119 {
120 key: -Math.pow(2, 64),
121 description: '64 bits (negative)'
122 },
123 {
124 key: Math.pow(2, 70),
125 description: 'greater than 64 bits, but still finite'
126 },
127 {
128 key: -Math.pow(2, 70),
129 description: 'greater than 64 bits, but still finite (negative)'
130 },
131 {
132 key: Infinity,
133 description: 'equal to Infinity'
134 },
135 {
136 key: -Infinity,
137 description: 'equal to -Infinity'
138 }
139 ].forEach(function(testCase) {
140 big_key_test(testCase.key,
141 `Key generator vs. explicit key ${testCase.description}`);
142 });
143
144
145
146 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698