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("Test that data inserted into IndexedDB does not get corrupted on disk.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('data-corruption')");
     20     request.onsuccess = openSuccess;
     21     request.onerror = unexpectedErrorCallback;
     22 }
     23 
     24 function openSuccess()
     25 {
     26     debug("openSuccess():");
     27     window.db = evalAndLog("db = event.target.result");
     28 
     29     request = evalAndLog("db.setVersion('new version')");
     30     request.onsuccess = setVersionSuccess;
     31     request.onerror = unexpectedErrorCallback;
     32 }
     33 
     34 function setVersionSuccess()
     35 {
     36     debug("setVersionSuccess():");
     37     window.trans = evalAndLog("trans = event.target.result");
     38     shouldBeTrue("trans !== null");
     39     trans.onabort = unexpectedAbortCallback;
     40     trans.oncomplete = addData;
     41 
     42     deleteAllObjectStores(db);
     43 
     44     evalAndLog("db.createObjectStore('storeName')");
     45 }
     46 
     47 var testDate = new Date('February 24, 1955 12:00:08');
     48 
     49 function addData()
     50 {
     51     debug("addData():");
     52     var transaction = evalAndLog("transaction = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     53     var request = evalAndLog("request = transaction.objectStore('storeName').add({x: testDate}, 'key')");
     54     request.onerror = unexpectedErrorCallback;
     55     transaction.oncomplete = getData;
     56 }
     57 
     58 function getData()
     59 {
     60     debug("addData():");
     61     var transaction = evalAndLog("transaction = db.transaction([], webkitIDBTransaction.READ_ONLY)");
     62     var request = evalAndLog("request = transaction.objectStore('storeName').get('key')");
     63     request.onerror = unexpectedErrorCallback;
     64     request.onsuccess = doCheck;
     65 }
     66 
     67 function doCheck()
     68 {
     69     shouldBeTrue("event.target.result.x.toString() == testDate.toString()");
     70     done();
     71 }
     72 
     73 test();
     74 
     75 var successfullyParsed = true;
     76 
     77 </script>
     78 </body>
     79 </html>
     80