Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 READ_WRITE = "readwrite"; |
michael@0 | 16 | |
michael@0 | 17 | const name = window.location.pathname; |
michael@0 | 18 | |
michael@0 | 19 | const objectStoreName = "Blobs"; |
michael@0 | 20 | |
michael@0 | 21 | getUsage(grabFileUsageAndContinueHandler); |
michael@0 | 22 | let startUsage = yield undefined; |
michael@0 | 23 | |
michael@0 | 24 | const fileData1 = { |
michael@0 | 25 | key: 1, |
michael@0 | 26 | obj: { id: 1, file: getRandomFile("random.bin", 100000) } |
michael@0 | 27 | }; |
michael@0 | 28 | const fileData2 = { |
michael@0 | 29 | key: 2, |
michael@0 | 30 | obj: { id: 1, file: getRandomFile("random.bin", 100000) } |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | { |
michael@0 | 34 | let request = indexedDB.open(name, 1); |
michael@0 | 35 | request.onerror = errorHandler; |
michael@0 | 36 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 37 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 38 | let event = yield undefined; |
michael@0 | 39 | |
michael@0 | 40 | is(event.type, "upgradeneeded", "Got correct event type"); |
michael@0 | 41 | |
michael@0 | 42 | let db = event.target.result; |
michael@0 | 43 | db.onerror = errorHandler; |
michael@0 | 44 | |
michael@0 | 45 | let objectStore = db.createObjectStore(objectStoreName, { }); |
michael@0 | 46 | |
michael@0 | 47 | objectStore.createIndex("index", "id", { unique: true }); |
michael@0 | 48 | |
michael@0 | 49 | objectStore.add(fileData1.obj, fileData1.key); |
michael@0 | 50 | |
michael@0 | 51 | request = objectStore.add(fileData2.obj, fileData2.key); |
michael@0 | 52 | request.addEventListener("error", new ExpectError("ConstraintError", true)); |
michael@0 | 53 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 54 | yield undefined; |
michael@0 | 55 | |
michael@0 | 56 | event = yield undefined; |
michael@0 | 57 | |
michael@0 | 58 | is(event.type, "success", "Got correct event type"); |
michael@0 | 59 | |
michael@0 | 60 | getUsage(grabFileUsageAndContinueHandler); |
michael@0 | 61 | let usage = yield undefined; |
michael@0 | 62 | |
michael@0 | 63 | is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size, |
michael@0 | 64 | "Correct file usage"); |
michael@0 | 65 | |
michael@0 | 66 | let trans = db.transaction([objectStoreName], READ_WRITE); |
michael@0 | 67 | trans.objectStore(objectStoreName).delete(fileData1.key); |
michael@0 | 68 | trans.oncomplete = grabEventAndContinueHandler; |
michael@0 | 69 | event = yield undefined; |
michael@0 | 70 | |
michael@0 | 71 | is(event.type, "complete", "Got correct event type"); |
michael@0 | 72 | |
michael@0 | 73 | getUsage(grabFileUsageAndContinueHandler); |
michael@0 | 74 | usage = yield undefined; |
michael@0 | 75 | |
michael@0 | 76 | is(usage, startUsage + fileData1.obj.file.size + fileData2.obj.file.size, |
michael@0 | 77 | "OS files exists"); |
michael@0 | 78 | |
michael@0 | 79 | fileData1.obj.file = null; |
michael@0 | 80 | fileData2.obj.file = null; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | scheduleGC(); |
michael@0 | 84 | yield undefined; |
michael@0 | 85 | |
michael@0 | 86 | getUsage(grabFileUsageAndContinueHandler); |
michael@0 | 87 | let endUsage = yield undefined; |
michael@0 | 88 | |
michael@0 | 89 | is(endUsage, startUsage, "OS files deleted"); |
michael@0 | 90 | |
michael@0 | 91 | finishTest(); |
michael@0 | 92 | yield undefined; |
michael@0 | 93 | } |
michael@0 | 94 | </script> |
michael@0 | 95 | <script type="text/javascript;version=1.7" src="file.js"></script> |
michael@0 | 96 | <script type="text/javascript;version=1.7" src="helpers.js"></script> |
michael@0 | 97 | |
michael@0 | 98 | </head> |
michael@0 | 99 | |
michael@0 | 100 | <body onload="runTest();"></body> |
michael@0 | 101 | |
michael@0 | 102 | </html> |