Bug 871846 - Tests for locale aware indexes. r=janv

This commit is contained in:
Shihua Zheng 2014-07-20 14:29:54 -07:00
parent 5e1f2a6b18
commit 8b824c5ed4
13 changed files with 1919 additions and 4 deletions

View File

@ -17,6 +17,9 @@ XPCSHELL_TESTS_MANIFESTS += [
'test/unit/xpcshell-parent-process.ini'
]
if CONFIG['ENABLE_INTL_API']:
MOCHITEST_MANIFESTS += ['test/mochitest-intl-api.ini']
EXPORTS.mozilla.dom.indexedDB += [
'ActorsParent.h',
'FileInfo.h',

View File

@ -332,10 +332,6 @@ function workerScript() {
return "undefined";
}
if (_thing_ === null) {
return "null";
}
let str;
try {

View File

@ -0,0 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
[DEFAULT]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116, b2g desktop specific, initial triage
[test_create_locale_aware_index.html]
[test_locale_aware_indexes.html]
[test_locale_aware_index_getAll.html]
[test_locale_aware_index_getAllObjects.html]

View File

@ -1,3 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
[DEFAULT]
support-files =
bfcache_iframe1.html
@ -27,6 +31,7 @@ support-files =
unit/test_count.js
unit/test_create_index.js
unit/test_create_index_with_integer_keys.js
unit/test_create_locale_aware_index.js
unit/test_create_objectStore.js
unit/test_cursor_mutation.js
unit/test_cursor_update_updates_indexes.js
@ -52,6 +57,9 @@ support-files =
unit/test_invalidate.js
unit/test_key_requirements.js
unit/test_keys.js
unit/test_locale_aware_indexes.js
unit/test_locale_aware_index_getAll.js
unit/test_locale_aware_index_getAllObjects.js
unit/test_lowDiskSpace.js
unit/test_multientry.js
unit/test_names_sorted.js

View File

@ -0,0 +1,18 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7" src="unit/test_create_locale_aware_index.js"></script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -0,0 +1,19 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7" src="unit/test_locale_aware_index_getAll.js"></script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -0,0 +1,19 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7" src="unit/test_locale_aware_index_getAllObjects.js"></script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -0,0 +1,18 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7" src="unit/test_locale_aware_indexes.js"></script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -0,0 +1,123 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var testGenerator = testSteps();
function testSteps()
{
const name = this.window ? window.location.pathname : "Splendid Test";
const objectStoreInfo = [
{ name: "a", options: { keyPath: "id", autoIncrement: true } },
{ name: "b", options: { keyPath: "id", autoIncrement: false } },
];
const indexInfo = [
{ name: "1", keyPath: "unique_value", options: { unique: true, locale: "es-ES" } },
{ name: "2", keyPath: "unique_value", options: { unique: true, locale: null } },
{ name: "3", keyPath: "value", options: { unique: false, locale: "es-ES" } },
{ name: "4", keyPath: "value", options: { unique: false, locale: "es-ES" } },
{ name: "", keyPath: "value", options: { unique: false, locale: "es-ES" } },
{ name: null, keyPath: "value", options: { unique: false, locale: "es-ES" } },
{ name: undefined, keyPath: "value", options: { unique: false, locale: "es-ES" } },
];
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = unexpectedSuccessHandler;
let event = yield undefined;
let db = event.target.result;
for (let i = 0; i < objectStoreInfo.length; i++) {
let info = objectStoreInfo[i];
let objectStore = info.hasOwnProperty("options") ?
db.createObjectStore(info.name, info.options) :
db.createObjectStore(info.name);
try {
request = objectStore.createIndex("Hola");
ok(false, "createIndex with no keyPath should throw");
}
catch(e) {
ok(true, "createIndex with no keyPath should throw");
}
let ex;
try {
objectStore.createIndex("Hola", ["foo"], { multiEntry: true });
}
catch(e) {
ex = e;
}
ok(ex, "createIndex with array keyPath and multiEntry should throw");
is(ex.name, "InvalidAccessError", "should throw right exception");
ok(ex instanceof DOMException, "should throw right exception");
is(ex.code, DOMException.INVALID_ACCESS_ERR, "should throw right exception");
try {
objectStore.createIndex("foo", "bar", 10);
ok(false, "createIndex with bad options should throw");
}
catch(e) {
ok(true, "createIndex with bad options threw");
}
ok(objectStore.createIndex("foo", "bar", { foo: "" }),
"createIndex with unknown options should not throw");
objectStore.deleteIndex("foo");
// Test index creation, and that it ends up in indexNames.
let objectStoreName = info.name;
for (let j = 0; j < indexInfo.length; j++) {
let info = indexInfo[j];
let count = objectStore.indexNames.length;
let index = info.hasOwnProperty("options") ?
objectStore.createIndex(info.name, info.keyPath,
info.options) :
objectStore.createIndex(info.name, info.keyPath);
let name = info.name;
if (name === null) {
name = "null";
}
else if (name === undefined) {
name = "undefined";
}
is(index.name, name, "correct name");
is(index.keyPath, info.keyPath, "correct keyPath");
is(index.unique, info.options.unique, "correct uniqueness");
is(index.locale, info.options.locale, "correct locale");
is(objectStore.indexNames.length, count + 1,
"indexNames grew in size");
let found = false;
for (let k = 0; k < objectStore.indexNames.length; k++) {
if (objectStore.indexNames.item(k) == name) {
found = true;
break;
}
}
ok(found, "Name is on objectStore.indexNames");
ok(event.target.transaction, "event has a transaction");
ok(event.target.transaction.db === db,
"transaction has the right db");
is(event.target.transaction.mode, "versionchange",
"transaction has the correct mode");
is(event.target.transaction.objectStoreNames.length, i + 1,
"transaction only has one object store");
ok(event.target.transaction.objectStoreNames.contains(objectStoreName),
"transaction has the correct object store");
}
}
request.onsuccess = grabEventAndContinueHandler;
request.onupgradeneeded = unexpectedSuccessHandler;
event = yield undefined;
finishTest();
yield undefined;
}

View File

@ -0,0 +1,191 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var testGenerator = testSteps();
function testSteps()
{
const name = this.window ? window.location.pathname : "Splendid Test";
const objectStoreName = "People";
const objectStoreData = [
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } }
];
const indexData = [
{ name: "name", keyPath: "name", options: { unique: true, locale: true } },
{ name: "height", keyPath: "height", options: { unique: false, locale: true } },
{ name: "weight", keyPath: "weight", options: { unique: false, locale: true } }
];
const objectStoreDataNameSort = [
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } }
];
const objectStoreDataWeightSort = [
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } }
];
const objectStoreDataHeightSort = [
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } }
];
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
let objectStore = db.createObjectStore(objectStoreName);
// First, add all our data to the object store.
let addedData = 0;
for (let i in objectStoreData) {
request = objectStore.add(objectStoreData[i].value,
objectStoreData[i].key);
request.onerror = errorHandler;
request.onsuccess = function(event) {
if (++addedData == objectStoreData.length) {
testGenerator.send(event);
}
}
}
yield undefined;
ok(true, "1");
// Now create the indexes.
for (let i in indexData) {
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
indexData[i].options);
}
is(objectStore.indexNames.length, indexData.length, "Good index count");
yield undefined;
ok(true, "2");
objectStore = db.transaction(objectStoreName)
.objectStore(objectStoreName);
request = objectStore.index("height").mozGetAllKeys(65);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "3");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
"Correct key");
}
request = objectStore.index("height").mozGetAllKeys(65, 0);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "3");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
"Correct key");
}
request = objectStore.index("height").mozGetAllKeys(65, null);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "3");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
"Correct key");
}
request = objectStore.index("height").mozGetAllKeys(65, undefined);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "3");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
"Correct key");
}
request = objectStore.index("height").mozGetAllKeys();
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "4");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, objectStoreDataHeightSort.length,
"Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
}
request = objectStore.index("height").mozGetAllKeys(null, 4);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "5");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 4, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
}
request = objectStore.index("height").mozGetAllKeys(65, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
ok(true, "6");
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 1, "Correct length");
for (let i in event.target.result) {
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
"Correct key");
}
finishTest();
yield undefined;
}

View File

@ -0,0 +1,233 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var testGenerator = testSteps();
function testSteps()
{
const name = this.window ? window.location.pathname : "Splendid Test";
const objectStoreName = "People";
const objectStoreData = [
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } }
];
const indexData = [
{ name: "name", keyPath: "name", options: { unique: true, locale: true } },
{ name: "height", keyPath: "height", options: { unique: false, locale: true } },
{ name: "weight", keyPath: "weight", options: { unique: false, locale: true } }
];
const objectStoreDataNameSort = [
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } }
];
const objectStoreDataWeightSort = [
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } }
];
const objectStoreDataHeightSort = [
{ key: "237-23-7733", value: { name: "ana", height: 52, weight: 110 } },
{ key: "237-23-7735", value: { name: "\u00F3scar", height: 58, weight: 130 } },
{ key: "237-23-7732", value: { name: "\u00E1na", height: 60, weight: 120 } },
{ key: "237-23-7736", value: { name: "bob", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "\u00E9ason", height: 65 } },
{ key: "237-23-7734", value: { name: "fabio", height: 73, weight: 180 } }
];
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
let objectStore = db.createObjectStore(objectStoreName, {});
// First, add all our data to the object store.
let addedData = 0;
for (let i in objectStoreData) {
request = objectStore.add(objectStoreData[i].value,
objectStoreData[i].key);
request.onerror = errorHandler;
request.onsuccess = function(event) {
if (++addedData == objectStoreData.length) {
testGenerator.send(event);
}
}
}
event = yield undefined;
// Now create the indexes.
for (let i in indexData) {
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
indexData[i].options);
}
is(objectStore.indexNames.length, indexData.length, "Good index count");
yield undefined;
objectStore = db.transaction(objectStoreName)
.objectStore(objectStoreName);
request = objectStore.index("height").mozGetAll(65);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
request = objectStore.index("height").mozGetAll(65, 0);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
request = objectStore.index("height").mozGetAll(65, null);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
request = objectStore.index("height").mozGetAll(65, undefined);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 2, "Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
request = objectStore.index("height").mozGetAll();
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, objectStoreDataHeightSort.length,
"Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[i].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
request = objectStore.index("height").mozGetAll(null, 4);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 4, "Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[i].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
request = objectStore.index("height").mozGetAll(65, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result instanceof Array, true, "Got an array object");
is(event.target.result.length, 1, "Correct length");
for (let i in event.target.result) {
let result = event.target.result[i];
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
is(result.name, testObj.name, "Correct name");
is(result.height, testObj.height, "Correct height");
if (testObj.hasOwnProperty("weight")) {
is(result.weight, testObj.weight, "Correct weight");
}
}
finishTest();
yield undefined;
}

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,8 @@
[test_count.js]
[test_create_index.js]
[test_create_index_with_integer_keys.js]
[test_create_locale_aware_index.js]
skip-if = toolkit == 'android' # bug 864843
[test_create_objectStore.js]
[test_cursor_cycle.js]
[test_cursor_mutation.js]
@ -38,6 +40,12 @@ skip-if = toolkit == 'android' # bug 1079278
[test_invalid_version.js]
[test_key_requirements.js]
[test_keys.js]
[test_locale_aware_indexes.js]
skip-if = toolkit == 'android' # bug 864843
[test_locale_aware_index_getAll.js]
skip-if = toolkit == 'android' # bug 864843
[test_locale_aware_index_getAllObjects.js]
skip-if = toolkit == 'android' # bug 864843
[test_multientry.js]
[test_names_sorted.js]
[test_object_identity.js]