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("Tests IndexedDB's quota enforcing mechanism.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('database-quota')");
     20     request.onsuccess = openSuccess;
     21     request.onerror = unexpectedErrorCallback;
     22 }
     23 
     24 function openSuccess()
     25 {
     26     window.db = evalAndLog("db = event.target.result");
     27 
     28     request = evalAndLog("db.setVersion('new version')");
     29     request.onsuccess = setVersionSuccess;
     30     request.onerror = unexpectedErrorCallback;
     31 }
     32 
     33 function setVersionSuccess()
     34 {
     35     debug("setVersionSuccess():");
     36     window.trans = evalAndLog("trans = event.target.result");
     37     shouldBeTrue("trans !== null");
     38     trans.onabort = unexpectedAbortCallback;
     39 
     40     deleteAllObjectStores(db);
     41 
     42     shouldBeEqualToString("db.version", "new version");
     43     shouldBeEqualToString("db.name", "database-quota");
     44     shouldBe("db.objectStoreNames", "[]");
     45     shouldBe("db.objectStoreNames.length", "0");
     46     shouldBe("db.objectStoreNames.contains('')", "false");
     47 
     48     objectStore = evalAndLog('db.createObjectStore("test123")');
     49     checkObjectStore();
     50     commitAndContinue();
     51 }
     52 
     53 function checkObjectStore()
     54 {
     55     shouldBe("db.objectStoreNames", "['test123']");
     56     shouldBe("db.objectStoreNames.length", "1");
     57     shouldBe("db.objectStoreNames.contains('')", "false");
     58     shouldBe("db.objectStoreNames.contains('test456')", "false");
     59     shouldBe("db.objectStoreNames.contains('test123')", "true");
     60 }
     61 
     62 function commitAndContinue()
     63 {
     64     window.setTimeout(checkQuotaEnforcing, 0);
     65 }
     66 
     67 function checkQuotaEnforcing()
     68 {
     69     var trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     70     trans.onabort = testComplete;
     71     trans.oncomplete = unexpectedCompleteCallback;
     72     debug("Creating 'data' which contains 64K of data");
     73     window.data = "X";
     74     for (var i = 0; i < 16; i++)
     75         data += data;
     76     shouldBe("data.length", "65536");
     77     window.dataAdded = 0;
     78     window.store = evalAndLog("store = trans.objectStore('test123')");
     79     addData();
     80 }
     81 
     82 function addData()
     83 {
     84     if (dataAdded < 5 * 1024 * 1024) {
     85         if (dataAdded > 0)
     86             store = event.target.source;
     87     } else {
     88         testFailed("added more than quota");
     89         done();
     90         return;
     91     }
     92     dataAdded += 65536;
     93     request = store.add({x: data}, dataAdded);
     94     request.onsuccess = addData;
     95     request.onerror = logError;
     96 }
     97 
     98 function logError()
     99 {
    100     debug("Error function called: (" + event.code + ") " + event.message);
    101     evalAndLog("event.preventDefault()");
    102 }
    103 
    104 function testComplete()
    105 {
    106     testPassed("Adding data failed due to quota error. Data added was about " + Math.round(dataAdded / 1024 / 1024) + " MB");
    107     done();
    108 }
    109 
    110 test();
    111 
    112 var successfullyParsed = true;
    113 
    114 </script>
    115 </body>
    116 </html>
    117