dom/indexedDB/test/test_file_replace.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!--
michael@0 2 Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 -->
michael@0 5 <html>
michael@0 6 <head>
michael@0 7 <title>Indexed Database Property Test</title>
michael@0 8
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11
michael@0 12 <script type="text/javascript;version=1.7">
michael@0 13 function testSteps()
michael@0 14 {
michael@0 15 const name = window.location.pathname;
michael@0 16
michael@0 17 const objectStoreName = "Blobs";
michael@0 18
michael@0 19 const blobData = { key: 42, blobs: [] };
michael@0 20
michael@0 21 for (let i = 0; i < 100; i++) {
michael@0 22 blobData.blobs[i] = getRandomBlob(i);
michael@0 23 }
michael@0 24
michael@0 25 let request = indexedDB.open(name, 1);
michael@0 26 request.onerror = errorHandler;
michael@0 27 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 28 request.onsuccess = grabEventAndContinueHandler;
michael@0 29 let event = yield undefined;
michael@0 30
michael@0 31 is(event.type, "upgradeneeded", "Got correct event type");
michael@0 32
michael@0 33 let db = event.target.result;
michael@0 34 db.onerror = errorHandler;
michael@0 35
michael@0 36 let objectStore = db.createObjectStore(objectStoreName, { });
michael@0 37
michael@0 38 for (let i = 0; i < blobData.blobs.length; i++) {
michael@0 39 objectStore.put(blobData.blobs[i], blobData.key);
michael@0 40 }
michael@0 41
michael@0 42 event = yield undefined;
michael@0 43
michael@0 44 is(event.type, "success", "Got correct event type");
michael@0 45
michael@0 46 for (let id = 1; id <= 100; id++) {
michael@0 47 let refs = {};
michael@0 48 let dbRefs = {};
michael@0 49 let hasFileInfo = utils.getFileReferences(name, id, null, refs, dbRefs);
michael@0 50 ok(hasFileInfo, "Has file info");
michael@0 51 is(refs.value, 1, "Correct ref count");
michael@0 52 is(dbRefs.value, id / 100 >> 0, "Correct db ref count");
michael@0 53 }
michael@0 54
michael@0 55 finishTest();
michael@0 56 yield undefined;
michael@0 57 }
michael@0 58 </script>
michael@0 59 <script type="text/javascript;version=1.7" src="file.js"></script>
michael@0 60 <script type="text/javascript;version=1.7" src="helpers.js"></script>
michael@0 61
michael@0 62 </head>
michael@0 63
michael@0 64 <body onload="runTest();"></body>
michael@0 65
michael@0 66 </html>

mercurial