mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 20:58:16 +00:00
LibWeb/Tests: Update IDB keyorder test file
This commit is contained in:
parent
75054aeecd
commit
9e66f49b44
Notes:
github-actions[bot]
2025-08-14 08:33:19 +00:00
Author: https://github.com/stelar7
Commit: 9e66f49b44
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5827
Reviewed-by: https://github.com/AtkinsSJ ✅
4 changed files with 196 additions and 187 deletions
|
@ -4,26 +4,26 @@ Found 24 tests
|
||||||
|
|
||||||
24 Pass
|
24 Pass
|
||||||
Pass Database readback sort - String < Array
|
Pass Database readback sort - String < Array
|
||||||
Pass IDBKey.cmp sorted - String < Array
|
Pass IDBKey.cmp sort - String < Array
|
||||||
Pass Database readback sort - float < String
|
Pass Database readback sort - float < String
|
||||||
Pass IDBKey.cmp sorted - float < String
|
Pass IDBKey.cmp sort - float < String
|
||||||
Pass Database readback sort - float < Date
|
Pass Database readback sort - float < Date
|
||||||
Pass IDBKey.cmp sorted - float < Date
|
Pass IDBKey.cmp sort - float < Date
|
||||||
Pass Database readback sort - float < Date < String < Array
|
Pass Database readback sort - float < Date < String < Array
|
||||||
Pass IDBKey.cmp sorted - float < Date < String < Array
|
Pass IDBKey.cmp sort - float < Date < String < Array
|
||||||
Pass Database readback sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)
|
Pass Database readback sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)
|
||||||
Pass IDBKey.cmp sorted - Date(1 sec ago) < Date(now) < Date(1 minute in future)
|
Pass IDBKey.cmp sort - Date(1 sec ago) < Date(now) < Date(1 minute in future)
|
||||||
Pass Database readback sort - -1.1 < 1 < 1.01337 < 1.013373 < 2
|
Pass Database readback sort - -1.1 < 1 < 1.01337 < 1.013373 < 2
|
||||||
Pass IDBKey.cmp sorted - -1.1 < 1 < 1.01337 < 1.013373 < 2
|
Pass IDBKey.cmp sort - -1.1 < 1 < 1.01337 < 1.013373 < 2
|
||||||
Pass Database readback sort - -Infinity < -0.01 < 0 < Infinity
|
Pass Database readback sort - -Infinity < -0.01 < 0 < Infinity
|
||||||
Pass IDBKey.cmp sorted - -Infinity < -0.01 < 0 < Infinity
|
Pass IDBKey.cmp sort - -Infinity < -0.01 < 0 < Infinity
|
||||||
Pass Database readback sort - "" < "a" < "ab" < "b" < "ba"
|
Pass Database readback sort - "" < "a" < "ab" < "b" < "ba"
|
||||||
Pass IDBKey.cmp sorted - "" < "a" < "ab" < "b" < "ba"
|
Pass IDBKey.cmp sort - "" < "a" < "ab" < "b" < "ba"
|
||||||
Pass Database readback sort - Arrays
|
Pass Database readback sort - Arrays
|
||||||
Pass IDBKey.cmp sorted - Arrays
|
Pass IDBKey.cmp sort - Arrays
|
||||||
Pass Database readback sort - Array.length: 10,000 < Array.length: 10,001
|
Pass Database readback sort - Array.length: 10,000 < Array.length: 10,001
|
||||||
Pass IDBKey.cmp sorted - Array.length: 10,000 < Array.length: 10,001
|
Pass IDBKey.cmp sort - Array.length: 10,000 < Array.length: 10,001
|
||||||
Pass Database readback sort - Infinity inside arrays
|
Pass Database readback sort - Infinity inside arrays
|
||||||
Pass IDBKey.cmp sorted - Infinity inside arrays
|
Pass IDBKey.cmp sort - Infinity inside arrays
|
||||||
Pass Database readback sort - Test different stuff at once
|
Pass Database readback sort - Test different stuff at once
|
||||||
Pass IDBKey.cmp sorted - Test different stuff at once
|
Pass IDBKey.cmp sort - Test different stuff at once
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset=utf-8>
|
||||||
|
<title>Key sort order</title>
|
||||||
|
<script>
|
||||||
|
self.GLOBAL = {
|
||||||
|
isWindow: function() { return true; },
|
||||||
|
isWorker: function() { return false; },
|
||||||
|
isShadowRealm: function() { return false; },
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script src="../resources/testharness.js"></script>
|
||||||
|
<script src="../resources/testharnessreport.js"></script>
|
||||||
|
<script src="resources/support.js"></script>
|
||||||
|
<div id=log></div>
|
||||||
|
<script src="../IndexedDB/keyorder.any.js"></script>
|
169
Tests/LibWeb/Text/input/wpt-import/IndexedDB/keyorder.any.js
Normal file
169
Tests/LibWeb/Text/input/wpt-import/IndexedDB/keyorder.any.js
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
// META: global=window,worker
|
||||||
|
// META: title=Key sort order
|
||||||
|
// META: script=resources/support.js
|
||||||
|
|
||||||
|
// Spec: https://w3c.github.io/IndexedDB/#key-construct
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const global_db = createdb_for_multiple_tests();
|
||||||
|
|
||||||
|
const keysort = (desc, unsorted, expected) => {
|
||||||
|
async_test(t => {
|
||||||
|
const store_name = 'store-' + Date.now() + Math.random();
|
||||||
|
|
||||||
|
// The database test
|
||||||
|
const open_rq = global_db.setTest(t);
|
||||||
|
open_rq.onupgradeneeded = t.step_func(e => {
|
||||||
|
const db = e.target.result;
|
||||||
|
const objStore = db.createObjectStore(store_name);
|
||||||
|
|
||||||
|
for (let i = 0; i < unsorted.length; i++)
|
||||||
|
objStore.add('value', unsorted[i]);
|
||||||
|
});
|
||||||
|
|
||||||
|
open_rq.onsuccess = t.step_func(e => {
|
||||||
|
const db = e.target.result;
|
||||||
|
const actual_keys = [];
|
||||||
|
const rq =
|
||||||
|
db.transaction(store_name).objectStore(store_name).openCursor();
|
||||||
|
|
||||||
|
rq.onsuccess = t.step_func(e => {
|
||||||
|
const cursor = e.target.result;
|
||||||
|
|
||||||
|
if (cursor) {
|
||||||
|
actual_keys.push(cursor.key);
|
||||||
|
cursor.continue();
|
||||||
|
} else {
|
||||||
|
assert_key_equals(actual_keys, expected, 'keyorder array');
|
||||||
|
assert_equals(actual_keys.length, expected.length, 'array length');
|
||||||
|
|
||||||
|
t.done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, `Database readback sort - ${desc}`);
|
||||||
|
|
||||||
|
// The IDBKey.cmp test
|
||||||
|
test(() => {
|
||||||
|
const sorted = unsorted.slice(0).sort((a, b) => indexedDB.cmp(a, b));
|
||||||
|
assert_key_equals(sorted, expected, 'sorted array');
|
||||||
|
}, `IDBKey.cmp sort - ${desc}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const one_sec_ago = new Date(now - 1000);
|
||||||
|
const one_min_future = new Date(now.getTime() + 1000 * 60);
|
||||||
|
|
||||||
|
keysort('String < Array', [[0], 'yo', '', []], ['', 'yo', [], [0]]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'float < String', [Infinity, 'yo', 0, '', 100],
|
||||||
|
[0, 100, Infinity, '', 'yo']);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'float < Date', [now, 0, 9999999999999, -0.22],
|
||||||
|
[-0.22, 0, 9999999999999, now]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'float < Date < String < Array', [[], '', now, [0], '-1', 0, 9999999999999],
|
||||||
|
[0, 9999999999999, now, '', '-1', [], [0]]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'Date(1 sec ago) < Date(now) < Date(1 minute in future)',
|
||||||
|
[now, one_sec_ago, one_min_future], [one_sec_ago, now, one_min_future]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'-1.1 < 1 < 1.01337 < 1.013373 < 2', [1.013373, 2, 1.01337, -1.1, 1],
|
||||||
|
[-1.1, 1, 1.01337, 1.013373, 2]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'-Infinity < -0.01 < 0 < Infinity', [0, -0.01, -Infinity, Infinity],
|
||||||
|
[-Infinity, -0.01, 0, Infinity]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'"" < "a" < "ab" < "b" < "ba"', ['a', 'ba', '', 'b', 'ab'],
|
||||||
|
['', 'a', 'ab', 'b', 'ba']);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'Arrays', [[[0]], [0], [], [0, 0], [0, [0]]],
|
||||||
|
[[], [0], [0, 0], [0, [0]], [[0]]]);
|
||||||
|
|
||||||
|
const big_array = [];
|
||||||
|
const bigger_array = [];
|
||||||
|
for (let i = 0; i < 10000; i++) {
|
||||||
|
big_array.push(i);
|
||||||
|
bigger_array.push(i);
|
||||||
|
}
|
||||||
|
bigger_array.push(0);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'Array.length: 10,000 < Array.length: 10,001',
|
||||||
|
[bigger_array, [0, 2, 3], [0], [9], big_array],
|
||||||
|
[[0], big_array, bigger_array, [0, 2, 3], [9]]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'Infinity inside arrays',
|
||||||
|
[
|
||||||
|
[Infinity, 1],
|
||||||
|
[Infinity, Infinity],
|
||||||
|
[1, 1],
|
||||||
|
[1, Infinity],
|
||||||
|
[1, -Infinity],
|
||||||
|
[-Infinity, Infinity],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[-Infinity, Infinity],
|
||||||
|
[1, -Infinity],
|
||||||
|
[1, 1],
|
||||||
|
[1, Infinity],
|
||||||
|
[Infinity, 1],
|
||||||
|
[Infinity, Infinity],
|
||||||
|
]);
|
||||||
|
|
||||||
|
keysort(
|
||||||
|
'Test different stuff at once',
|
||||||
|
[
|
||||||
|
now,
|
||||||
|
[0, []],
|
||||||
|
'test',
|
||||||
|
1,
|
||||||
|
['a', [1, [-1]]],
|
||||||
|
['b', 'a'],
|
||||||
|
[0, 2, 'c'],
|
||||||
|
['a', [1, 2]],
|
||||||
|
[],
|
||||||
|
[0, [], 3],
|
||||||
|
['a', 'b'],
|
||||||
|
[1, 2],
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
one_sec_ago,
|
||||||
|
[0, 'b', 'c'],
|
||||||
|
Infinity,
|
||||||
|
-Infinity,
|
||||||
|
2.55,
|
||||||
|
[0, now],
|
||||||
|
[1],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
-Infinity,
|
||||||
|
1,
|
||||||
|
2.55,
|
||||||
|
Infinity,
|
||||||
|
one_sec_ago,
|
||||||
|
now,
|
||||||
|
'test',
|
||||||
|
[],
|
||||||
|
[0, 2, 'c'],
|
||||||
|
[0, now],
|
||||||
|
[0, 'b', 'c'],
|
||||||
|
[0, []],
|
||||||
|
[0, [], 3],
|
||||||
|
[1],
|
||||||
|
[1, 2],
|
||||||
|
['a', 'b'],
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
['a', [1, 2]],
|
||||||
|
['a', [1, [-1]]],
|
||||||
|
['b', 'a'],
|
||||||
|
]);
|
|
@ -1,175 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<!-- Submitted from TestTWF Paris -->
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Key sort order</title>
|
|
||||||
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#key-construct">
|
|
||||||
<link rel=assert title="For purposes of comparison, all Arrays are greater than all DOMString, Date and float values; all DOMString values are greater than all Date and float values; and all Date values are greater than all float values. Values of type float are compared to other float values numerically. Values of type Date are compared to other Date values chronologically. Values of type DOMString are compared to other values of type DOMString by using the algorithm defined by step 4 of section 11.8.5, The Abstract Relational Comparison Algorithm, of the ECMAScript Language Specification [ECMA-262]. Values of type Array are compared to other values of type Array as follows:
|
|
||||||
|
|
||||||
1. Let A be the first Array value and B be the second Array value.
|
|
||||||
2. Let length be the lesser of A's length and B's length.
|
|
||||||
3. Let i be 0.
|
|
||||||
4. If the ith value of A is less than the ith value of B, then A is less than B. Skip the remaining steps.
|
|
||||||
5. If the ith value of A is greater than the ith value of B, then A is greater than B. Skip the remaining steps.
|
|
||||||
6. Increase i by 1.
|
|
||||||
7. If i is not equal to length, go back to step 4. Otherwise continue to next step.
|
|
||||||
8. If A's length is less than B's length, then A is less than B. If A's length is greater than B's length, then A is greater than B. Otherwise A and B are equal.">
|
|
||||||
<script src="../resources/testharness.js"></script>
|
|
||||||
<script src="../resources/testharnessreport.js"></script>
|
|
||||||
<script src="resources/support.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var global_db = createdb_for_multiple_tests();
|
|
||||||
|
|
||||||
function keysort(desc, unsorted, expected) {
|
|
||||||
var db,
|
|
||||||
t = async_test("Database readback sort - " + desc),
|
|
||||||
store_name = 'store-' + Date.now() + Math.random();
|
|
||||||
|
|
||||||
// The database test
|
|
||||||
var open_rq = global_db.setTest(t);
|
|
||||||
open_rq.onupgradeneeded = function(e) {
|
|
||||||
db = e.target.result;
|
|
||||||
var objStore = db.createObjectStore(store_name);
|
|
||||||
|
|
||||||
for (var i = 0; i < unsorted.length; i++)
|
|
||||||
objStore.add("value", unsorted[i]);
|
|
||||||
};
|
|
||||||
|
|
||||||
open_rq.onsuccess = function(e) {
|
|
||||||
var actual_keys = [],
|
|
||||||
rq = db.transaction(store_name)
|
|
||||||
.objectStore(store_name)
|
|
||||||
.openCursor();
|
|
||||||
|
|
||||||
rq.onsuccess = t.step_func(function(e) {
|
|
||||||
var cursor = e.target.result;
|
|
||||||
|
|
||||||
if (cursor) {
|
|
||||||
actual_keys.push(cursor.key);
|
|
||||||
cursor.continue();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert_key_equals(actual_keys, expected, "keyorder array");
|
|
||||||
assert_equals(actual_keys.length, expected.length, "array length");
|
|
||||||
|
|
||||||
t.done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// The IDBKey.cmp test
|
|
||||||
test(function () {
|
|
||||||
var sorted = unsorted.slice(0).sort(function(a, b) { return indexedDB.cmp(a, b)});
|
|
||||||
assert_key_equals(sorted, expected, "sorted array");
|
|
||||||
|
|
||||||
}, "IDBKey.cmp sorted - " + desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
var now = new Date(),
|
|
||||||
one_sec_ago = new Date(now - 1000),
|
|
||||||
one_min_future = new Date(now.getTime() + (1000*60));
|
|
||||||
|
|
||||||
keysort('String < Array',
|
|
||||||
[ [0], "yo", "", [] ],
|
|
||||||
[ "", "yo", [], [0] ]);
|
|
||||||
|
|
||||||
keysort('float < String',
|
|
||||||
[ Infinity, "yo", 0, "", 100 ],
|
|
||||||
[ 0, 100, Infinity, "", "yo" ]);
|
|
||||||
|
|
||||||
keysort('float < Date',
|
|
||||||
[ now, 0, 9999999999999, -0.22 ],
|
|
||||||
[ -0.22, 0, 9999999999999, now ]);
|
|
||||||
|
|
||||||
keysort('float < Date < String < Array',
|
|
||||||
[ [], "", now, [0], "-1", 0, 9999999999999, ],
|
|
||||||
[ 0, 9999999999999, now, "", "-1", [], [0] ]);
|
|
||||||
|
|
||||||
|
|
||||||
keysort('Date(1 sec ago) < Date(now) < Date(1 minute in future)',
|
|
||||||
[ now, one_sec_ago, one_min_future ],
|
|
||||||
[ one_sec_ago, now, one_min_future ]);
|
|
||||||
|
|
||||||
keysort('-1.1 < 1 < 1.01337 < 1.013373 < 2',
|
|
||||||
[ 1.013373, 2, 1.01337, -1.1, 1 ],
|
|
||||||
[ -1.1, 1, 1.01337, 1.013373, 2 ]);
|
|
||||||
|
|
||||||
keysort('-Infinity < -0.01 < 0 < Infinity',
|
|
||||||
[ 0, -0.01, -Infinity, Infinity ],
|
|
||||||
[ -Infinity, -0.01, 0, Infinity ]);
|
|
||||||
|
|
||||||
keysort('"" < "a" < "ab" < "b" < "ba"',
|
|
||||||
[ "a", "ba", "", "b", "ab" ],
|
|
||||||
[ "", "a", "ab", "b", "ba" ]);
|
|
||||||
|
|
||||||
keysort('Arrays',
|
|
||||||
[ [[0]], [0], [], [0, 0], [0, [0]] ],
|
|
||||||
[ [], [0], [0, 0], [0, [0]], [[0]] ]);
|
|
||||||
|
|
||||||
var big_array = [], bigger_array = [];
|
|
||||||
for (var i=0; i < 10000; i++) {
|
|
||||||
big_array.push(i);
|
|
||||||
bigger_array.push(i);
|
|
||||||
}
|
|
||||||
bigger_array.push(0);
|
|
||||||
|
|
||||||
keysort('Array.length: 10,000 < Array.length: 10,001',
|
|
||||||
[ bigger_array, [0, 2, 3], [0], [9], big_array ],
|
|
||||||
[ [0], big_array, bigger_array, [0, 2, 3], [9] ]);
|
|
||||||
|
|
||||||
keysort('Infinity inside arrays',
|
|
||||||
[ [Infinity, 1], [Infinity, Infinity], [1, 1],
|
|
||||||
[1, Infinity], [1, -Infinity], [-Infinity, Infinity] ],
|
|
||||||
[ [-Infinity, Infinity], [1, -Infinity], [1, 1],
|
|
||||||
[1, Infinity], [Infinity, 1], [Infinity, Infinity] ]);
|
|
||||||
|
|
||||||
|
|
||||||
keysort('Test different stuff at once',
|
|
||||||
[
|
|
||||||
now,
|
|
||||||
[0, []],
|
|
||||||
"test",
|
|
||||||
1,
|
|
||||||
["a", [1, [-1]]],
|
|
||||||
["b", "a"],
|
|
||||||
[ 0, 2, "c"],
|
|
||||||
["a", [1, 2]],
|
|
||||||
[],
|
|
||||||
[0, [], 3],
|
|
||||||
["a", "b"],
|
|
||||||
[ 1, 2 ],
|
|
||||||
["a", "b", "c"],
|
|
||||||
one_sec_ago,
|
|
||||||
[ 0, "b", "c"],
|
|
||||||
Infinity,
|
|
||||||
-Infinity,
|
|
||||||
2.55,
|
|
||||||
[ 0, now ],
|
|
||||||
[1]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
-Infinity,
|
|
||||||
1,
|
|
||||||
2.55,
|
|
||||||
Infinity,
|
|
||||||
one_sec_ago,
|
|
||||||
now,
|
|
||||||
"test",
|
|
||||||
[],
|
|
||||||
[0 ,2, "c"],
|
|
||||||
[0, now],
|
|
||||||
[0, "b", "c"],
|
|
||||||
[0, []],
|
|
||||||
[0, [], 3],
|
|
||||||
[1],
|
|
||||||
[1, 2],
|
|
||||||
["a", "b"],
|
|
||||||
["a", "b", "c"],
|
|
||||||
["a", [1, 2]],
|
|
||||||
["a", [1, [-1]]],
|
|
||||||
["b", "a"]
|
|
||||||
]);
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div id="log"></div>
|
|
Loading…
Add table
Add a link
Reference in a new issue