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

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

<!DOCTYPE html>
<html>
<!--
Copyright 2017 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 blobs use space when created and free up space when deleted</title>
<script src="common.js"></script>
<script>

// Constants.
var store_name = 'blobs';
var blob_key = 'blob_key';
var blob_size = 4 * 1024 * 1024;  // 4MB

// Shared variables.
var db;

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

function prepareDatabase() {
  db = event.target.result;
  db.createObjectStore(store_name);
}

function putBlob() {
  debug("Writing blob.");

  var trans = db.transaction(store_name, 'readwrite');
  trans.onabort = unexpectedAbortCallback;
  trans.oncomplete = done;

  var data = new Array(1 + blob_size).join("X");
  var blob = new Blob([data]);
  var request = trans.objectStore(store_name).put(blob, blob_key);
  request.onerror = unexpectedErrorCallback;
}

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