test_locale_aware_indexes.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. var testGenerator = testSteps();
  6. function testSteps()
  7. {
  8. const name = this.window ? window.location.pathname : "Splendid Test";
  9. const objectStoreName = "People";
  10. const objectStoreData = [
  11. { key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
  12. { key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
  13. { key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
  14. { key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
  15. { key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
  16. { key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } }
  17. ];
  18. const indexData = [
  19. { name: "name", keyPath: "name", options: { unique: true, locale: "es-ES" } },
  20. { name: "height", keyPath: "height", options: { locale: "auto" } },
  21. { name: "weight", keyPath: "weight", options: { unique: false, locale: "es-ES" } }
  22. ];
  23. const objectStoreDataNameSort = [
  24. { key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
  25. { key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
  26. { key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
  27. { key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
  28. { key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
  29. { key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } }
  30. ];
  31. const objectStoreDataWeightSort = [
  32. { key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
  33. { key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
  34. { key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
  35. { key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
  36. { key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } }
  37. ];
  38. const objectStoreDataHeightSort = [
  39. { key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
  40. { key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
  41. { key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
  42. { key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
  43. { key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
  44. { key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } }
  45. ];
  46. let request = indexedDB.open(name, 1);
  47. request.onerror = errorHandler;
  48. request.onupgradeneeded = grabEventAndContinueHandler;
  49. request.onsuccess = grabEventAndContinueHandler;
  50. let event = yield undefined;
  51. let db = event.target.result;
  52. let objectStore = db.createObjectStore(objectStoreName, { keyPath: null });
  53. // First, add all our data to the object store.
  54. let addedData = 0;
  55. for (let i in objectStoreData) {
  56. request = objectStore.add(objectStoreData[i].value,
  57. objectStoreData[i].key);
  58. request.onerror = errorHandler;
  59. request.onsuccess = function(event) {
  60. if (++addedData == objectStoreData.length) {
  61. testGenerator.send(event);
  62. }
  63. }
  64. }
  65. event = yield undefined;
  66. // Now create the indexes.
  67. for (let i in indexData) {
  68. objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
  69. indexData[i].options);
  70. }
  71. is(objectStore.indexNames.length, indexData.length, "Good index count");
  72. yield undefined;
  73. objectStore = db.transaction(objectStoreName)
  74. .objectStore(objectStoreName);
  75. // Check global properties to make sure they are correct.
  76. is(objectStore.indexNames.length, indexData.length, "Good index count");
  77. for (let i in indexData) {
  78. let found = false;
  79. for (let j = 0; j < objectStore.indexNames.length; j++) {
  80. if (objectStore.indexNames.item(j) == indexData[i].name) {
  81. found = true;
  82. break;
  83. }
  84. }
  85. is(found, true, "objectStore has our index");
  86. let index = objectStore.index(indexData[i].name);
  87. is(index.name, indexData[i].name, "Correct name");
  88. is(index.objectStore.name, objectStore.name, "Correct store name");
  89. is(index.keyPath, indexData[i].keyPath, "Correct keyPath");
  90. is(index.unique, indexData[i].options.unique ? true : false,
  91. "Correct unique value");
  92. if (indexData[i].options.locale == "auto") {
  93. is(index.isAutoLocale, true, "Correct isAutoLocale value");
  94. is(index.locale, "en_US", "Correct locale value");
  95. } else {
  96. is(index.isAutoLocale, false, "Correct isAutoLocale value");
  97. is(index.locale, indexData[i].options.locale, "Correct locale value");
  98. }
  99. }
  100. request = objectStore.index("name").getKey("\u00E1na");
  101. request.onerror = errorHandler;
  102. request.onsuccess = grabEventAndContinueHandler;
  103. event = yield undefined;
  104. is(event.target.result, "237-23-7732", "Correct key returned!");
  105. request = objectStore.index("name").get("\u00E1na");
  106. request.onerror = errorHandler;
  107. request.onsuccess = grabEventAndContinueHandler;
  108. event = yield undefined;
  109. is(event.target.result.name, "\u00E1na", "Correct name returned!");
  110. is(event.target.result.height, 60, "Correct height returned!");
  111. is(event.target.result.weight, 120, "Correct weight returned!");
  112. ok(true, "Test group 1");
  113. let keyIndex = 0;
  114. request = objectStore.index("name").openKeyCursor();
  115. request.onerror = errorHandler;
  116. request.onsuccess = function (event) {
  117. let cursor = event.target.result;
  118. if (cursor) {
  119. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  120. "Correct key");
  121. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  122. "Correct primary key");
  123. ok(!("value" in cursor), "No value");
  124. cursor.continue();
  125. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  126. "Correct key");
  127. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  128. "Correct value");
  129. ok(!("value" in cursor), "No value");
  130. keyIndex++;
  131. }
  132. else {
  133. testGenerator.next();
  134. }
  135. }
  136. yield undefined;
  137. is(keyIndex, objectStoreData.length, "Saw all the expected keys");
  138. ok(true, "Test group 2");
  139. keyIndex = 0;
  140. request = objectStore.index("weight").openKeyCursor(null, "next");
  141. request.onerror = errorHandler;
  142. request.onsuccess = function (event) {
  143. let cursor = event.target.result;
  144. if (cursor) {
  145. is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
  146. "Correct key");
  147. is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
  148. "Correct value");
  149. cursor.continue();
  150. is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
  151. "Correct key");
  152. is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
  153. "Correct value");
  154. keyIndex++;
  155. }
  156. else {
  157. testGenerator.next();
  158. }
  159. }
  160. yield undefined;
  161. is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys");
  162. // Check that the name index enforces its unique constraint.
  163. objectStore = db.transaction(objectStoreName, "readwrite")
  164. .objectStore(objectStoreName);
  165. request = objectStore.add({ name: "\u00E1na", height: 62, weight: 170 },
  166. "237-23-7738");
  167. request.addEventListener("error", new ExpectError("ConstraintError", true));
  168. request.onsuccess = unexpectedSuccessHandler;
  169. event = yield undefined;
  170. ok(true, "Test group 3");
  171. keyIndex = objectStoreDataNameSort.length - 1;
  172. request = objectStore.index("name").openKeyCursor(null, "prev");
  173. request.onerror = errorHandler;
  174. request.onsuccess = function (event) {
  175. let cursor = event.target.result;
  176. if (cursor) {
  177. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  178. "Correct key");
  179. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  180. "Correct value");
  181. cursor.continue();
  182. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  183. "Correct key");
  184. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  185. "Correct value");
  186. keyIndex--;
  187. }
  188. else {
  189. testGenerator.next();
  190. }
  191. }
  192. yield undefined;
  193. is(keyIndex, -1, "Saw all the expected keys");
  194. ok(true, "Test group 4");
  195. keyIndex = 1;
  196. let keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio");
  197. request = objectStore.index("name").openKeyCursor(keyRange);
  198. request.onerror = errorHandler;
  199. request.onsuccess = function (event) {
  200. let cursor = event.target.result;
  201. if (cursor) {
  202. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  203. "Correct key");
  204. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  205. "Correct value");
  206. cursor.continue();
  207. keyIndex++;
  208. }
  209. else {
  210. testGenerator.next();
  211. }
  212. }
  213. yield undefined;
  214. is(keyIndex, 5, "Saw all the expected keys");
  215. ok(true, "Test group 5");
  216. keyIndex = 2;
  217. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio", true);
  218. request = objectStore.index("name").openKeyCursor(keyRange);
  219. request.onerror = errorHandler;
  220. request.onsuccess = function (event) {
  221. let cursor = event.target.result;
  222. if (cursor) {
  223. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  224. "Correct key");
  225. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  226. "Correct value");
  227. cursor.continue();
  228. keyIndex++;
  229. }
  230. else {
  231. testGenerator.next();
  232. }
  233. }
  234. yield undefined;
  235. is(keyIndex, 5, "Saw all the expected keys");
  236. ok(true, "Test group 6");
  237. keyIndex = 1;
  238. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio", false, true);
  239. request = objectStore.index("name").openKeyCursor(keyRange);
  240. request.onerror = errorHandler;
  241. request.onsuccess = function (event) {
  242. let cursor = event.target.result;
  243. if (cursor) {
  244. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  245. "Correct key");
  246. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  247. "Correct value");
  248. cursor.continue();
  249. keyIndex++;
  250. }
  251. else {
  252. testGenerator.next();
  253. }
  254. }
  255. yield undefined;
  256. is(keyIndex, 4, "Saw all the expected keys");
  257. ok(true, "Test group 7");
  258. keyIndex = 2;
  259. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio", true, true);
  260. request = objectStore.index("name").openKeyCursor(keyRange);
  261. request.onerror = errorHandler;
  262. request.onsuccess = function (event) {
  263. let cursor = event.target.result;
  264. if (cursor) {
  265. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  266. "Correct key");
  267. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  268. "Correct value");
  269. cursor.continue();
  270. keyIndex++;
  271. }
  272. else {
  273. testGenerator.next();
  274. }
  275. }
  276. yield undefined;
  277. is(keyIndex, 4, "Saw all the expected keys");
  278. ok(true, "Test group 8");
  279. keyIndex = 1;
  280. keyRange = IDBKeyRange.lowerBound("\u00E1na");
  281. request = objectStore.index("name").openKeyCursor(keyRange);
  282. request.onerror = errorHandler;
  283. request.onsuccess = function (event) {
  284. let cursor = event.target.result;
  285. if (cursor) {
  286. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  287. "Correct key");
  288. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  289. "Correct value");
  290. cursor.continue();
  291. keyIndex++;
  292. }
  293. else {
  294. testGenerator.next();
  295. }
  296. }
  297. yield undefined;
  298. is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
  299. ok(true, "Test group 9");
  300. keyIndex = 2;
  301. keyRange = IDBKeyRange.lowerBound("\u00E1na", true);
  302. request = objectStore.index("name").openKeyCursor(keyRange);
  303. request.onerror = errorHandler;
  304. request.onsuccess = function (event) {
  305. let cursor = event.target.result;
  306. if (cursor) {
  307. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  308. "Correct key");
  309. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  310. "Correct value");
  311. cursor.continue();
  312. keyIndex++;
  313. }
  314. else {
  315. testGenerator.next();
  316. }
  317. }
  318. yield undefined;
  319. is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
  320. ok(true, "Test group 10");
  321. keyIndex = 0;
  322. keyRange = IDBKeyRange.upperBound("bob");
  323. request = objectStore.index("name").openKeyCursor(keyRange);
  324. request.onerror = errorHandler;
  325. request.onsuccess = function (event) {
  326. let cursor = event.target.result;
  327. if (cursor) {
  328. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  329. "Correct key");
  330. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  331. "Correct value");
  332. cursor.continue();
  333. keyIndex++;
  334. }
  335. else {
  336. testGenerator.next();
  337. }
  338. }
  339. yield undefined;
  340. is(keyIndex, 3, "Saw all the expected keys");
  341. ok(true, "Test group 11");
  342. keyIndex = 0;
  343. keyRange = IDBKeyRange.upperBound("bob", true);
  344. request = objectStore.index("name").openKeyCursor(keyRange);
  345. request.onerror = errorHandler;
  346. request.onsuccess = function (event) {
  347. let cursor = event.target.result;
  348. if (cursor) {
  349. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  350. "Correct key");
  351. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  352. "Correct value");
  353. cursor.continue();
  354. keyIndex++;
  355. }
  356. else {
  357. testGenerator.next();
  358. }
  359. }
  360. yield undefined;
  361. is(keyIndex, 2, "Saw all the expected keys");
  362. ok(true, "Test group 12");
  363. keyIndex = 3;
  364. keyRange = IDBKeyRange.only("\u00E9ason");
  365. request = objectStore.index("name").openKeyCursor(keyRange);
  366. request.onerror = errorHandler;
  367. request.onsuccess = function (event) {
  368. let cursor = event.target.result;
  369. if (cursor) {
  370. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  371. "Correct key");
  372. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  373. "Correct value");
  374. cursor.continue();
  375. keyIndex++;
  376. }
  377. else {
  378. testGenerator.next();
  379. }
  380. }
  381. yield undefined;
  382. is(keyIndex, 4, "Saw all the expected keys");
  383. ok(true, "Test group 13");
  384. keyIndex = 0;
  385. request = objectStore.index("name").openCursor();
  386. request.onerror = errorHandler;
  387. request.onsuccess = function (event) {
  388. let cursor = event.target.result;
  389. if (cursor) {
  390. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  391. "Correct key");
  392. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  393. "Correct primary key");
  394. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  395. "Correct name");
  396. is(cursor.value.height,
  397. objectStoreDataNameSort[keyIndex].value.height,
  398. "Correct height");
  399. if ("weight" in cursor.value) {
  400. is(cursor.value.weight,
  401. objectStoreDataNameSort[keyIndex].value.weight,
  402. "Correct weight");
  403. }
  404. cursor.continue();
  405. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  406. "Correct key");
  407. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  408. "Correct primary key");
  409. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  410. "Correct name");
  411. is(cursor.value.height,
  412. objectStoreDataNameSort[keyIndex].value.height,
  413. "Correct height");
  414. if ("weight" in cursor.value) {
  415. is(cursor.value.weight,
  416. objectStoreDataNameSort[keyIndex].value.weight,
  417. "Correct weight");
  418. }
  419. keyIndex++;
  420. }
  421. else {
  422. testGenerator.next();
  423. }
  424. }
  425. yield undefined;
  426. is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
  427. ok(true, "Test group 14");
  428. keyIndex = objectStoreDataNameSort.length - 1;
  429. request = objectStore.index("name").openCursor(null, "prev");
  430. request.onerror = errorHandler;
  431. request.onsuccess = function (event) {
  432. let cursor = event.target.result;
  433. if (cursor) {
  434. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  435. "Correct key");
  436. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  437. "Correct primary key");
  438. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  439. "Correct name");
  440. is(cursor.value.height,
  441. objectStoreDataNameSort[keyIndex].value.height,
  442. "Correct height");
  443. if ("weight" in cursor.value) {
  444. is(cursor.value.weight,
  445. objectStoreDataNameSort[keyIndex].value.weight,
  446. "Correct weight");
  447. }
  448. cursor.continue();
  449. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  450. "Correct key");
  451. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  452. "Correct primary key");
  453. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  454. "Correct name");
  455. is(cursor.value.height,
  456. objectStoreDataNameSort[keyIndex].value.height,
  457. "Correct height");
  458. if ("weight" in cursor.value) {
  459. is(cursor.value.weight,
  460. objectStoreDataNameSort[keyIndex].value.weight,
  461. "Correct weight");
  462. }
  463. keyIndex--;
  464. }
  465. else {
  466. testGenerator.next();
  467. }
  468. }
  469. yield undefined;
  470. is(keyIndex, -1, "Saw all the expected keys");
  471. ok(true, "Test group 15");
  472. keyIndex = 1;
  473. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio");
  474. request = objectStore.index("name").openCursor(keyRange);
  475. request.onerror = errorHandler;
  476. request.onsuccess = function (event) {
  477. let cursor = event.target.result;
  478. if (cursor) {
  479. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  480. "Correct key");
  481. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  482. "Correct primary key");
  483. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  484. "Correct name");
  485. is(cursor.value.height,
  486. objectStoreDataNameSort[keyIndex].value.height,
  487. "Correct height");
  488. if ("weight" in cursor.value) {
  489. is(cursor.value.weight,
  490. objectStoreDataNameSort[keyIndex].value.weight,
  491. "Correct weight");
  492. }
  493. cursor.continue();
  494. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  495. "Correct key");
  496. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  497. "Correct primary key");
  498. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  499. "Correct name");
  500. is(cursor.value.height,
  501. objectStoreDataNameSort[keyIndex].value.height,
  502. "Correct height");
  503. if ("weight" in cursor.value) {
  504. is(cursor.value.weight,
  505. objectStoreDataNameSort[keyIndex].value.weight,
  506. "Correct weight");
  507. }
  508. keyIndex++;
  509. }
  510. else {
  511. testGenerator.next();
  512. }
  513. }
  514. yield undefined;
  515. is(keyIndex, 5, "Saw all the expected keys");
  516. ok(true, "Test group 16");
  517. keyIndex = 2;
  518. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio", true);
  519. request = objectStore.index("name").openCursor(keyRange);
  520. request.onerror = errorHandler;
  521. request.onsuccess = function (event) {
  522. let cursor = event.target.result;
  523. if (cursor) {
  524. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  525. "Correct key");
  526. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  527. "Correct primary key");
  528. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  529. "Correct name");
  530. is(cursor.value.height,
  531. objectStoreDataNameSort[keyIndex].value.height,
  532. "Correct height");
  533. if ("weight" in cursor.value) {
  534. is(cursor.value.weight,
  535. objectStoreDataNameSort[keyIndex].value.weight,
  536. "Correct weight");
  537. }
  538. cursor.continue();
  539. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  540. "Correct key");
  541. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  542. "Correct primary key");
  543. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  544. "Correct name");
  545. is(cursor.value.height,
  546. objectStoreDataNameSort[keyIndex].value.height,
  547. "Correct height");
  548. if ("weight" in cursor.value) {
  549. is(cursor.value.weight,
  550. objectStoreDataNameSort[keyIndex].value.weight,
  551. "Correct weight");
  552. }
  553. keyIndex++;
  554. }
  555. else {
  556. testGenerator.next();
  557. }
  558. }
  559. yield undefined;
  560. is(keyIndex, 5, "Saw all the expected keys");
  561. ok(true, "Test group 17");
  562. keyIndex = 1;
  563. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio", false, true);
  564. request = objectStore.index("name").openCursor(keyRange);
  565. request.onerror = errorHandler;
  566. request.onsuccess = function (event) {
  567. let cursor = event.target.result;
  568. if (cursor) {
  569. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  570. "Correct key");
  571. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  572. "Correct primary key");
  573. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  574. "Correct name");
  575. is(cursor.value.height,
  576. objectStoreDataNameSort[keyIndex].value.height,
  577. "Correct height");
  578. if ("weight" in cursor.value) {
  579. is(cursor.value.weight,
  580. objectStoreDataNameSort[keyIndex].value.weight,
  581. "Correct weight");
  582. }
  583. cursor.continue();
  584. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  585. "Correct key");
  586. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  587. "Correct primary key");
  588. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  589. "Correct name");
  590. is(cursor.value.height,
  591. objectStoreDataNameSort[keyIndex].value.height,
  592. "Correct height");
  593. if ("weight" in cursor.value) {
  594. is(cursor.value.weight,
  595. objectStoreDataNameSort[keyIndex].value.weight,
  596. "Correct weight");
  597. }
  598. keyIndex++;
  599. }
  600. else {
  601. testGenerator.next();
  602. }
  603. }
  604. yield undefined;
  605. is(keyIndex, 4, "Saw all the expected keys");
  606. ok(true, "Test group 18");
  607. keyIndex = 2;
  608. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio", true, true);
  609. request = objectStore.index("name").openCursor(keyRange);
  610. request.onerror = errorHandler;
  611. request.onsuccess = function (event) {
  612. let cursor = event.target.result;
  613. if (cursor) {
  614. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  615. "Correct key");
  616. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  617. "Correct primary key");
  618. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  619. "Correct name");
  620. is(cursor.value.height,
  621. objectStoreDataNameSort[keyIndex].value.height,
  622. "Correct height");
  623. if ("weight" in cursor.value) {
  624. is(cursor.value.weight,
  625. objectStoreDataNameSort[keyIndex].value.weight,
  626. "Correct weight");
  627. }
  628. cursor.continue();
  629. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  630. "Correct key");
  631. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  632. "Correct primary key");
  633. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  634. "Correct name");
  635. is(cursor.value.height,
  636. objectStoreDataNameSort[keyIndex].value.height,
  637. "Correct height");
  638. if ("weight" in cursor.value) {
  639. is(cursor.value.weight,
  640. objectStoreDataNameSort[keyIndex].value.weight,
  641. "Correct weight");
  642. }
  643. keyIndex++;
  644. }
  645. else {
  646. testGenerator.next();
  647. }
  648. }
  649. yield undefined;
  650. is(keyIndex, 4, "Saw all the expected keys");
  651. ok(true, "Test group 19");
  652. keyIndex = 4;
  653. keyRange = IDBLocaleAwareKeyRange.bound("\u00E1na", "fabio");
  654. request = objectStore.index("name").openCursor(keyRange, "prev");
  655. request.onerror = errorHandler;
  656. request.onsuccess = function (event) {
  657. let cursor = event.target.result;
  658. if (cursor) {
  659. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  660. "Correct key");
  661. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  662. "Correct primary key");
  663. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  664. "Correct name");
  665. is(cursor.value.height,
  666. objectStoreDataNameSort[keyIndex].value.height,
  667. "Correct height");
  668. if ("weight" in cursor.value) {
  669. is(cursor.value.weight,
  670. objectStoreDataNameSort[keyIndex].value.weight,
  671. "Correct weight");
  672. }
  673. cursor.continue();
  674. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  675. "Correct key");
  676. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  677. "Correct primary key");
  678. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  679. "Correct name");
  680. is(cursor.value.height,
  681. objectStoreDataNameSort[keyIndex].value.height,
  682. "Correct height");
  683. if ("weight" in cursor.value) {
  684. is(cursor.value.weight,
  685. objectStoreDataNameSort[keyIndex].value.weight,
  686. "Correct weight");
  687. }
  688. keyIndex--;
  689. }
  690. else {
  691. testGenerator.next();
  692. }
  693. }
  694. yield undefined;
  695. is(keyIndex, 0, "Saw all the expected keys");
  696. ok(true, "Test group 20");
  697. // Test "nextunique"
  698. keyIndex = 3;
  699. keyRange = IDBKeyRange.only(65);
  700. request = objectStore.index("height").openKeyCursor(keyRange, "next");
  701. request.onerror = errorHandler;
  702. request.onsuccess = function (event) {
  703. let cursor = event.target.result;
  704. if (cursor) {
  705. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  706. "Correct key");
  707. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  708. "Correct value");
  709. cursor.continue();
  710. keyIndex++;
  711. }
  712. else {
  713. testGenerator.next();
  714. }
  715. }
  716. yield undefined;
  717. is(keyIndex, 5, "Saw all the expected keys");
  718. ok(true, "Test group 21");
  719. keyIndex = 3;
  720. keyRange = IDBKeyRange.only(65);
  721. request = objectStore.index("height").openKeyCursor(keyRange,
  722. "nextunique");
  723. request.onerror = errorHandler;
  724. request.onsuccess = function (event) {
  725. let cursor = event.target.result;
  726. if (cursor) {
  727. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  728. "Correct key");
  729. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  730. "Correct value");
  731. cursor.continue();
  732. keyIndex++;
  733. }
  734. else {
  735. testGenerator.next();
  736. }
  737. }
  738. yield undefined;
  739. is(keyIndex, 4, "Saw all the expected keys");
  740. ok(true, "Test group 21.5");
  741. keyIndex = 5;
  742. request = objectStore.index("height").openKeyCursor(null, "prev");
  743. request.onerror = errorHandler;
  744. request.onsuccess = function (event) {
  745. let cursor = event.target.result;
  746. if (cursor) {
  747. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  748. "Correct key");
  749. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  750. "Correct value");
  751. cursor.continue();
  752. keyIndex--;
  753. }
  754. else {
  755. testGenerator.next();
  756. }
  757. }
  758. yield undefined;
  759. is(keyIndex, -1, "Saw all the expected keys");
  760. ok(true, "Test group 22");
  761. keyIndex = 5;
  762. request = objectStore.index("height").openKeyCursor(null,
  763. "prevunique");
  764. request.onerror = errorHandler;
  765. request.onsuccess = function (event) {
  766. let cursor = event.target.result;
  767. if (cursor) {
  768. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  769. "Correct key");
  770. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  771. "Correct value");
  772. cursor.continue();
  773. if (keyIndex == 5) {
  774. keyIndex--;
  775. }
  776. keyIndex--;
  777. }
  778. else {
  779. testGenerator.next();
  780. }
  781. }
  782. yield undefined;
  783. is(keyIndex, -1, "Saw all the expected keys");
  784. ok(true, "Test group 23");
  785. keyIndex = 3;
  786. keyRange = IDBKeyRange.only(65);
  787. request = objectStore.index("height").openCursor(keyRange, "next");
  788. request.onerror = errorHandler;
  789. request.onsuccess = function (event) {
  790. let cursor = event.target.result;
  791. if (cursor) {
  792. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  793. "Correct key");
  794. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  795. "Correct primary key");
  796. is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
  797. "Correct name");
  798. is(cursor.value.height,
  799. objectStoreDataHeightSort[keyIndex].value.height,
  800. "Correct height");
  801. if ("weight" in cursor.value) {
  802. is(cursor.value.weight,
  803. objectStoreDataHeightSort[keyIndex].value.weight,
  804. "Correct weight");
  805. }
  806. cursor.continue();
  807. keyIndex++;
  808. }
  809. else {
  810. testGenerator.next();
  811. }
  812. }
  813. yield undefined;
  814. is(keyIndex, 5, "Saw all the expected keys");
  815. ok(true, "Test group 24");
  816. keyIndex = 3;
  817. keyRange = IDBKeyRange.only(65);
  818. request = objectStore.index("height").openCursor(keyRange,
  819. "nextunique");
  820. request.onerror = errorHandler;
  821. request.onsuccess = function (event) {
  822. let cursor = event.target.result;
  823. if (cursor) {
  824. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  825. "Correct key");
  826. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  827. "Correct primary key");
  828. is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
  829. "Correct name");
  830. is(cursor.value.height,
  831. objectStoreDataHeightSort[keyIndex].value.height,
  832. "Correct height");
  833. if ("weight" in cursor.value) {
  834. is(cursor.value.weight,
  835. objectStoreDataHeightSort[keyIndex].value.weight,
  836. "Correct weight");
  837. }
  838. cursor.continue();
  839. keyIndex++;
  840. }
  841. else {
  842. testGenerator.next();
  843. }
  844. }
  845. yield undefined;
  846. is(keyIndex, 4, "Saw all the expected keys");
  847. ok(true, "Test group 24.5");
  848. keyIndex = 5;
  849. request = objectStore.index("height").openCursor(null, "prev");
  850. request.onerror = errorHandler;
  851. request.onsuccess = function (event) {
  852. let cursor = event.target.result;
  853. if (cursor) {
  854. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  855. "Correct key");
  856. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  857. "Correct primary key");
  858. is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
  859. "Correct name");
  860. is(cursor.value.height,
  861. objectStoreDataHeightSort[keyIndex].value.height,
  862. "Correct height");
  863. if ("weight" in cursor.value) {
  864. is(cursor.value.weight,
  865. objectStoreDataHeightSort[keyIndex].value.weight,
  866. "Correct weight");
  867. }
  868. cursor.continue();
  869. keyIndex--;
  870. }
  871. else {
  872. testGenerator.next();
  873. }
  874. }
  875. yield undefined;
  876. is(keyIndex, -1, "Saw all the expected keys");
  877. ok(true, "Test group 25");
  878. keyIndex = 5;
  879. request = objectStore.index("height").openCursor(null,
  880. "prevunique");
  881. request.onerror = errorHandler;
  882. request.onsuccess = function (event) {
  883. let cursor = event.target.result;
  884. if (cursor) {
  885. is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
  886. "Correct key");
  887. is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
  888. "Correct primary key");
  889. is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
  890. "Correct name");
  891. is(cursor.value.height,
  892. objectStoreDataHeightSort[keyIndex].value.height,
  893. "Correct height");
  894. if ("weight" in cursor.value) {
  895. is(cursor.value.weight,
  896. objectStoreDataHeightSort[keyIndex].value.weight,
  897. "Correct weight");
  898. }
  899. cursor.continue();
  900. if (keyIndex == 5) {
  901. keyIndex--;
  902. }
  903. keyIndex--;
  904. }
  905. else {
  906. testGenerator.next();
  907. }
  908. }
  909. yield undefined;
  910. is(keyIndex, -1, "Saw all the expected keys");
  911. ok(true, "Test group 26");
  912. keyIndex = 0;
  913. request = objectStore.index("name").openKeyCursor();
  914. request.onerror = errorHandler;
  915. request.onsuccess = function (event) {
  916. let cursor = event.target.result;
  917. if (cursor) {
  918. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  919. "Correct key");
  920. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  921. "Correct value");
  922. let nextKey = !keyIndex ? "\u00E9ason" : undefined;
  923. cursor.continue(nextKey);
  924. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  925. "Correct key");
  926. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  927. "Correct value");
  928. if (!keyIndex) {
  929. keyIndex = 3;
  930. }
  931. else {
  932. keyIndex++;
  933. }
  934. }
  935. else {
  936. testGenerator.next();
  937. }
  938. }
  939. yield undefined;
  940. is(keyIndex, objectStoreData.length, "Saw all the expected keys");
  941. ok(true, "Test group 27");
  942. keyIndex = 0;
  943. request = objectStore.index("name").openKeyCursor();
  944. request.onerror = errorHandler;
  945. request.onsuccess = function (event) {
  946. let cursor = event.target.result;
  947. if (cursor) {
  948. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  949. "Correct key");
  950. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  951. "Correct value");
  952. let nextKey = !keyIndex ? "bar" : undefined;
  953. cursor.continue(nextKey);
  954. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  955. "Correct key");
  956. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  957. "Correct value");
  958. keyIndex += keyIndex ? 1 : 2;
  959. }
  960. else {
  961. testGenerator.next();
  962. }
  963. }
  964. yield undefined;
  965. is(keyIndex, objectStoreData.length, "Saw all the expected keys");
  966. ok(true, "Test group 28");
  967. keyIndex = 0;
  968. request = objectStore.index("name").openCursor();
  969. request.onerror = errorHandler;
  970. request.onsuccess = function (event) {
  971. let cursor = event.target.result;
  972. if (cursor) {
  973. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  974. "Correct key");
  975. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  976. "Correct primary key");
  977. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  978. "Correct name");
  979. is(cursor.value.height,
  980. objectStoreDataNameSort[keyIndex].value.height,
  981. "Correct height");
  982. if ("weight" in cursor.value) {
  983. is(cursor.value.weight,
  984. objectStoreDataNameSort[keyIndex].value.weight,
  985. "Correct weight");
  986. }
  987. let nextKey = !keyIndex ? "\u00E9ason" : undefined;
  988. cursor.continue(nextKey);
  989. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  990. "Correct key");
  991. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  992. "Correct primary key");
  993. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  994. "Correct name");
  995. is(cursor.value.height,
  996. objectStoreDataNameSort[keyIndex].value.height,
  997. "Correct height");
  998. if ("weight" in cursor.value) {
  999. is(cursor.value.weight,
  1000. objectStoreDataNameSort[keyIndex].value.weight,
  1001. "Correct weight");
  1002. }
  1003. if (!keyIndex) {
  1004. keyIndex = 3;
  1005. }
  1006. else {
  1007. keyIndex++;
  1008. }
  1009. }
  1010. else {
  1011. testGenerator.next();
  1012. }
  1013. }
  1014. yield undefined;
  1015. is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
  1016. ok(true, "Test group 29");
  1017. keyIndex = 0;
  1018. request = objectStore.index("name").openCursor();
  1019. request.onerror = errorHandler;
  1020. request.onsuccess = function (event) {
  1021. let cursor = event.target.result;
  1022. if (cursor) {
  1023. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  1024. "Correct key");
  1025. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  1026. "Correct primary key");
  1027. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  1028. "Correct name");
  1029. is(cursor.value.height,
  1030. objectStoreDataNameSort[keyIndex].value.height,
  1031. "Correct height");
  1032. if ("weight" in cursor.value) {
  1033. is(cursor.value.weight,
  1034. objectStoreDataNameSort[keyIndex].value.weight,
  1035. "Correct weight");
  1036. }
  1037. let nextKey = !keyIndex ? "bar" : undefined;
  1038. cursor.continue(nextKey);
  1039. is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
  1040. "Correct key");
  1041. is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key,
  1042. "Correct primary key");
  1043. is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
  1044. "Correct name");
  1045. is(cursor.value.height,
  1046. objectStoreDataNameSort[keyIndex].value.height,
  1047. "Correct height");
  1048. if ("weight" in cursor.value) {
  1049. is(cursor.value.weight,
  1050. objectStoreDataNameSort[keyIndex].value.weight,
  1051. "Correct weight");
  1052. }
  1053. keyIndex += keyIndex ? 1 : 2;
  1054. }
  1055. else {
  1056. testGenerator.next();
  1057. }
  1058. }
  1059. yield undefined;
  1060. is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
  1061. finishTest();
  1062. yield undefined;
  1063. }