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 | let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); |
michael@0 | 11 | request.onerror = errorHandler; |
michael@0 | 12 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 13 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 14 | |
michael@0 | 15 | let event = yield undefined; |
michael@0 | 16 | |
michael@0 | 17 | let db = event.target.result; |
michael@0 | 18 | |
michael@0 | 19 | for each (let autoIncrement in [false, true]) { |
michael@0 | 20 | let objectStore = |
michael@0 | 21 | db.createObjectStore(autoIncrement, { keyPath: "id", |
michael@0 | 22 | autoIncrement: autoIncrement }); |
michael@0 | 23 | objectStore.createIndex("", "index", { unique: true }); |
michael@0 | 24 | |
michael@0 | 25 | for (let i = 0; i < 10; i++) { |
michael@0 | 26 | objectStore.add({ id: i, index: i }); |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | event = yield undefined; |
michael@0 | 31 | is(event.type, "success", "expect a success event"); |
michael@0 | 32 | |
michael@0 | 33 | for each (let autoIncrement in [false, true]) { |
michael@0 | 34 | objectStore = db.transaction(autoIncrement, "readwrite") |
michael@0 | 35 | .objectStore(autoIncrement); |
michael@0 | 36 | |
michael@0 | 37 | request = objectStore.put({ id: 5, index: 6 }); |
michael@0 | 38 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 39 | request.addEventListener("error", new ExpectError("ConstraintError", true)); |
michael@0 | 40 | event = yield undefined; |
michael@0 | 41 | |
michael@0 | 42 | event.preventDefault(); |
michael@0 | 43 | |
michael@0 | 44 | let keyRange = IDBKeyRange.only(5); |
michael@0 | 45 | |
michael@0 | 46 | objectStore.index("").openCursor(keyRange).onsuccess = function(event) { |
michael@0 | 47 | let cursor = event.target.result; |
michael@0 | 48 | ok(cursor, "Must have a cursor here"); |
michael@0 | 49 | |
michael@0 | 50 | is(cursor.value.index, 5, "Still have the right index value"); |
michael@0 | 51 | |
michael@0 | 52 | cursor.value.index = 6; |
michael@0 | 53 | |
michael@0 | 54 | request = cursor.update(cursor.value); |
michael@0 | 55 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 56 | request.addEventListener("error", new ExpectError("ConstraintError", true)); |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | yield undefined; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | finishTest(); |
michael@0 | 63 | yield undefined; |
michael@0 | 64 | } |