keypath_invalid.any.js (1782B)
1 // META: global=window,worker 2 // META: title=Invalid keypath 3 // META: script=resources/support.js 4 5 // Spec: 6 // http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#key-path-construct 7 8 'use strict'; 9 10 let global_db = createdb_for_multiple_tests(); 11 12 function invalid_keypath(keypath, desc) { 13 let t = async_test( 14 'Invalid keyPath - ' + (desc ? desc : format_value(keypath)), undefined, 15 2); 16 17 let openrq = global_db.setTest(t); 18 let store_name = 'store-' + Date.now() + Math.random(); 19 20 openrq.onupgradeneeded = function(e) { 21 let db = e.target.result; 22 assert_throws_dom('SyntaxError', function() { 23 db.createObjectStore(store_name, {keyPath: keypath}) 24 }, 'createObjectStore with keyPath'); 25 26 let store = db.createObjectStore(store_name); 27 assert_throws_dom('SyntaxError', function() { 28 store.createIndex('index', keypath); 29 }, 'createIndex with keyPath'); 30 31 db.close(); 32 33 t.done(); 34 }; 35 } 36 37 invalid_keypath('j a'); 38 invalid_keypath('.yo'); 39 invalid_keypath('yo,lo'); 40 invalid_keypath([]); 41 invalid_keypath(['array with space']); 42 invalid_keypath( 43 ['multi_array', ['a', 'b']], 44 'multidimensional array (invalid toString)'); // => ['multi_array', 45 // 'a,b'] 46 invalid_keypath('3m'); 47 invalid_keypath( 48 { 49 toString: function() { 50 return '3m' 51 } 52 }, 53 '{toString->3m}'); 54 invalid_keypath('my.1337'); 55 invalid_keypath('..yo'); 56 invalid_keypath('y..o'); 57 invalid_keypath('y.o.'); 58 invalid_keypath('y.o..'); 59 invalid_keypath('m.*'); 60 invalid_keypath('"m"'); 61 invalid_keypath('m%'); 62 invalid_keypath('m/'); 63 invalid_keypath('m/a'); 64 invalid_keypath('m&'); 65 invalid_keypath('m!'); 66 invalid_keypath('*'); 67 invalid_keypath('*.*'); 68 invalid_keypath('^m'); 69 invalid_keypath('/m/');