dom/indexedDB/test/unit/test_index_getAllObjects.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial