1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/test/unit/test_clear.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/** 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +var testGenerator = testSteps(); 1.10 + 1.11 +function testSteps() 1.12 +{ 1.13 + const name = this.window ? window.location.pathname : "Splendid Test"; 1.14 + const entryCount = 1000; 1.15 + 1.16 + let request = indexedDB.open(name, 1); 1.17 + request.onerror = errorHandler; 1.18 + request.onupgradeneeded = grabEventAndContinueHandler; 1.19 + let event = yield undefined; 1.20 + 1.21 + let db = request.result; 1.22 + 1.23 + event.target.onsuccess = continueToNextStep; 1.24 + 1.25 + let objectStore = db.createObjectStore("foo", { autoIncrement: true }); 1.26 + 1.27 + let firstKey; 1.28 + for (let i = 0; i < entryCount; i++) { 1.29 + request = objectStore.add({}); 1.30 + request.onerror = errorHandler; 1.31 + if (!i) { 1.32 + request.onsuccess = function(event) { 1.33 + firstKey = event.target.result; 1.34 + }; 1.35 + } 1.36 + } 1.37 + yield undefined; 1.38 + 1.39 + isnot(firstKey, undefined, "got first key"); 1.40 + 1.41 + let seenEntryCount = 0; 1.42 + 1.43 + request = db.transaction("foo").objectStore("foo").openCursor(); 1.44 + request.onerror = errorHandler; 1.45 + request.onsuccess = function(event) { 1.46 + let cursor = event.target.result; 1.47 + if (cursor) { 1.48 + seenEntryCount++; 1.49 + cursor.continue(); 1.50 + } 1.51 + else { 1.52 + continueToNextStep(); 1.53 + } 1.54 + } 1.55 + yield undefined; 1.56 + 1.57 + is(seenEntryCount, entryCount, "Correct entry count"); 1.58 + 1.59 + try { 1.60 + db.transaction("foo").objectStore("foo").clear(); 1.61 + ok(false, "clear should throw on READ_ONLY transactions"); 1.62 + } 1.63 + catch (e) { 1.64 + ok(true, "clear should throw on READ_ONLY transactions"); 1.65 + } 1.66 + 1.67 + request = db.transaction("foo", "readwrite").objectStore("foo").clear(); 1.68 + request.onerror = errorHandler; 1.69 + request.onsuccess = grabEventAndContinueHandler; 1.70 + event = yield undefined; 1.71 + 1.72 + ok(event.target.result === undefined, "Correct event.target.result"); 1.73 + ok(request.result === undefined, "Correct request.result"); 1.74 + ok(request === event.target, "Correct event.target"); 1.75 + 1.76 + request = db.transaction("foo").objectStore("foo").openCursor(); 1.77 + request.onerror = errorHandler; 1.78 + request.onsuccess = function(event) { 1.79 + let cursor = request.result; 1.80 + if (cursor) { 1.81 + ok(false, "Shouldn't have any entries"); 1.82 + } 1.83 + continueToNextStep(); 1.84 + } 1.85 + yield undefined; 1.86 + 1.87 + request = db.transaction("foo", "readwrite").objectStore("foo").add({}); 1.88 + request.onerror = errorHandler; 1.89 + request.onsuccess = grabEventAndContinueHandler; 1.90 + event = yield undefined; 1.91 + 1.92 + isnot(event.target.result, firstKey, "Got a different key"); 1.93 + 1.94 + finishTest(); 1.95 + yield undefined; 1.96 +}