dom/indexedDB/test/unit/test_objectStore_remove_values.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 var data = [
michael@0 13 { name: "inline key; key generator",
michael@0 14 autoIncrement: true,
michael@0 15 storedObject: {name: "Lincoln"},
michael@0 16 keyName: "id",
michael@0 17 keyValue: undefined,
michael@0 18 },
michael@0 19 { name: "inline key; no key generator",
michael@0 20 autoIncrement: false,
michael@0 21 storedObject: {id: 1, name: "Lincoln"},
michael@0 22 keyName: "id",
michael@0 23 keyValue: undefined,
michael@0 24 },
michael@0 25 { name: "out of line key; key generator",
michael@0 26 autoIncrement: true,
michael@0 27 storedObject: {name: "Lincoln"},
michael@0 28 keyName: undefined,
michael@0 29 keyValue: undefined,
michael@0 30 },
michael@0 31 { name: "out of line key; no key generator",
michael@0 32 autoIncrement: false,
michael@0 33 storedObject: {name: "Lincoln"},
michael@0 34 keyName: null,
michael@0 35 keyValue: 1,
michael@0 36 }
michael@0 37 ];
michael@0 38
michael@0 39 for (let i = 0; i < data.length; i++) {
michael@0 40 let test = data[i];
michael@0 41
michael@0 42 let request = indexedDB.open(name, i+1);
michael@0 43 request.onerror = errorHandler;
michael@0 44 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 45 let event = yield undefined;
michael@0 46
michael@0 47 let db = event.target.result;
michael@0 48
michael@0 49 let objectStore = db.createObjectStore(test.name,
michael@0 50 { keyPath: test.keyName,
michael@0 51 autoIncrement: test.autoIncrement });
michael@0 52
michael@0 53 request = objectStore.add(test.storedObject, test.keyValue);
michael@0 54 request.onerror = errorHandler;
michael@0 55 request.onsuccess = grabEventAndContinueHandler;
michael@0 56 event = yield undefined;
michael@0 57
michael@0 58 let id = event.target.result;
michael@0 59 request = objectStore.get(id);
michael@0 60 request.onerror = errorHandler;
michael@0 61 request.onsuccess = grabEventAndContinueHandler;
michael@0 62 event = yield undefined;
michael@0 63
michael@0 64 // Sanity check!
michael@0 65 is(test.storedObject.name, event.target.result.name,
michael@0 66 "The correct object was stored.");
michael@0 67
michael@0 68 request = objectStore.delete(id);
michael@0 69 request.onerror = errorHandler;
michael@0 70 request.onsuccess = grabEventAndContinueHandler;
michael@0 71 event = yield undefined;
michael@0 72
michael@0 73 // Make sure it was removed.
michael@0 74 request = objectStore.get(id);
michael@0 75 request.onerror = errorHandler;
michael@0 76 request.onsuccess = grabEventAndContinueHandler;
michael@0 77 event = yield undefined;
michael@0 78
michael@0 79 ok(event.target.result === undefined, "Object was deleted");
michael@0 80 db.close();
michael@0 81 }
michael@0 82
michael@0 83 finishTest();
michael@0 84 yield undefined;
michael@0 85 }
michael@0 86

mercurial