dom/indexedDB/test/unit/test_readonly_transactions.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 if (!this.window) {
michael@0 7 this.runTest = function() {
michael@0 8 todo(false, "Test disabled in xpcshell test suite for now");
michael@0 9 finishTest();
michael@0 10 }
michael@0 11 }
michael@0 12
michael@0 13 var testGenerator = testSteps();
michael@0 14
michael@0 15 function testSteps()
michael@0 16 {
michael@0 17 const name = this.window ? window.location.pathname : "Splendid Test";
michael@0 18 const osName = "foo";
michael@0 19
michael@0 20 let request = indexedDB.open(name, 1);
michael@0 21 request.onerror = errorHandler;
michael@0 22 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 23 request.onsuccess = grabEventAndContinueHandler;
michael@0 24 let event = yield undefined;
michael@0 25
michael@0 26 let db = event.target.result;
michael@0 27 is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
michael@0 28
michael@0 29 db.createObjectStore(osName, { autoIncrement: "true" });
michael@0 30
michael@0 31 yield undefined;
michael@0 32
michael@0 33 let key1, key2;
michael@0 34
michael@0 35 request = db.transaction([osName], "readwrite")
michael@0 36 .objectStore(osName)
michael@0 37 .add({});
michael@0 38 request.onerror = errorHandler;
michael@0 39 request.onsuccess = function(event) {
michael@0 40 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 41 key1 = event.target.result;
michael@0 42 testGenerator.next();
michael@0 43 }
michael@0 44 yield undefined;
michael@0 45
michael@0 46 request = db.transaction(osName, "readwrite").objectStore(osName).add({});
michael@0 47 request.onerror = errorHandler;
michael@0 48 request.onsuccess = function(event) {
michael@0 49 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 50 key2 = event.target.result;
michael@0 51 testGenerator.next();
michael@0 52 }
michael@0 53 yield undefined;
michael@0 54
michael@0 55 request = db.transaction([osName], "readwrite")
michael@0 56 .objectStore(osName)
michael@0 57 .put({}, key1);
michael@0 58 request.onerror = errorHandler;
michael@0 59 request.onsuccess = function(event) {
michael@0 60 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 61 testGenerator.next();
michael@0 62 }
michael@0 63 yield undefined;
michael@0 64
michael@0 65 request = db.transaction(osName, "readwrite")
michael@0 66 .objectStore(osName)
michael@0 67 .put({}, key2);
michael@0 68 request.onerror = errorHandler;
michael@0 69 request.onsuccess = function(event) {
michael@0 70 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 71 testGenerator.next();
michael@0 72 }
michael@0 73 yield undefined;
michael@0 74
michael@0 75 request = db.transaction([osName], "readwrite")
michael@0 76 .objectStore(osName)
michael@0 77 .put({}, key1);
michael@0 78 request.onerror = errorHandler;
michael@0 79 request.onsuccess = function(event) {
michael@0 80 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 81 testGenerator.next();
michael@0 82 }
michael@0 83 yield undefined;
michael@0 84
michael@0 85 request = db.transaction(osName, "readwrite")
michael@0 86 .objectStore(osName)
michael@0 87 .put({}, key1);
michael@0 88 request.onerror = errorHandler;
michael@0 89 request.onsuccess = function(event) {
michael@0 90 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 91 testGenerator.next();
michael@0 92 }
michael@0 93 yield undefined;
michael@0 94
michael@0 95 request = db.transaction([osName], "readwrite")
michael@0 96 .objectStore(osName)
michael@0 97 .delete(key1);
michael@0 98 request.onerror = errorHandler;
michael@0 99 request.onsuccess = function(event) {
michael@0 100 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 101 testGenerator.next();
michael@0 102 }
michael@0 103 yield undefined;
michael@0 104
michael@0 105 request = db.transaction(osName, "readwrite")
michael@0 106 .objectStore(osName)
michael@0 107 .delete(key2);
michael@0 108 request.onerror = errorHandler;
michael@0 109 request.onsuccess = function(event) {
michael@0 110 is(event.target.transaction.mode, "readwrite", "Correct mode");
michael@0 111 testGenerator.next();
michael@0 112 }
michael@0 113 yield undefined;
michael@0 114
michael@0 115 try {
michael@0 116 request = db.transaction([osName]).objectStore(osName).add({});
michael@0 117 ok(false, "Adding to a readonly transaction should fail!");
michael@0 118 }
michael@0 119 catch (e) {
michael@0 120 ok(true, "Adding to a readonly transaction failed");
michael@0 121 }
michael@0 122
michael@0 123 try {
michael@0 124 request = db.transaction(osName).objectStore(osName).add({});
michael@0 125 ok(false, "Adding to a readonly transaction should fail!");
michael@0 126 }
michael@0 127 catch (e) {
michael@0 128 ok(true, "Adding to a readonly transaction failed");
michael@0 129 }
michael@0 130
michael@0 131 try {
michael@0 132 request = db.transaction([osName]).objectStore(osName).put({});
michael@0 133 ok(false, "Adding or modifying a readonly transaction should fail!");
michael@0 134 }
michael@0 135 catch (e) {
michael@0 136 ok(true, "Adding or modifying a readonly transaction failed");
michael@0 137 }
michael@0 138
michael@0 139 try {
michael@0 140 request = db.transaction(osName).objectStore(osName).put({});
michael@0 141 ok(false, "Adding or modifying a readonly transaction should fail!");
michael@0 142 }
michael@0 143 catch (e) {
michael@0 144 ok(true, "Adding or modifying a readonly transaction failed");
michael@0 145 }
michael@0 146
michael@0 147 try {
michael@0 148 request = db.transaction([osName]).objectStore(osName).put({}, key1);
michael@0 149 ok(false, "Modifying a readonly transaction should fail!");
michael@0 150 }
michael@0 151 catch (e) {
michael@0 152 ok(true, "Modifying a readonly transaction failed");
michael@0 153 }
michael@0 154
michael@0 155 try {
michael@0 156 request = db.transaction(osName).objectStore(osName).put({}, key1);
michael@0 157 ok(false, "Modifying a readonly transaction should fail!");
michael@0 158 }
michael@0 159 catch (e) {
michael@0 160 ok(true, "Modifying a readonly transaction failed");
michael@0 161 }
michael@0 162
michael@0 163 try {
michael@0 164 request = db.transaction([osName]).objectStore(osName).delete(key1);
michael@0 165 ok(false, "Removing from a readonly transaction should fail!");
michael@0 166 }
michael@0 167 catch (e) {
michael@0 168 ok(true, "Removing from a readonly transaction failed");
michael@0 169 }
michael@0 170
michael@0 171 try {
michael@0 172 request = db.transaction(osName).objectStore(osName).delete(key2);
michael@0 173 ok(false, "Removing from a readonly transaction should fail!");
michael@0 174 }
michael@0 175 catch (e) {
michael@0 176 ok(true, "Removing from a readonly transaction failed");
michael@0 177 }
michael@0 178
michael@0 179 finishTest();
michael@0 180 yield undefined;
michael@0 181 }

mercurial