tor-browser

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

test_locale_aware_index_getAllObjects.js (7531B)


      1 /**
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/publicdomain/zero/1.0/
      4 */
      5 
      6 /* exported testGenerator */
      7 var testGenerator = testSteps();
      8 
      9 function* testSteps() {
     10  const name = this.window ? window.location.pathname : "Splendid Test";
     11  const objectStoreName = "People";
     12 
     13  const objectStoreData = [
     14    {
     15      key: "237-23-7732",
     16      value: { name: "\u00E1na", height: 60, weight: 120 },
     17    },
     18    { key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
     19    { key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
     20    {
     21      key: "237-23-7735",
     22      value: { name: "\u00F3scar", height: 58, weight: 130 },
     23    },
     24    { key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
     25    { key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
     26  ];
     27 
     28  const indexData = [
     29    { name: "name", keyPath: "name", options: { unique: true, locale: true } },
     30    {
     31      name: "height",
     32      keyPath: "height",
     33      options: { unique: false, locale: true },
     34    },
     35    {
     36      name: "weight",
     37      keyPath: "weight",
     38      options: { unique: false, locale: true },
     39    },
     40  ];
     41 
     42  const objectStoreDataHeightSort = [
     43    { key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
     44    {
     45      key: "237-23-7735",
     46      value: { name: "\u00F3scar", height: 58, weight: 130 },
     47    },
     48    {
     49      key: "237-23-7732",
     50      value: { name: "\u00E1na", height: 60, weight: 120 },
     51    },
     52    { key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
     53    { key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
     54    { key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
     55  ];
     56 
     57  let request = indexedDB.open(name, 1);
     58  request.onerror = errorHandler;
     59  request.onupgradeneeded = grabEventAndContinueHandler;
     60  request.onsuccess = grabEventAndContinueHandler;
     61  let event = yield undefined;
     62 
     63  let db = event.target.result;
     64 
     65  let objectStore = db.createObjectStore(objectStoreName, {});
     66 
     67  // First, add all our data to the object store.
     68  let addedData = 0;
     69  for (let i in objectStoreData) {
     70    request = objectStore.add(objectStoreData[i].value, objectStoreData[i].key);
     71    request.onerror = errorHandler;
     72    request.onsuccess = function (event) {
     73      if (++addedData == objectStoreData.length) {
     74        testGenerator.next(event);
     75      }
     76    };
     77  }
     78  event = yield undefined;
     79 
     80  // Now create the indexes.
     81  for (let i in indexData) {
     82    objectStore.createIndex(
     83      indexData[i].name,
     84      indexData[i].keyPath,
     85      indexData[i].options
     86    );
     87  }
     88 
     89  is(objectStore.indexNames.length, indexData.length, "Good index count");
     90  yield undefined;
     91 
     92  objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
     93 
     94  request = objectStore.index("height").mozGetAll(65);
     95  request.onerror = errorHandler;
     96  request.onsuccess = grabEventAndContinueHandler;
     97  event = yield undefined;
     98 
     99  is(event.target.result instanceof Array, true, "Got an array object");
    100  is(event.target.result.length, 2, "Correct length");
    101 
    102  for (let i in event.target.result) {
    103    let result = event.target.result[i];
    104    let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
    105 
    106    is(result.name, testObj.name, "Correct name");
    107    is(result.height, testObj.height, "Correct height");
    108 
    109    if (testObj.hasOwnProperty("weight")) {
    110      is(result.weight, testObj.weight, "Correct weight");
    111    }
    112  }
    113 
    114  request = objectStore.index("height").mozGetAll(65, 0);
    115  request.onerror = errorHandler;
    116  request.onsuccess = grabEventAndContinueHandler;
    117  event = yield undefined;
    118 
    119  is(event.target.result instanceof Array, true, "Got an array object");
    120  is(event.target.result.length, 2, "Correct length");
    121 
    122  for (let i in event.target.result) {
    123    let result = event.target.result[i];
    124    let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
    125 
    126    is(result.name, testObj.name, "Correct name");
    127    is(result.height, testObj.height, "Correct height");
    128 
    129    if (testObj.hasOwnProperty("weight")) {
    130      is(result.weight, testObj.weight, "Correct weight");
    131    }
    132  }
    133 
    134  request = objectStore.index("height").mozGetAll(65, null);
    135  request.onerror = errorHandler;
    136  request.onsuccess = grabEventAndContinueHandler;
    137  event = yield undefined;
    138 
    139  is(event.target.result instanceof Array, true, "Got an array object");
    140  is(event.target.result.length, 2, "Correct length");
    141 
    142  for (let i in event.target.result) {
    143    let result = event.target.result[i];
    144    let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
    145 
    146    is(result.name, testObj.name, "Correct name");
    147    is(result.height, testObj.height, "Correct height");
    148 
    149    if (testObj.hasOwnProperty("weight")) {
    150      is(result.weight, testObj.weight, "Correct weight");
    151    }
    152  }
    153 
    154  request = objectStore.index("height").mozGetAll(65, undefined);
    155  request.onerror = errorHandler;
    156  request.onsuccess = grabEventAndContinueHandler;
    157  event = yield undefined;
    158 
    159  is(event.target.result instanceof Array, true, "Got an array object");
    160  is(event.target.result.length, 2, "Correct length");
    161 
    162  for (let i in event.target.result) {
    163    let result = event.target.result[i];
    164    let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
    165 
    166    is(result.name, testObj.name, "Correct name");
    167    is(result.height, testObj.height, "Correct height");
    168 
    169    if (testObj.hasOwnProperty("weight")) {
    170      is(result.weight, testObj.weight, "Correct weight");
    171    }
    172  }
    173 
    174  request = objectStore.index("height").mozGetAll();
    175  request.onerror = errorHandler;
    176  request.onsuccess = grabEventAndContinueHandler;
    177  event = yield undefined;
    178 
    179  is(event.target.result instanceof Array, true, "Got an array object");
    180  is(
    181    event.target.result.length,
    182    objectStoreDataHeightSort.length,
    183    "Correct length"
    184  );
    185 
    186  for (let i in event.target.result) {
    187    let result = event.target.result[i];
    188    let testObj = objectStoreDataHeightSort[i].value;
    189 
    190    is(result.name, testObj.name, "Correct name");
    191    is(result.height, testObj.height, "Correct height");
    192 
    193    if (testObj.hasOwnProperty("weight")) {
    194      is(result.weight, testObj.weight, "Correct weight");
    195    }
    196  }
    197 
    198  request = objectStore.index("height").mozGetAll(null, 4);
    199  request.onerror = errorHandler;
    200  request.onsuccess = grabEventAndContinueHandler;
    201  event = yield undefined;
    202 
    203  is(event.target.result instanceof Array, true, "Got an array object");
    204  is(event.target.result.length, 4, "Correct length");
    205 
    206  for (let i in event.target.result) {
    207    let result = event.target.result[i];
    208    let testObj = objectStoreDataHeightSort[i].value;
    209 
    210    is(result.name, testObj.name, "Correct name");
    211    is(result.height, testObj.height, "Correct height");
    212 
    213    if (testObj.hasOwnProperty("weight")) {
    214      is(result.weight, testObj.weight, "Correct weight");
    215    }
    216  }
    217 
    218  request = objectStore.index("height").mozGetAll(65, 1);
    219  request.onerror = errorHandler;
    220  request.onsuccess = grabEventAndContinueHandler;
    221  event = yield undefined;
    222 
    223  is(event.target.result instanceof Array, true, "Got an array object");
    224  is(event.target.result.length, 1, "Correct length");
    225 
    226  for (let i in event.target.result) {
    227    let result = event.target.result[i];
    228    let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
    229 
    230    is(result.name, testObj.name, "Correct name");
    231    is(result.height, testObj.height, "Correct height");
    232 
    233    if (testObj.hasOwnProperty("weight")) {
    234      is(result.weight, testObj.weight, "Correct weight");
    235    }
    236  }
    237 
    238  finishTest();
    239 }