dom/indexedDB/test/unit/test_setVersion_abort.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 let request = indexedDB.open(name, 1);
michael@0 13 request.onerror = errorHandler;
michael@0 14 request.onsuccess = unexpectedSuccessHandler;
michael@0 15 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 16 let event = yield undefined;
michael@0 17
michael@0 18 let db = event.target.result;
michael@0 19
michael@0 20 let objectStore = db.createObjectStore("foo");
michael@0 21 let index = objectStore.createIndex("bar", "baz");
michael@0 22
michael@0 23 is(db.version, 1, "Correct version");
michael@0 24 is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
michael@0 25 is(objectStore.indexNames.length, 1, "Correct indexNames length");
michael@0 26
michael@0 27 let transaction = event.target.transaction;
michael@0 28 is(transaction.mode, "versionchange", "Correct transaction mode");
michael@0 29 transaction.oncomplete = unexpectedSuccessHandler;
michael@0 30 transaction.onabort = grabEventAndContinueHandler;
michael@0 31 transaction.abort();
michael@0 32
michael@0 33 is(db.version, 0, "Correct version");
michael@0 34 is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
michael@0 35 is(objectStore.indexNames.length, 0, "Correct indexNames length");
michael@0 36
michael@0 37 // Test that the db is actually closed.
michael@0 38 try {
michael@0 39 db.transaction("");
michael@0 40 ok(false, "Expect an exception");
michael@0 41 } catch (e) {
michael@0 42 ok(true, "Expect an exception");
michael@0 43 is(e.name, "InvalidStateError", "Expect an InvalidStateError");
michael@0 44 }
michael@0 45
michael@0 46 event = yield undefined;
michael@0 47 is(event.type, "abort", "Got transaction abort event");
michael@0 48 is(event.target, transaction, "Right target");
michael@0 49 is(event.target.transaction, null, "No transaction");
michael@0 50
michael@0 51 is(db.version, 0, "Correct version");
michael@0 52 is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
michael@0 53 is(objectStore.indexNames.length, 0, "Correct indexNames length");
michael@0 54
michael@0 55 request.onerror = grabEventAndContinueHandler;
michael@0 56 request.onupgradeneeded = unexpectedSuccessHandler;
michael@0 57
michael@0 58 event = yield undefined;
michael@0 59
michael@0 60 is(event.type, "error", "Got request error event");
michael@0 61 is(event.target, request, "Right target");
michael@0 62 is(event.target.transaction, null, "No transaction");
michael@0 63
michael@0 64 event.preventDefault();
michael@0 65
michael@0 66 request = indexedDB.open(name, 1);
michael@0 67 request.onerror = errorHandler;
michael@0 68 request.onsuccess = unexpectedSuccessHandler;
michael@0 69 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 70 event = yield undefined;
michael@0 71
michael@0 72 is(event.type, "upgradeneeded", "Got upgradeneeded event");
michael@0 73
michael@0 74 let db2 = event.target.result;
michael@0 75
michael@0 76 isnot(db, db2, "Should give a different db instance");
michael@0 77 is(db2.version, 1, "Correct version");
michael@0 78 is(db2.objectStoreNames.length, 0, "Correct objectStoreNames length");
michael@0 79
michael@0 80 let objectStore2 = db2.createObjectStore("foo");
michael@0 81 let index2 = objectStore2.createIndex("bar", "baz");
michael@0 82
michael@0 83 request.onsuccess = grabEventAndContinueHandler;
michael@0 84 request.onupgradeneeded = unexpectedSuccessHandler;
michael@0 85 event = yield undefined;
michael@0 86
michael@0 87 is(event.target.result, db2, "Correct target");
michael@0 88 is(event.type, "success", "Got success event");
michael@0 89 is(db2.version, 1, "Correct version");
michael@0 90 is(db2.objectStoreNames.length, 1, "Correct objectStoreNames length");
michael@0 91 is(objectStore2.indexNames.length, 1, "Correct indexNames length");
michael@0 92 is(db.version, 0, "Correct version still");
michael@0 93 is(db.objectStoreNames.length, 0, "Correct objectStoreNames length still");
michael@0 94 is(objectStore.indexNames.length, 0, "Correct indexNames length still");
michael@0 95
michael@0 96 finishTest();
michael@0 97 yield undefined;
michael@0 98 }

mercurial