tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

idbfactory_cmp.any.js (3093B)


      1 // META: global=window,worker
      2 // META: title=IDBFactory.cmp()
      3 // META: script=resources/support-promises.js
      4 
      5 // Spec: https://w3c.github.io/IndexedDB/#dom-idbfactory-cmp
      6 // Spec: http://w3c.github.io/IndexedDB/#key-construct
      7 
      8 'use strict';
      9 
     10 // Test cmp() with valid keys. These tests verify that cmp() returns the correct
     11 // comparison value.
     12 test(function() {
     13  let greater = indexedDB.cmp(2, 1);
     14  let equal = indexedDB.cmp(2, 2);
     15  let less = indexedDB.cmp(1, 2);
     16 
     17  assert_equals(greater, 1, 'greater');
     18  assert_equals(equal, 0, 'equal');
     19  assert_equals(less, -1, 'less');
     20 }, 'IDBFactory.cmp() - compared keys return correct value');
     21 
     22 // Test cmp() with invalid keys. These tests verify that cmp() throws an
     23 // exception when given invalid input.
     24 test(function() {
     25  assert_throws_js(TypeError, function() {
     26    indexedDB.cmp();
     27  });
     28 }, 'IDBFactory.cmp() - no argument');
     29 
     30 test(function() {
     31  assert_throws_dom('DataError', function() {
     32    indexedDB.cmp(null, null);
     33  });
     34  assert_throws_dom('DataError', function() {
     35    indexedDB.cmp(1, null);
     36  });
     37  assert_throws_dom('DataError', function() {
     38    indexedDB.cmp(null, 1);
     39  });
     40 }, 'IDBFactory.cmp() - null');
     41 
     42 test(function() {
     43  assert_throws_dom('DataError', function() {
     44    indexedDB.cmp(NaN, NaN);
     45  });
     46  assert_throws_dom('DataError', function() {
     47    indexedDB.cmp(1, NaN);
     48  });
     49  assert_throws_dom('DataError', function() {
     50    indexedDB.cmp(NaN, 1);
     51  });
     52 }, 'IDBFactory.cmp() - NaN');
     53 
     54 // Test cmp() with keys of different types. These tests verify that cmp()
     55 // correctly compares keys of different types.
     56 test(function() {
     57  assert_equals(indexedDB.cmp([0], new Uint8Array([0])), 1, 'Array > Binary');
     58 }, 'Array vs. Binary');
     59 
     60 test(function() {
     61  assert_equals(indexedDB.cmp(new Uint8Array([0]), '0'), 1, 'Binary > String');
     62 }, 'Binary vs. String');
     63 
     64 test(function() {
     65  assert_equals(indexedDB.cmp('', new Date(0)), 1, 'String > Date');
     66 }, 'String vs. Date');
     67 
     68 test(function() {
     69  assert_equals(indexedDB.cmp(new Date(0), 0), 1, 'Date > Number');
     70 }, 'Date vs. Number');
     71 
     72 // Test cmp() with binary keys. These tests verify that cmp() correctly compares
     73 // binary keys.
     74 test(function() {
     75  assert_equals(
     76      indexedDB.cmp(new Int8Array([-1]), new Uint8Array([0])), 1,
     77      '255(-1) shall be larger than 0');
     78 }, 'Compare in unsigned octet values (in the range [0, 255])');
     79 
     80 test(function() {
     81  assert_equals(
     82      indexedDB.cmp(
     83          new Uint8Array([255, 254, 253]), new Uint8Array([255, 253, 254])),
     84      1, '[255, 254, 253] shall be larger than [255, 253, 254]');
     85 }, 'Compare values of the same length');
     86 
     87 test(function() {
     88  assert_equals(
     89      indexedDB.cmp(
     90          new Uint8Array([255, 254]), new Uint8Array([255, 253, 254])),
     91      1, '[255, 254] shall be larger than [255, 253, 254]');
     92 }, 'Compare values of different lengths');
     93 
     94 test(function() {
     95  assert_equals(
     96      indexedDB.cmp(
     97          new Uint8Array([255, 253, 254]), new Uint8Array([255, 253])),
     98      1, '[255, 253, 254] shall be larger than [255, 253]');
     99 }, 'Compare when values in the range of their minimal length are the same');