2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 /* exported testGenerator */
7 var testGenerator = testSteps();
9 function* testSteps() {
10 const name = this.window ? window.location.pathname : "Splendid Test";
13 let openRequest = indexedDB.open(name, dbVersion);
14 openRequest.onerror = errorHandler;
15 openRequest.onblocked = errorHandler;
16 openRequest.onsuccess = unexpectedSuccessHandler;
17 openRequest.onupgradeneeded = grabEventAndContinueHandler;
19 let event = yield undefined;
21 is(event.type, "upgradeneeded", "Expect an upgradeneeded event");
22 ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
24 let db = event.target.result;
25 db.onversionchange = errorHandler;
26 db.createObjectStore("stuff");
28 openRequest.onsuccess = grabEventAndContinueHandler;
30 event = yield undefined;
32 is(event.type, "success", "Expect a success event");
33 is(event.target, openRequest, "Event has right target");
34 ok(event.target.result instanceof IDBDatabase, "Result should be a database");
35 is(db.objectStoreNames.length, 1, "Expect an objectStore here");
37 db.onversionchange = grabEventAndContinueHandler;
38 let deletingRequest = indexedDB.deleteDatabase(name);
39 deletingRequest.onerror = errorHandler;
40 deletingRequest.onsuccess = errorHandler;
41 deletingRequest.onblocked = errorHandler;
43 event = yield undefined;
45 is(event.type, "versionchange", "Expect an versionchange event");
46 is(event.target, db, "Event has right target");
47 ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
48 is(event.oldVersion, dbVersion, "Correct old version");
49 is(event.newVersion, null, "Correct new version");
51 deletingRequest.onblocked = grabEventAndContinueHandler;
53 event = yield undefined;
55 is(event.type, "blocked", "Expect an blocked event");
56 is(event.target, deletingRequest, "Event has right target");
57 ok(event instanceof IDBVersionChangeEvent, "Expect a versionchange event");
58 is(event.oldVersion, dbVersion, "Correct old version");
59 is(event.newVersion, null, "Correct new version");
61 deletingRequest.onsuccess = grabEventAndContinueHandler;
64 event = yield undefined;
66 is(event.type, "success", "expect a success event");
67 is(event.target, deletingRequest, "event has right target");
68 is(event.target.result, undefined, "event should have no result");
70 openRequest = indexedDB.open(name, 1);
71 openRequest.onerror = errorHandler;
72 openRequest.onsuccess = grabEventAndContinueHandler;
74 event = yield undefined;
75 db = event.target.result;
76 is(db.version, 1, "DB has proper version");
77 is(db.objectStoreNames.length, 0, "DB should have no object stores");