1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65

content / test / data / indexeddb / fill_quota.html [blame]

<!DOCTYPE html>
<html>
<!--
Copyright 2023 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>IDB test that origins over quota aren't trapped Part 1 / 2</title>
<script type="text/javascript" src="common.js"></script>
<script>

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

function prepareDatabase()
{
  db = event.target.result;
  objectStore = db.createObjectStore("test123");
  data = generateRandomString(1);
  numTransactions = 0;
}

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

  var trans = db.transaction(['test123'], 'readwrite');
  trans.onabort = e => {
    if (trans.error.name === 'QuotaExceededError') done();
    else fail('unexpected error ' + trans.error.name);
  };
  trans.oncomplete = getQuotaAndUsage;
  var store = trans.objectStore('test123');
  request = store.put({x: numTransactions, data: 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));
  startNewTransaction();
}

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>