dom/indexedDB/test/unit/test_cursor_update_updates_indexes.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 const START_DATA = "hi";
michael@0 12 const END_DATA = "bye";
michael@0 13 const objectStoreInfo = [
michael@0 14 { name: "1", options: { keyPath: null }, key: 1,
michael@0 15 entry: { data: START_DATA } },
michael@0 16 { name: "2", options: { keyPath: "foo" },
michael@0 17 entry: { foo: 1, data: START_DATA } },
michael@0 18 { name: "3", options: { keyPath: null, autoIncrement: true },
michael@0 19 entry: { data: START_DATA } },
michael@0 20 { name: "4", options: { keyPath: "foo", autoIncrement: true },
michael@0 21 entry: { data: START_DATA } },
michael@0 22 ];
michael@0 23
michael@0 24 for (let i = 0; i < objectStoreInfo.length; i++) {
michael@0 25 // Create our object stores.
michael@0 26 let info = objectStoreInfo[i];
michael@0 27
michael@0 28 ok(true, "1");
michael@0 29 request = indexedDB.open(name, i + 1);
michael@0 30 request.onerror = errorHandler;
michael@0 31 request.onupgradeneeded = grabEventAndContinueHandler;
michael@0 32 event = yield undefined;
michael@0 33
michael@0 34 let db = event.target.result;
michael@0 35
michael@0 36 ok(true, "2");
michael@0 37 let objectStore = info.hasOwnProperty("options") ?
michael@0 38 db.createObjectStore(info.name, info.options) :
michael@0 39 db.createObjectStore(info.name);
michael@0 40
michael@0 41 // Create the indexes on 'data' on the object store.
michael@0 42 let index = objectStore.createIndex("data_index", "data",
michael@0 43 { unique: false });
michael@0 44 let uniqueIndex = objectStore.createIndex("unique_data_index", "data",
michael@0 45 { unique: true });
michael@0 46 // Populate the object store with one entry of data.
michael@0 47 request = info.hasOwnProperty("key") ?
michael@0 48 objectStore.add(info.entry, info.key) :
michael@0 49 objectStore.add(info.entry);
michael@0 50 request.onerror = errorHandler;
michael@0 51 request.onsuccess = grabEventAndContinueHandler;
michael@0 52 event = yield undefined;
michael@0 53 ok(true, "3");
michael@0 54
michael@0 55 // Use a cursor to update 'data' to END_DATA.
michael@0 56 request = objectStore.openCursor();
michael@0 57 request.onerror = errorHandler;
michael@0 58 request.onsuccess = grabEventAndContinueHandler;
michael@0 59 event = yield undefined;
michael@0 60 ok(true, "4");
michael@0 61
michael@0 62 let cursor = request.result;
michael@0 63 let obj = cursor.value;
michael@0 64 obj.data = END_DATA;
michael@0 65 request = cursor.update(obj);
michael@0 66 request.onerror = errorHandler;
michael@0 67 request.onsuccess = grabEventAndContinueHandler;
michael@0 68 event = yield undefined;
michael@0 69 ok(true, "5");
michael@0 70
michael@0 71 // Check both indexes to make sure that they were updated.
michael@0 72 request = index.get(END_DATA);
michael@0 73 request.onerror = errorHandler;
michael@0 74 request.onsuccess = grabEventAndContinueHandler;
michael@0 75 event = yield undefined;
michael@0 76 ok(true, "6");
michael@0 77 ok(obj.data, event.target.result.data,
michael@0 78 "Non-unique index was properly updated.");
michael@0 79
michael@0 80 request = uniqueIndex.get(END_DATA);
michael@0 81 request.onerror = errorHandler;
michael@0 82 request.onsuccess = grabEventAndContinueHandler;
michael@0 83 event = yield undefined;
michael@0 84
michael@0 85 ok(true, "7");
michael@0 86 ok(obj.data, event.target.result.data,
michael@0 87 "Unique index was properly updated.");
michael@0 88 db.close();
michael@0 89 }
michael@0 90
michael@0 91 finishTest();
michael@0 92 yield undefined;
michael@0 93 }
michael@0 94

mercurial