1 <!DOCTYPE html> 2 <html> 3 <head> 4 <!-- 5 Copyright 2013 The Chromium Authors. All rights reserved. 6 Use of this source code is governed by a BSD-style license that can be 7 found in the LICENSE file. 8 --> 9 <title>IDB test that database deletion triggers a compaction</title> 10 <script type="text/javascript" src="common.js"></script> 11 <script> 12 13 var dbname = 'delete_compact'; 14 15 // Follow navigation requests from the browser test. 16 window.onhashchange = test; 17 18 function test() 19 { 20 if (location.hash === '#fill') 21 fill(); 22 else if (location.hash === '#purge') 23 purge(); 24 else if (location.hash !== '#pass' && location.hash !== '#fail') 25 fail('unexpected hash'); 26 } 27 28 function fill() 29 { 30 var bytes = 0; 31 var request = indexedDB.open(dbname); 32 request.onupgradeneeded = function() { 33 var db = request.result; 34 var store = db.createObjectStore('store'); 35 var kilobyte = Array(512+1).join('\u0100'); // 2 bytes in UTF-8 or UTF-16. 36 var megabyte = Array(1024+1).join(kilobyte); 37 for (var i = 0; i < 5; ++i) { 38 store.put(megabyte, i); 39 bytes += 1024 * 1024; 40 } 41 }; 42 request.onsuccess = function() { 43 var db = request.result; 44 db.close(); 45 done('filled with ' + bytes + ' bytes'); 46 }; 47 } 48 49 function purge() 50 { 51 var request = indexedDB.deleteDatabase(dbname); 52 request.onsuccess = function() { 53 done('purged'); 54 }; 55 } 56 57 </script> 58 </head> 59 <body onload="test()"> 60 <div id="status">Starting...</div> 61 </body> 62 </html> 63