Bug 1816170 - Disable perftest-on-autoland cron. r=aglavic
[gecko.git] / dom / indexedDB / test / unit / test_overlapping_transactions.js
blobd7f8f6c4662dd973458547e20ab78ca115bbdfc5
1 /**
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/publicdomain/zero/1.0/
4  */
6 /* exported testGenerator */
7 var testGenerator = testSteps();
9 function* testSteps() {
10   const name = this.window ? window.location.pathname : "Splendid Test";
11   const objectStores = ["foo", "bar"];
13   let request = indexedDB.open(name, 1);
14   request.onerror = errorHandler;
15   request.onupgradeneeded = grabEventAndContinueHandler;
16   let event = yield undefined;
18   let db = event.target.result;
19   is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
21   event.target.onsuccess = grabEventAndContinueHandler;
22   for (let i in objectStores) {
23     db.createObjectStore(objectStores[i], { autoIncrement: true });
24   }
25   event = yield undefined;
27   is(
28     db.objectStoreNames.length,
29     objectStores.length,
30     "Correct objectStoreNames list"
31   );
33   for (let i = 0; i < 50; i++) {
34     let stepNumber = 0;
36     request = db
37       .transaction(["foo"], "readwrite")
38       .objectStore("foo")
39       .add({});
40     request.onerror = errorHandler;
41     request.onsuccess = function(event) {
42       is(stepNumber, 1, "This callback came first");
43       stepNumber++;
44       event.target.transaction.oncomplete = grabEventAndContinueHandler;
45     };
47     request = db
48       .transaction(["foo"], "readwrite")
49       .objectStore("foo")
50       .add({});
51     request.onerror = errorHandler;
52     request.onsuccess = function(event) {
53       is(stepNumber, 2, "This callback came second");
54       stepNumber++;
55       event.target.transaction.oncomplete = grabEventAndContinueHandler;
56     };
58     request = db
59       .transaction(["foo", "bar"], "readwrite")
60       .objectStore("bar")
61       .add({});
62     request.onerror = errorHandler;
63     request.onsuccess = function(event) {
64       is(stepNumber, 3, "This callback came third");
65       stepNumber++;
66       event.target.transaction.oncomplete = grabEventAndContinueHandler;
67     };
69     request = db
70       .transaction(["foo", "bar"], "readwrite")
71       .objectStore("bar")
72       .add({});
73     request.onerror = errorHandler;
74     request.onsuccess = function(event) {
75       is(stepNumber, 4, "This callback came fourth");
76       stepNumber++;
77       event.target.transaction.oncomplete = grabEventAndContinueHandler;
78     };
80     request = db
81       .transaction(["bar"], "readwrite")
82       .objectStore("bar")
83       .add({});
84     request.onerror = errorHandler;
85     request.onsuccess = function(event) {
86       is(stepNumber, 5, "This callback came fifth");
87       stepNumber++;
88       event.target.transaction.oncomplete = grabEventAndContinueHandler;
89     };
91     stepNumber++;
92     yield undefined;
93     yield undefined;
94     yield undefined;
95     yield undefined;
96     yield undefined;
98     is(stepNumber, 6, "All callbacks received");
99   }
101   finishTest();