chromium/content/test/data/indexeddb/fill_up_5k.html

<!DOCTYPE html>
<html>
<!--
Copyright 2013 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<script type="text/javascript" src="common.js"></script>
<script>

function test() {
  indexedDBTest(prepareDatabase, startNewTransaction);
}

function prepareDatabase()
{
  db = event.target.result;
  objectStore = db.createObjectStore("test123");
  var len = 1024;
  data = Array(1+len).join("X");
  numTransactions = 0;
}

function startNewTransaction() {
  debug("Starting new transaction.");

  var trans = db.transaction(['test123'], 'readwrite');
  trans.onabort = unexpectedAbortCallback;
  trans.oncomplete = getQuotaAndUsage;
  var store = trans.objectStore('test123');
  request = store.put({x: data}, numTransactions);
  request.onerror = unexpectedErrorCallback;
}

function getQuotaAndUsage() {
  numTransactions++;
  navigator.webkitTemporaryStorage.queryUsageAndQuota(
    usageCallback, unexpectedErrorCallback);
}

function usageCallback(usage, quota) {
  debug("Transaction finished.");
  returnedUsage = usage;
  returnedQuota = quota;
  debug("Allotted quota is " + displaySize(returnedQuota));
  debug("LevelDB usage is " + displaySize(returnedUsage));
  if (returnedUsage < 5 * 1024)
    startNewTransaction();
  else
    done("Filled up " + returnedUsage);
}

function displaySize(bytes) {
  var k = bytes / 1024;
  var m = k / 1024;
  return bytes + " (" + k + "k) (" + m + "m)";
}

</script>
</head>
<body onLoad="test()">
<div id="status">Starting...</div>
</body>
</html>