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 | |
michael@0 | 6 | var testGenerator = testSteps(); |
michael@0 | 7 | |
michael@0 | 8 | function testSteps() |
michael@0 | 9 | { |
michael@0 | 10 | const name = this.window ? window.location.pathname : "Splendid Test"; |
michael@0 | 11 | |
michael@0 | 12 | const objectStores = [ |
michael@0 | 13 | { name: "a", autoIncrement: false }, |
michael@0 | 14 | { name: "b", autoIncrement: true } |
michael@0 | 15 | ]; |
michael@0 | 16 | |
michael@0 | 17 | const indexes = [ |
michael@0 | 18 | { name: "a", options: { } }, |
michael@0 | 19 | { name: "b", options: { unique: true } } |
michael@0 | 20 | ]; |
michael@0 | 21 | |
michael@0 | 22 | var j = 0; |
michael@0 | 23 | for (let i in objectStores) { |
michael@0 | 24 | let request = indexedDB.open(name, ++j); |
michael@0 | 25 | request.onerror = errorHandler; |
michael@0 | 26 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 27 | let event = yield undefined; |
michael@0 | 28 | |
michael@0 | 29 | let db = event.target.result; |
michael@0 | 30 | |
michael@0 | 31 | let objectStore = |
michael@0 | 32 | db.createObjectStore(objectStores[i].name, |
michael@0 | 33 | { keyPath: "id", |
michael@0 | 34 | autoIncrement: objectStores[i].autoIncrement }); |
michael@0 | 35 | |
michael@0 | 36 | for (let j in indexes) { |
michael@0 | 37 | objectStore.createIndex(indexes[j].name, "name", indexes[j].options); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | let data = { name: "Ben" }; |
michael@0 | 41 | if (!objectStores[i].autoIncrement) { |
michael@0 | 42 | data.id = 1; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | request = objectStore.add(data); |
michael@0 | 46 | request.onerror = errorHandler; |
michael@0 | 47 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 48 | event = yield undefined; |
michael@0 | 49 | |
michael@0 | 50 | ok(event.target.result == 1 || event.target.result == 2, "Good id"); |
michael@0 | 51 | db.close(); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | executeSoon(function() { testGenerator.next(); }); |
michael@0 | 55 | yield undefined; |
michael@0 | 56 | |
michael@0 | 57 | let request = indexedDB.open(name, j); |
michael@0 | 58 | request.onerror = errorHandler; |
michael@0 | 59 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 60 | let event = yield undefined; |
michael@0 | 61 | |
michael@0 | 62 | let db = event.target.result; |
michael@0 | 63 | |
michael@0 | 64 | for (let i in objectStores) { |
michael@0 | 65 | for (let j in indexes) { |
michael@0 | 66 | let objectStore = db.transaction(objectStores[i].name) |
michael@0 | 67 | .objectStore(objectStores[i].name); |
michael@0 | 68 | let index = objectStore.index(indexes[j].name); |
michael@0 | 69 | |
michael@0 | 70 | request = index.openCursor(); |
michael@0 | 71 | request.onerror = errorHandler; |
michael@0 | 72 | request.onsuccess = function (event) { |
michael@0 | 73 | is(event.target.result.value.name, "Ben", "Good object"); |
michael@0 | 74 | executeSoon(function() { testGenerator.next(); }); |
michael@0 | 75 | } |
michael@0 | 76 | yield undefined; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | finishTest(); |
michael@0 | 81 | yield undefined; |
michael@0 | 82 | } |
michael@0 | 83 |