123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <!--
- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/
- -->
- <html>
- <head>
- <title>Indexed Database Property Test</title>
- <script type="text/javascript"
- src="/tests/SimpleTest/SimpleTest.js">
- </script>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
- <script type="text/javascript;version=1.7">
- function testSteps()
- {
- const databaseName = window.location.pathname;
- const databaseVersion = 1;
- const objectStoreName = "foo";
- const mutableFileName = "bar";
- const mutableFileKey = 42;
- info("opening database");
- let request = indexedDB.open(databaseName, databaseVersion);
- request.onerror = errorHandler;
- request.onupgradeneeded = grabEventAndContinueHandler;
- request.onsuccess = unexpectedSuccessHandler;
- let event = yield undefined;
- info("creating object store");
- let db = event.target.result;
- db.onerror = errorHandler;
- db.onversionchange = function(event) {
- is(event.oldVersion, databaseVersion, "got correct oldVersion");
- is(event.newVersion, null, "got correct newVersion");
- db.close();
- };
- let objectStore = db.createObjectStore(objectStoreName,
- { autoIncrement: true });
- request.onupgradeneeded = unexpectedSuccessHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- info("creating mutable file");
- request = db.createMutableFile(mutableFileName);
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- let mutableFile = event.target.result;
- verifyMutableFile(mutableFile, getFile(mutableFileName, "", ""));
- yield undefined;
- objectStore = db.transaction([objectStoreName], "readwrite")
- .objectStore(objectStoreName);
- info("adding mutable file");
- request = objectStore.add(mutableFile, mutableFileKey);
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- info("getting mutable file");
- request = objectStore.get(mutableFileKey);
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- verifyMutableFile(event.target.result,
- getFile(mutableFileName, "", ""));
- yield undefined;
- info("opening database");
- request = indexedDB.open(databaseName, databaseVersion);
- request.onerror = errorHandler;
- request.onupgradeneeded = unexpectedSuccessHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- let db2 = event.target.result;
- db2.onerror = errorHandler;
- db2.onversionchange = function(event) {
- is(event.oldVersion, databaseVersion, "got correct oldVersion");
- is(event.newVersion, null, "got correct newVersion");
- db2.close();
- };
- objectStore = db2.transaction([objectStoreName], "readwrite")
- .objectStore(objectStoreName);
- info("adding mutable file");
- request = objectStore.add(mutableFile);
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- info("getting mutable file");
- request = objectStore.get(event.target.result);
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- verifyMutableFile(event.target.result,
- getFile(mutableFileName, "", ""));
- yield undefined;
- info("setting file handle pref");
- SpecialPowers.pushPrefEnv({ set: [["dom.fileHandle.enabled", false]] },
- continueToNextStep);
- yield undefined;
- info("opening database");
- request = indexedDB.open(databaseName, databaseVersion);
- request.onerror = errorHandler;
- request.onupgradeneeded = unexpectedSuccessHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- let db3 = event.target.result;
- db3.onerror = errorHandler;
- db3.onversionchange = function(event) {
- is(event.oldVersion, databaseVersion, "got correct oldVersion");
- is(event.newVersion, null, "got correct newVersion");
- db3.close();
- };
- info("creating mutable file");
- try {
- db3.createMutableFile(mutableFileName);
- ok(false, "Should have thrown!");
- }
- catch (e) {
- ok(e instanceof DOMException, "Got exception.");
- is(e.name, "InvalidStateError", "Good error.");
- is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
- }
- objectStore = db3.transaction([objectStoreName], "readwrite")
- .objectStore(objectStoreName);
- info("adding mutable file");
- try {
- objectStore.add(mutableFile);
- ok(false, "Should have thrown!");
- }
- catch (e) {
- ok(e instanceof DOMException, "Got exception.");
- is(e.name, "DataCloneError", "Good error.");
- is(e.code, DOMException.DATA_CLONE_ERR, "Good error code.");
- }
- info("getting mutable file");
- request = objectStore.get(mutableFileKey);
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- try {
- let result = request.result;
- ok(false, "Should have thrown!");
- }
- catch (e) {
- ok(e instanceof DOMException, "Got exception.");
- is(e.name, "InvalidStateError", "Good error.");
- is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
- }
- info("deleting database");
- request = indexedDB.deleteDatabase(databaseName);
- request.onerror = errorHandler;
- request.onsuccess = grabEventAndContinueHandler;
- event = yield undefined;
- info("resetting file handle pref");
- SpecialPowers.popPrefEnv(continueToNextStep);
- yield undefined;
- finishTest();
- yield undefined;
- }
- </script>
- <script type="text/javascript;version=1.7" src="helpers.js"></script>
- <script type="text/javascript;version=1.7" src="file.js"></script>
- </head>
- <body onload="runTest();"></body>
- </html>
|