dom/indexedDB/test/unit/test_open_for_principal.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 const objectStoreName = "Foo";
michael@0 13
michael@0 14 const data = { key: 1, value: "bar" };
michael@0 15
michael@0 16 let request = indexedDB.open(name, 1);
michael@0 17 request.onerror = errorHandler;
michael@0 18 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 19 request.onsuccess = grabEventAndContinueHandler;
michael@0 20 let event = yield undefined;
michael@0 21
michael@0 22 is(event.type, "upgradeneeded", "Got correct event type");
michael@0 23
michael@0 24 let db = event.target.result;
michael@0 25 db.onerror = errorHandler;
michael@0 26
michael@0 27 let objectStore = db.createObjectStore(objectStoreName, { });
michael@0 28
michael@0 29 event = yield undefined;
michael@0 30
michael@0 31 is(event.type, "success", "Got correct event type");
michael@0 32
michael@0 33 objectStore = db.transaction([objectStoreName], "readwrite")
michael@0 34 .objectStore(objectStoreName);
michael@0 35
michael@0 36 request = objectStore.get(data.key);
michael@0 37 request.onsuccess = grabEventAndContinueHandler;
michael@0 38 event = yield undefined;
michael@0 39
michael@0 40 is(event.target.result, null, "Got no data");
michael@0 41
michael@0 42 request = objectStore.add(data.value, data.key);
michael@0 43 request.onsuccess = grabEventAndContinueHandler;
michael@0 44 event = yield undefined;
michael@0 45
michael@0 46 is(event.target.result, data.key, "Got correct key");
michael@0 47
michael@0 48 let uri = Components.classes["@mozilla.org/network/io-service;1"]
michael@0 49 .getService(Components.interfaces.nsIIOService)
michael@0 50 .newURI("http://appdata.example.com", null, null);
michael@0 51 let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
michael@0 52 .getService(Components.interfaces.nsIScriptSecurityManager)
michael@0 53 .getNoAppCodebasePrincipal(uri);
michael@0 54
michael@0 55 request = indexedDB.openForPrincipal(principal, name, 1);
michael@0 56 request.onerror = errorHandler;
michael@0 57 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 58 request.onsuccess = grabEventAndContinueHandler;
michael@0 59 let event = yield undefined;
michael@0 60
michael@0 61 is(event.type, "upgradeneeded", "Got correct event type");
michael@0 62
michael@0 63 db = event.target.result;
michael@0 64 db.onerror = errorHandler;
michael@0 65
michael@0 66 objectStore = db.createObjectStore(objectStoreName, { });
michael@0 67
michael@0 68 event = yield undefined;
michael@0 69
michael@0 70 is(event.type, "success", "Got correct event type");
michael@0 71
michael@0 72 objectStore = db.transaction([objectStoreName])
michael@0 73 .objectStore(objectStoreName);
michael@0 74
michael@0 75 request = objectStore.get(data.key);
michael@0 76 request.onsuccess = grabEventAndContinueHandler;
michael@0 77 event = yield undefined;
michael@0 78
michael@0 79 is(event.target.result, null, "Got no data");
michael@0 80
michael@0 81 db.close();
michael@0 82
michael@0 83 request = indexedDB.deleteForPrincipal(principal, name);
michael@0 84 request.onerror = errorHandler;
michael@0 85 request.onsuccess = grabEventAndContinueHandler
michael@0 86 event = yield undefined;
michael@0 87
michael@0 88 finishTest();
michael@0 89 yield undefined;
michael@0 90 }

mercurial