Home | History | Annotate | Download | only in indexeddb
      1 <html>
      2 <head>
      3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
      4 <script src="../../fast/js/resources/js-test-pre.js"></script>
      5 <script src="../../fast/js/resources/js-test-post-function.js"></script>
      6 <script src="resources/shared.js"></script>
      7 </head>
      8 <body>
      9 <p id="description"></p>
     10 <div id="console"></div>
     11 <script>
     12 
     13 description("Verify that you can put the same data in 2 different databases without uniqueness constraints firing.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 testCount = 0;
     18 function test()
     19 {
     20     if (testCount++ == 0)
     21         request = evalAndLog("webkitIndexedDB.open('duplicates-1')");
     22     else
     23         request = evalAndLog("webkitIndexedDB.open('duplicates-2')");
     24     request.onsuccess = setVersion;
     25     request.onerror = unexpectedErrorCallback;
     26 }
     27 
     28 function setVersion()
     29 {
     30     db = evalAndLog("db = event.target.result");
     31 
     32     request = evalAndLog("db.setVersion('new version')");
     33     request.onsuccess = deleteExisting;
     34     request.onerror = unexpectedErrorCallback;
     35 }
     36 
     37 function deleteExisting()
     38 {
     39     debug("setVersionSuccess():");
     40     window.trans = evalAndLog("trans = event.target.result");
     41     shouldBeTrue("trans !== null");
     42     trans.onabort = unexpectedAbortCallback;
     43 
     44     deleteAllObjectStores(db);
     45 
     46     window.store = evalAndLog("db.createObjectStore('storeName', null)");
     47     window.indexObject = evalAndLog("store.createIndex('indexName', 'x')");
     48     addData();
     49 }
     50 
     51 function addData()
     52 {
     53     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     54     request.onsuccess = addMore;
     55     request.onerror = unexpectedErrorCallback;
     56 }
     57 
     58 function addMore()
     59 {
     60     request = evalAndLog("event.target.source.add({x: 'value2', y: 'zzz2'}, 'key2')");
     61     request.onsuccess = getData;
     62     request.onerror = unexpectedErrorCallback;
     63 }
     64 
     65 function getData()
     66 {
     67     request = evalAndLog("indexObject.getKey('value')");
     68     request.onsuccess = getObjectData;
     69     request.onerror = unexpectedErrorCallback;
     70 }
     71 
     72 function getObjectData()
     73 {
     74     shouldBeEqualToString("event.target.result", "key");
     75 
     76     request = evalAndLog("indexObject.get('value')");
     77     request.onsuccess = getDataFail;
     78     request.onerror = unexpectedErrorCallback;
     79 }
     80 
     81 function getDataFail()
     82 {
     83     shouldBeEqualToString("event.target.result.x", "value");
     84     shouldBeEqualToString("event.target.result.y", "zzz");
     85 
     86     request = evalAndLog("indexObject.getKey('does not exist')");
     87     request.onsuccess = unexpectedSuccessCallback;
     88     request.onerror = getObjectDataFail;
     89 }
     90 
     91 function getObjectDataFail()
     92 {
     93     shouldBe("event.target.errorCode", "webkitIDBDatabaseException.NOT_FOUND_ERR");
     94 
     95     evalAndLog("event.preventDefault()");
     96 
     97     request = evalAndLog("indexObject.get('does not exist')");
     98     request.onsuccess = unexpectedSuccessCallback;
     99     request.onerror = openKeyCursor;
    100 }
    101 
    102 function openKeyCursor()
    103 {
    104     shouldBe("event.target.errorCode", "webkitIDBDatabaseException.NOT_FOUND_ERR");
    105 
    106     evalAndLog("event.preventDefault()");
    107 
    108     window.request = evalAndLog("indexObject.openKeyCursor()");
    109     request.onsuccess = cursor1Continue;
    110     request.onerror = unexpectedErrorCallback;
    111 }
    112 
    113 function cursor1Continue()
    114 {
    115     shouldBeFalse("event.target.result === null");
    116     shouldBeEqualToString("event.target.result.key", "value");
    117     shouldBeEqualToString("event.target.result.primaryKey", "key");
    118 
    119     // We re-use the last request object.
    120     evalAndLog("event.target.result.continue()");
    121     window.request.onsuccess = cursor1Continue2;
    122 }
    123 
    124 function cursor1Continue2()
    125 {
    126     shouldBeFalse("event.target.result === null");
    127     shouldBeEqualToString("event.target.result.key", "value2");
    128     shouldBeEqualToString("event.target.result.primaryKey", "key2");
    129 
    130     // We re-use the last request object.
    131     evalAndLog("event.target.result.continue()");
    132     window.request.onsuccess = openObjectCursor;
    133 }
    134 
    135 function openObjectCursor()
    136 {
    137     shouldBeTrue("event.target.result === null");
    138 
    139     window.request = evalAndLog("indexObject.openCursor()");
    140     request.onsuccess = cursor2Continue;
    141     request.onerror = unexpectedErrorCallback;
    142 }
    143 
    144 function cursor2Continue()
    145 {
    146     shouldBeFalse("event.target.result === null");
    147     shouldBeEqualToString("event.target.result.key", "value");
    148     shouldBeEqualToString("event.target.result.value.x", "value");
    149     shouldBeEqualToString("event.target.result.value.y", "zzz");
    150 
    151     // We re-use the last request object.
    152     evalAndLog("event.target.result.continue()");
    153     window.request.onsuccess = cursor2Continue2;
    154 }
    155 
    156 function cursor2Continue2()
    157 {
    158     shouldBeFalse("event.target.result === null");
    159     shouldBeEqualToString("event.target.result.key", "value2");
    160     shouldBeEqualToString("event.target.result.value.x", "value2");    
    161     shouldBeEqualToString("event.target.result.value.y", "zzz2");
    162 
    163     // We re-use the last request object.
    164     evalAndLog("event.target.result.continue()");
    165     window.request.onsuccess = last;
    166 }
    167 
    168 function last()
    169 {
    170     shouldBeTrue("event.target.result === null");
    171 
    172     if (testCount == 1)
    173         test();
    174     else
    175         done();
    176 }
    177 
    178 test();
    179 
    180 var successfullyParsed = true;
    181 
    182 </script>
    183 </body>
    184 </html>
    185