1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB keyPath edge cases");
8 indexedDBTest(prepareDatabase, testKeyPaths);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
13 evalAndLog("db.createObjectStore('store-with-path', {keyPath: 'foo'})");
14 evalAndLog("db.createObjectStore('store-with-path-and-generator', {keyPath: 'foo', autoIncrement: true})");
17 function testKeyPaths()
20 debug("testKeyPaths():");
22 transaction = evalAndLog("transaction = db.transaction(['store-with-path'], 'readwrite')");
23 store = evalAndLog("store = transaction.objectStore('store-with-path')");
26 debug("Key path doesn't resolve to a value; should yield null, should throw DATA_ERR");
27 evalAndExpectException("store.put(null)", "0", "'DataError'");
30 debug("Key path doesn't resolve to a value; should yield null, should throw DATA_ERR");
31 evalAndExpectException("store.put({})", "0", "'DataError'");
34 debug("Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR");
35 evalAndExpectException("store.put({foo: null})", "0", "'DataError'");
38 debug("Key path resolves to a value that is valid key; should yield 'string' key, should succeed");
39 request = evalAndLog("store.put({foo: 'zoo'})");
40 request.onerror = unexpectedErrorCallback;
41 request.onsuccess = function () {
42 testPassed("store.put succeeded");
45 transaction.onabort = unexpectedAbortCallback;
46 transaction.oncomplete = testKeyPathsAndGenerator;
49 function testKeyPathsAndGenerator()
52 debug("testKeyPathsAndGenerator():");
54 transaction = evalAndLog("transaction = db.transaction(['store-with-path-and-generator'], 'readwrite')");
55 store = evalAndLog("store = transaction.objectStore('store-with-path-and-generator')");
58 debug("Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception");
59 evalAndExpectException("store.put(null)", "0", "'DataError'");
62 debug("Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception");
63 evalAndExpectException("store.put('string')", "0", "'DataError'");
66 debug("Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed");
67 request = evalAndLog("store.put({})");
68 request.onerror = unexpectedErrorCallback;
69 request.onsuccess = function () {
70 testPassed("store.put succeeded");
73 debug("Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR");
74 evalAndExpectException("store.put({foo: null})", "0", "'DataError'");
77 debug("Key path resolves to a value that is valid key; should yield 'string' key, should succeed");
78 request = evalAndLog("store.put({foo: 'zoo'})");
79 request.onerror = unexpectedErrorCallback;
80 request.onsuccess = function () {
81 testPassed("store.put succeeded");
86 transaction.onabort = unexpectedAbortCallback;
87 transaction.oncomplete = finishJSTest;