dom/indexedDB/test/unit/test_setVersion_exclusion.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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.onupgradeneeded = grabEventAndContinueHandler;
michael@0 15 request.onsuccess = unexpectedSuccessHandler;
michael@0 16
michael@0 17 let request2 = indexedDB.open(name, 2);
michael@0 18 request2.onerror = errorHandler;
michael@0 19 request2.onupgradeneeded = unexpectedSuccessHandler;
michael@0 20 request2.onsuccess = unexpectedSuccessHandler;
michael@0 21
michael@0 22 let event = yield undefined;
michael@0 23 is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
michael@0 24 is(event.target, request, "Event should be fired on the request");
michael@0 25 ok(event.target.result instanceof IDBDatabase, "Expect a database here");
michael@0 26
michael@0 27 let db = event.target.result;
michael@0 28 is(db.version, 1, "Database has correct version");
michael@0 29
michael@0 30 db.onupgradeneeded = function() {
michael@0 31 ok(false, "our ongoing VERSION_CHANGE transaction should exclude any others!");
michael@0 32 }
michael@0 33
michael@0 34 db.createObjectStore("foo");
michael@0 35
michael@0 36 try {
michael@0 37 db.transaction("foo");
michael@0 38 ok(false, "Transactions should be disallowed now!");
michael@0 39 } catch (e) {
michael@0 40 ok(e instanceof DOMException, "Expect a DOMException");
michael@0 41 is(e.name, "InvalidStateError", "Expect an InvalidStateError");
michael@0 42 is(e.code, DOMException.INVALID_STATE_ERR, "Expect an INVALID_STATE_ERR");
michael@0 43 }
michael@0 44
michael@0 45 request.onupgradeneeded = unexpectedSuccessHandler;
michael@0 46 request.transaction.oncomplete = grabEventAndContinueHandler;
michael@0 47
michael@0 48 event = yield undefined;
michael@0 49 is(event.type, "complete", "Got complete event");
michael@0 50
michael@0 51 try {
michael@0 52 db.transaction("foo");
michael@0 53 ok(true, "Transactions should be allowed now!");
michael@0 54 } catch (e) {
michael@0 55 ok(false, "Transactions should be allowed now!");
michael@0 56 }
michael@0 57
michael@0 58 request.onsuccess = grabEventAndContinueHandler;
michael@0 59
michael@0 60 event = yield undefined;
michael@0 61 is(event.type, "success", "Expect a success event");
michael@0 62 is(event.target.result, db, "Same database");
michael@0 63
michael@0 64 db.onversionchange = function() {
michael@0 65 ok(true, "next setVersion was unblocked appropriately");
michael@0 66 db.close();
michael@0 67 }
michael@0 68
michael@0 69 try {
michael@0 70 db.transaction("foo");
michael@0 71 ok(true, "Transactions should be allowed now!");
michael@0 72 } catch (e) {
michael@0 73 ok(false, "Transactions should be allowed now!");
michael@0 74 }
michael@0 75
michael@0 76 request.onsuccess = unexpectedSuccessHandler;
michael@0 77 request2.onupgradeneeded = grabEventAndContinueHandler;
michael@0 78
michael@0 79 event = yield undefined;
michael@0 80 is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
michael@0 81
michael@0 82 db = event.target.result;
michael@0 83 is(db.version, 2, "Database has correct version");
michael@0 84
michael@0 85 request2.onupgradeneeded = unexpectedSuccessHandler;
michael@0 86 request2.onsuccess = grabEventAndContinueHandler;
michael@0 87
michael@0 88 event = yield undefined;
michael@0 89 is(event.type, "success", "Expect a success event");
michael@0 90 is(event.target.result, db, "Same database");
michael@0 91 is(db.version, 2, "Database has correct version");
michael@0 92
michael@0 93 finishTest();
michael@0 94 yield undefined;
michael@0 95 }

mercurial