| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../fast/js/resources/js-test-pre.js"></script> |
| <script src="resources/shared.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description("Test IndexedDB readonly properties"); |
| if (window.layoutTestController) |
| layoutTestController.waitUntilDone(); |
| |
| function setReadonlyProperty(property, value) |
| { |
| oldValue = eval(property); |
| debug("trying to set readonly property " + property); |
| evalAndLog(property + " = " + value); |
| newValue = eval(property); |
| if (oldValue == newValue) { |
| testPassed(property + " is still " + oldValue); |
| } else { |
| testFailed(property + " value was changed"); |
| } |
| } |
| |
| function test() |
| { |
| indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;"); |
| shouldBeFalse("indexedDB == null"); |
| IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;"); |
| shouldBeFalse("IDBDatabaseException == null"); |
| IDBCursor = evalAndLog("IDBCursor = window.IDBCursor || window.webkitIDBCursor;"); |
| shouldBeFalse("IDBCursor == null"); |
| IDBKeyRange = evalAndLog("IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;"); |
| shouldBeFalse("IDBKeyRange == null"); |
| |
| name = "foo"; |
| description = "My Test Database"; |
| request = evalAndLog("indexedDB.open(name, description)"); |
| request.onsuccess = openSuccess; |
| request.onerror = unexpectedErrorCallback; |
| } |
| |
| function openSuccess() |
| { |
| setReadonlyProperty("request.result", "Infinity"); |
| setReadonlyProperty("request.errorCode", "666"); |
| setReadonlyProperty("request.source", "this"); |
| setReadonlyProperty("request.transaction", "this"); |
| setReadonlyProperty("request.readyState", "666"); |
| |
| db = evalAndLog("db = event.target.result"); |
| setReadonlyProperty("db.name", "'bar'"); |
| |
| request = evalAndLog("request = db.setVersion('1')"); |
| request.onsuccess = createAndPopulateObjectStore; |
| request.onerror = unexpectedErrorCallback; |
| } |
| |
| function createAndPopulateObjectStore() |
| { |
| transaction = evalAndLog("transaction = event.target.result;"); |
| setReadonlyProperty("transaction.mode", "666"); |
| setReadonlyProperty("transaction.db", "this"); |
| |
| deleteAllObjectStores(db); |
| |
| objectStore = evalAndLog("objectStore = db.createObjectStore('foo');"); |
| |
| setReadonlyProperty("objectStore.name", "'bar'"); |
| setReadonlyProperty("objectStore.keyPath", "'bar'"); |
| /* fails, split into separate test |
| setReadonlyProperty("objectStore.indexNames", "['bar']"); |
| */ |
| /* fails, split into separate test |
| setReadonlyProperty("objectStore.transaction", "this"); |
| */ |
| |
| result = evalAndLog("result = objectStore.add({}, 'first');"); |
| result.onerror = unexpectedErrorCallback; |
| result.onsuccess = addSuccess; |
| } |
| |
| function addSuccess() |
| { |
| result = evalAndLog("result = objectStore.openCursor();"); |
| result.onerror = unexpectedErrorCallback; |
| result.onsuccess = checkCursor; |
| } |
| |
| function checkCursor() |
| { |
| cursor = evalAndLog("cursor = event.target.result;"); |
| if (cursor) { |
| setReadonlyProperty("cursor.source", "this"); |
| setReadonlyProperty("cursor.direction", "666"); |
| setReadonlyProperty("cursor.key", "Infinity"); |
| setReadonlyProperty("cursor.primaryKey", "Infinity"); |
| } else { |
| testFailed("cursor is null"); |
| } |
| |
| index = evalAndLog("index = objectStore.createIndex('first', 'first');"); |
| setReadonlyProperty("index.name", "'bar'"); |
| setReadonlyProperty("index.objectStore", "this"); |
| setReadonlyProperty("index.keyPath", "'bar'"); |
| setReadonlyProperty("index.unique", "true"); |
| |
| keyRange = IDBKeyRange.only("first"); |
| setReadonlyProperty("keyRange.lower", "Infinity"); |
| setReadonlyProperty("keyRange.upper", "Infinity"); |
| setReadonlyProperty("keyRange.lowerOpen", "true"); |
| setReadonlyProperty("keyRange.upperOpen", "true"); |
| |
| done(); |
| } |
| |
| |
| test(); |
| |
| </script> |
| </body> |
| </html> |