1 <!DOCTYPE html> 2 <html> 3 <!-- 4 Copyright (c) 2013 The Chromium Authors. All rights reserved. 5 Use of this source code is governed by a BSD-style license that can be 6 found in the LICENSE file. 7 --> 8 <head> 9 <title>IDB test that origins over quota aren't trapped Part 1 / 2</title> 10 <script type="text/javascript" src="common.js"></script> 11 <script> 12 13 function test() { 14 indexedDBTest(prepareDatabase, startNewTransaction); 15 } 16 17 function prepareDatabase() 18 { 19 db = event.target.result; 20 objectStore = db.createObjectStore("test123"); 21 var len = 1024; 22 data = Array(1+len).join("X"); 23 numTransactions = 0; 24 } 25 26 function startNewTransaction() { 27 debug("Starting new transaction."); 28 29 var trans = db.transaction(['test123'], 'readwrite'); 30 trans.onabort = unexpectedAbortCallback; 31 trans.oncomplete = getQuotaAndUsage; 32 var store = trans.objectStore('test123'); 33 request = store.put({x: data}, numTransactions); 34 request.onerror = unexpectedErrorCallback; 35 } 36 37 function getQuotaAndUsage() { 38 numTransactions++; 39 webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, 40 usageCallback, unexpectedErrorCallback); 41 } 42 43 function usageCallback(usage, quota) { 44 debug("Transaction finished."); 45 returnedUsage = usage; 46 returnedQuota = quota; 47 debug("Allotted quota is " + displaySize(returnedQuota)); 48 debug("LevelDB usage is " + displaySize(returnedUsage)); 49 if (returnedUsage < 5 * 1024) 50 startNewTransaction(); 51 else 52 done("Filled up " + returnedUsage); 53 } 54 55 function displaySize(bytes) { 56 var k = bytes / 1024; 57 var m = k / 1024; 58 return bytes + " (" + k + "k) (" + m + "m)"; 59 } 60 61 </script> 62 </head> 63 <body onLoad="test()"> 64 <div id="status">Starting...</div> 65 </body> 66 </html> 67