1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test for valid and invalid keypaths");
8 indexedDBTest(prepareDatabase);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
13 evalAndLog("store = db.createObjectStore('name')");
14 shouldBeNull("store.keyPath");
15 deleteAllObjectStores(db);
18 { keyPath: "null", storeExpected: "null", indexExpected: "'null'" },
19 { keyPath: "undefined", storeExpected: "null", indexExpected: "'undefined'" },
22 { keyPath: "'foo.bar.baz'" },
27 { keyPath: "'\\u0391'" }, // GREEK CAPITAL LETTER ALPHA (Lc)
28 { keyPath: "'\\u0371'" }, // GREEK SMALL LETTER ALPHA (Lu)
29 { keyPath: "'\\u01C5'" }, // LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON (Lt)
30 { keyPath: "'\\u02B0'" }, // MODIFIER LETTER SMALL H (Lm)
31 { keyPath: "'\\u00AA'" }, // FEMININE ORDINAL INDICATOR (Lo)
32 { keyPath: "'\\u16EE'" }, // RUNIC ARLAUG SYMBOL (Nl)
37 { keyPath: "'_\\u0391'" }, // GREEK CAPITAL LETTER ALPHA (Lc)
38 { keyPath: "'_\\u0371'" }, // GREEK SMALL LETTER ALPHA (Lu)
39 { keyPath: "'_\\u01C5'" }, // LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON (Lt)
40 { keyPath: "'_\\u02B0'" }, // MODIFIER LETTER SMALL H (Lm)
41 { keyPath: "'_\\u00AA'" }, // FEMININE ORDINAL INDICATOR (Lo)
42 { keyPath: "'_\\u16EE'" }, // RUNIC ARLAUG SYMBOL (Nl)
43 { keyPath: "'_\\u0300'" }, // COMBINING GRAVE ACCENT (Mn)
44 { keyPath: "'_\\u0903'" }, // DEVANAGARI SIGN VISARGA (Mc)
45 { keyPath: "'_\\u0300'" }, // DIGIT ZERO (Nd)
46 { keyPath: "'_\\u203F'" }, // UNDERTIE (Pc)
47 { keyPath: "'_\\u200C'" }, // ZWNJ
48 { keyPath: "'_\\u200D'" } // ZWJ
51 testKeyPaths.forEach(function (testCase) {
52 storeExpected = ('storeExpected' in testCase) ? testCase.storeExpected : testCase.keyPath;
53 indexExpected = ('indexExpected' in testCase) ? testCase.indexExpected : testCase.keyPath;
55 evalAndLog("store = db.createObjectStore('name', {keyPath: " + testCase.keyPath + "})");
56 shouldBe("store.keyPath", storeExpected);
57 evalAndLog("index = store.createIndex('name', " + testCase.keyPath + ")");
58 shouldBe("index.keyPath", indexExpected);
59 deleteAllObjectStores(db);
62 testInvalidKeyPaths();
65 function testInvalidKeyPaths()
68 debug("testInvalidKeyPaths():");
69 deleteAllObjectStores(db);
72 debug("Object store key path may not be empty or an array if autoIncrement is true");
73 testKeyPaths = ["''", "['a']", "['']"];
74 testKeyPaths.forEach(function (keyPath) {
75 store = evalAndExpectException("store = db.createObjectStore('storeName', {autoIncrement: true, keyPath: " + keyPath + "})", "DOMException.INVALID_ACCESS_ERR");
76 deleteAllObjectStores(db);
80 debug("Key paths which are never valid:");
94 // IdentifierPart but not IdentifierStart
95 "'\\u0300'", // COMBINING GRAVE ACCENT (Mn)
96 "'\\u0903'", // DEVANAGARI SIGN VISARGA (Mc)
97 "'\\u0300'", // DIGIT ZERO (Nd)
98 "'\\u203F'", // UNDERTIE (Pc)
102 // Neither IdentifierPart nor IdentifierStart
103 "'\\u002D'", // HYPHEN-MINUS (Pd)
104 "'\\u0028'", // LEFT PARENTHESIS (Ps)
105 "'\\u0029'", // RIGHT PARENTHESIS (Pe)
106 "'\\u00AB'", // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (Pi)
107 "'\\u00BB'", // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (Pf)
108 "'\\u0021'", // EXCLAMATION MARK (Po)
109 "'\\u002B'", // PLUS SIGN (Sm)
110 "'\\u00A2'", // CENT SIGN (Sc)
111 "'\\u005E'", // CIRCUMFLEX ACCENT (Sk)
112 "'\\u00A6'", // BROKEN BAR (So)
113 "'\\u00A0'", // NO-BREAK SPACE (Zs)
114 "'\\u2028'", // LINE SEPARATOR (Zl)
115 "'\\u2029'", // PARAGRAPH SEPARATOR (Zp)
116 "'\\u0000'", // NULL (Cc)
117 "'\\u00AD'", // SOFT HYPHEN (Cf)
118 "'\\uD800'", // Surrogate (Cs)
119 "'\\uE000'", // Private Use (Co)
120 "'\\uFFFE'", // Special
121 "'\\uFFFF'", // Special
123 // Neither IdentifierPart nor IdentifierStart
124 "'_\\u002D'", // HYPHEN-MINUS (Pd)
125 "'_\\u0028'", // LEFT PARENTHESIS (Ps)
126 "'_\\u0029'", // RIGHT PARENTHESIS (Pe)
127 "'_\\u00AB'", // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (Pi)
128 "'_\\u00BB'", // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (Pf)
129 "'_\\u0021'", // EXCLAMATION MARK (Po)
130 "'_\\u002B'", // PLUS SIGN (Sm)
131 "'_\\u00A2'", // CENT SIGN (Sc)
132 "'_\\u005E'", // CIRCUMFLEX ACCENT (Sk)
133 "'_\\u00A6'", // BROKEN BAR (So)
134 "'_\\u00A0'", // NO-BREAK SPACE (Zs)
135 "'_\\u2028'", // LINE SEPARATOR (Zl)
136 "'_\\u2029'", // PARAGRAPH SEPARATOR (Zp)
137 "'_\\u0000'", // NULL (Cc)
138 "'_\\u00AD'", // SOFT HYPHEN (Cf)
139 "'_\\uD800'", // Surrogate (Cs)
140 "'_\\uE000'", // Private Use (Co)
141 "'_\\uFFFE'", // Special
142 "'_\\uFFFF'" // Special
144 testKeyPaths.forEach(function (keyPath) {
145 evalAndExpectException("db.createObjectStore('name', {keyPath: " + keyPath + "})", "DOMException.SYNTAX_ERR");
146 evalAndExpectException("db.createObjectStore('name').createIndex('name', " + keyPath + ")", "DOMException.SYNTAX_ERR");
147 deleteAllObjectStores(db);