2 <!-- Submitted from TestTWF Paris -->
4 <title>Invalid keypath</title>
5 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#key-path-construct">
6 <link rel=assert title="A key path is a DOMString that defines how to extract a key from a value. A valid key path is either the empty string, a JavaScript identifier, or multiple Javascript identifiers separated by periods (ASCII character code 46) [ECMA-262].">
7 <script src="../../../resources/testharness.js"></script>
8 <script src="../../../resources/testharnessreport.js"></script>
9 <script src="support.js"></script>
13 var global_db = createdb_for_multiple_tests();
15 function invalid_keypath(keypath, desc) {
16 var t = async_test("Invalid keyPath - " + (desc ? desc : format_value(keypath)), undefined, 2);
18 var openrq = global_db.setTest(t),
19 store_name = "store-" + Date.now() + Math.random();
21 openrq.onupgradeneeded = function(e) {
22 var db = e.target.result;
23 assert_throws('SyntaxError', function() {
24 db.createObjectStore(store_name, { keyPath: keypath })
25 }, "createObjectStore with keyPath");
27 store = db.createObjectStore(store_name);
28 assert_throws('SyntaxError', function() {
29 store.createIndex('index', keypath);
30 }, "createIndex with keyPath");
38 invalid_keypath('j a');
39 invalid_keypath('.yo');
40 invalid_keypath('yo,lo');
42 invalid_keypath(['array with space']);
43 invalid_keypath(['multi_array', ['a', 'b']], "multidimensional array (invalid toString)"); // => ['multi_array', 'a,b']
44 invalid_keypath('3m');
45 invalid_keypath({toString:function(){return '3m'}}, '{toString->3m}');
46 invalid_keypath('my.1337');
47 invalid_keypath('..yo');
48 invalid_keypath('y..o');
49 invalid_keypath('y.o.');
50 invalid_keypath('y.o..');
51 invalid_keypath('m.*');
52 invalid_keypath('"m"');
53 invalid_keypath('m%');
54 invalid_keypath('m/');
55 invalid_keypath('m/a');
56 invalid_keypath('m&');
57 invalid_keypath('m!');
59 invalid_keypath('*.*');
60 invalid_keypath('^m');
61 invalid_keypath('/m/');