dom/indexedDB/test/unit/test_names_sorted.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/unit/test_names_sorted.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +var testGenerator = testSteps();
    1.10 +
    1.11 +function testSteps()
    1.12 +{
    1.13 +  const name = this.window ? window.location.pathname : "Splendid Test";
    1.14 +  const objectStoreInfo = [
    1.15 +    { name: "foo", options: { keyPath: "id" }, location: 1 },
    1.16 +    { name: "bar", options: { keyPath: "id" }, location: 0 },
    1.17 +  ];
    1.18 +  const indexInfo = [
    1.19 +    { name: "foo", keyPath: "value", location: 1 },
    1.20 +    { name: "bar", keyPath: "value", location: 0 },
    1.21 +  ];
    1.22 +
    1.23 +  let request = indexedDB.open(name, 1);
    1.24 +  request.onerror = errorHandler;
    1.25 +  request.onupgradeneeded = grabEventAndContinueHandler;
    1.26 +  request.onsuccess = unexpectedSuccessHandler;
    1.27 +  let event = yield undefined;
    1.28 +  let db = event.target.result;
    1.29 +
    1.30 +  for (let i = 0; i < objectStoreInfo.length; i++) {
    1.31 +    let info = objectStoreInfo[i];
    1.32 +    let objectStore = info.hasOwnProperty("options") ?
    1.33 +                      db.createObjectStore(info.name, info.options) :
    1.34 +                      db.createObjectStore(info.name);
    1.35 +
    1.36 +    // Test index creation, and that it ends up in indexNames.
    1.37 +    let objectStoreName = info.name;
    1.38 +    for (let j = 0; j < indexInfo.length; j++) {
    1.39 +      let info = indexInfo[j];
    1.40 +      let count = objectStore.indexNames.length;
    1.41 +      let index = info.hasOwnProperty("options") ?
    1.42 +                  objectStore.createIndex(info.name, info.keyPath,
    1.43 +                                          info.options) :
    1.44 +                  objectStore.createIndex(info.name, info.keyPath);
    1.45 +    }
    1.46 +  }
    1.47 +
    1.48 +  request.onsuccess = grabEventAndContinueHandler;
    1.49 +  request.onupgradeneeded = unexpectedSuccessHandler;
    1.50 +
    1.51 +  event = yield undefined;
    1.52 +
    1.53 +  let objectStoreNames = []
    1.54 +  for (let i = 0; i < objectStoreInfo.length; i++) {
    1.55 +    let info = objectStoreInfo[i];
    1.56 +    objectStoreNames.push(info.name);
    1.57 +
    1.58 +    is(db.objectStoreNames[info.location], info.name,
    1.59 +       "Got objectStore name in the right location");
    1.60 +
    1.61 +    let trans = db.transaction(info.name);
    1.62 +    let objectStore = trans.objectStore(info.name);
    1.63 +    for (let j = 0; j < indexInfo.length; j++) {
    1.64 +      let info = indexInfo[j];
    1.65 +      is(objectStore.indexNames[info.location], info.name,
    1.66 +         "Got index name in the right location");
    1.67 +    }
    1.68 +  }
    1.69 +
    1.70 +  let trans = db.transaction(objectStoreNames);
    1.71 +  for (let i = 0; i < objectStoreInfo.length; i++) {
    1.72 +    let info = objectStoreInfo[i];
    1.73 +  
    1.74 +    is(trans.objectStoreNames[info.location], info.name,
    1.75 +       "Got objectStore name in the right location");
    1.76 +  }
    1.77 +
    1.78 +  db.close();
    1.79 +
    1.80 +  let request = indexedDB.open(name, 1);
    1.81 +  request.onerror = errorHandler;
    1.82 +  request.onsuccess = grabEventAndContinueHandler;
    1.83 +  request.onupgradeneeded = unexpectedSuccessHandler;
    1.84 +  let event = yield undefined;
    1.85 +
    1.86 +  let db = event.target.result;
    1.87 +
    1.88 +  let objectStoreNames = []
    1.89 +  for (let i = 0; i < objectStoreInfo.length; i++) {
    1.90 +    let info = objectStoreInfo[i];
    1.91 +    objectStoreNames.push(info.name);
    1.92 +
    1.93 +    is(db.objectStoreNames[info.location], info.name,
    1.94 +       "Got objectStore name in the right location");
    1.95 +
    1.96 +    let trans = db.transaction(info.name);
    1.97 +    let objectStore = trans.objectStore(info.name);
    1.98 +    for (let j = 0; j < indexInfo.length; j++) {
    1.99 +      let info = indexInfo[j];
   1.100 +      is(objectStore.indexNames[info.location], info.name,
   1.101 +         "Got index name in the right location");
   1.102 +    }
   1.103 +  }
   1.104 +
   1.105 +  let trans = db.transaction(objectStoreNames);
   1.106 +  for (let i = 0; i < objectStoreInfo.length; i++) {
   1.107 +    let info = objectStoreInfo[i];
   1.108 +  
   1.109 +    is(trans.objectStoreNames[info.location], info.name,
   1.110 +       "Got objectStore name in the right location");
   1.111 +  }
   1.112 +
   1.113 +  db.close();
   1.114 +
   1.115 +  finishTest();
   1.116 +  yield undefined;
   1.117 +}

mercurial