Skip to content

Commit

Permalink
IDB WPTs: Extend idbfactory_cmp related tests to workers
Browse files Browse the repository at this point in the history
The update modifies idbfactory_cmp related WPTs to run not
only in window environments but also on dedicated, service, and shared
workers.

Bug: 41455766
Change-Id: I41425b288dd7c83a5cf72ceeec91e2c008a07491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6186671
Auto-Submit: Garima Chadha <[email protected]>
Reviewed-by: Steve Becker <[email protected]>
Commit-Queue: Rahul Singh <[email protected]>
Reviewed-by: Rahul Singh <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1409998}
  • Loading branch information
Garima Chadha authored and chromium-wpt-export-bot committed Jan 23, 2025
1 parent 19b2aac commit 5753f6c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 129 deletions.
99 changes: 99 additions & 0 deletions IndexedDB/idbfactory_cmp.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// META: global=window,worker
// META: title=IDBFactory.cmp()
// META: script=resources/support-promises.js

// Spec: https://w3c.github.io/IndexedDB/#dom-idbfactory-cmp
// Spec: http://w3c.github.io/IndexedDB/#key-construct

'use strict';

// Test cmp() with valid keys. These tests verify that cmp() returns the correct
// comparison value.
test(function() {
let greater = indexedDB.cmp(2, 1);
let equal = indexedDB.cmp(2, 2);
let less = indexedDB.cmp(1, 2);

assert_equals(greater, 1, 'greater');
assert_equals(equal, 0, 'equal');
assert_equals(less, -1, 'less');
}, 'IDBFactory.cmp() - compared keys return correct value');

// Test cmp() with invalid keys. These tests verify that cmp() throws an
// exception when given invalid input.
test(function() {
assert_throws_js(TypeError, function() {
indexedDB.cmp();
});
}, 'IDBFactory.cmp() - no argument');

test(function() {
assert_throws_dom('DataError', function() {
indexedDB.cmp(null, null);
});
assert_throws_dom('DataError', function() {
indexedDB.cmp(1, null);
});
assert_throws_dom('DataError', function() {
indexedDB.cmp(null, 1);
});
}, 'IDBFactory.cmp() - null');

test(function() {
assert_throws_dom('DataError', function() {
indexedDB.cmp(NaN, NaN);
});
assert_throws_dom('DataError', function() {
indexedDB.cmp(1, NaN);
});
assert_throws_dom('DataError', function() {
indexedDB.cmp(NaN, 1);
});
}, 'IDBFactory.cmp() - NaN');

// Test cmp() with keys of different types. These tests verify that cmp()
// correctly compares keys of different types.
test(function() {
assert_equals(indexedDB.cmp([0], new Uint8Array([0])), 1, 'Array > Binary');
}, 'Array vs. Binary');

test(function() {
assert_equals(indexedDB.cmp(new Uint8Array([0]), '0'), 1, 'Binary > String');
}, 'Binary vs. String');

test(function() {
assert_equals(indexedDB.cmp('', new Date(0)), 1, 'String > Date');
}, 'String vs. Date');

test(function() {
assert_equals(indexedDB.cmp(new Date(0), 0), 1, 'Date > Number');
}, 'Date vs. Number');

// Test cmp() with binary keys. These tests verify that cmp() correctly compares
// binary keys.
test(function() {
assert_equals(
indexedDB.cmp(new Int8Array([-1]), new Uint8Array([0])), 1,
'255(-1) shall be larger than 0');
}, 'Compare in unsigned octet values (in the range [0, 255])');

test(function() {
assert_equals(
indexedDB.cmp(
new Uint8Array([255, 254, 253]), new Uint8Array([255, 253, 254])),
1, '[255, 254, 253] shall be larger than [255, 253, 254]');
}, 'Compare values of the same length');

test(function() {
assert_equals(
indexedDB.cmp(
new Uint8Array([255, 254]), new Uint8Array([255, 253, 254])),
1, '[255, 254] shall be larger than [255, 253, 254]');
}, 'Compare values of different lengths');

test(function() {
assert_equals(
indexedDB.cmp(
new Uint8Array([255, 253, 254]), new Uint8Array([255, 253])),
1, '[255, 253, 254] shall be larger than [255, 253]');
}, 'Compare when values in the range of their minimal length are the same');
21 changes: 0 additions & 21 deletions IndexedDB/idbfactory_cmp.htm

This file was deleted.

41 changes: 0 additions & 41 deletions IndexedDB/idbfactory_cmp2.htm

This file was deleted.

27 changes: 0 additions & 27 deletions IndexedDB/idbfactory_cmp3.htm

This file was deleted.

40 changes: 0 additions & 40 deletions IndexedDB/idbfactory_cmp4.htm

This file was deleted.

0 comments on commit 5753f6c

Please sign in to comment.