Bug 1504158 [wpt PR 13856] - IndexedDB: fix minor nits in databases() WPTs, a=testonly

Automatic update from web-platform-testsIndexedDB: fix minor nits in databases() WPTs

Fixing minor nits with IndexedDBFactory databases() WPTs as suggested
by jsbell@ over email
-assert_object_equals is deprecated and shouldn't be used. Prefer to
test the results explicitly, even though it's more code.
-all of the test cases use 1 for the version - we should have tests
for databases at other versions.
-the assertion messages should have the form ".... should be ...",
describing what is being asserted, rather than attempting to diagnose
the problem (it's easier to verify that the assertions match the spec
that way)
-there are a handful of lines missing semicolons
-the trailing done() should not be needed for .any.js tests

Bug: 899085
Change-Id: Ie8831c26fabe0e043ccba8238925ac7f520d1d69
Reviewed-on: https://chromium-review.googlesource.com/c/1313275
Reviewed-by: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Commit-Queue: Andreas Butler <andreasbutler@google.com>
Cr-Commit-Position: refs/heads/master@{#605128}

--

wpt-commits: 4ff6f151a21ef885d4e7a41122907862ae5ae037
wpt-pr: 13856
This commit is contained in:
Andreas Butler 2018-11-09 17:25:53 +00:00 committed by moz-wptsync-bot
parent 0477661a25
commit 50302b49b7

View File

@ -1,20 +1,29 @@
// META: script=support-promises.js
promise_test(async testCase => {
// Delete any databases that may not have been cleaned up after
// previous test runs.
assert_true(indexedDB.databases() instanceof Promise,
"databases() should return a promise.");
}, "Ensure that databases() returns a promise.");
promise_test(async testCase => {
// Delete any databases that may not have been cleaned up after previous test
// runs.
await deleteAllDatabases(testCase);
const db_name = "TestDatabase";
const db = await createNamedDatabase(testCase, db_name, ()=>{});
const databases_promise = await indexedDB.databases();
const expected_result = [
{"name": db_name, "version": 1},
];
assert_object_equals(
databases_promise,
expected_result,
"Call to databases() did not retrieve the single expected result.");
const databases_result = await indexedDB.databases();
db.close();
const expected_result = {"name": db_name, "version": 1};
assert_equals(
databases_result.length,
1,
"The result of databases() should contain one result per database.");
assert_true(
databases_result[0].name === expected_result.name
&& databases_result[0].version === expected_result.version,
"The result of databases() should be a sequence of the correct names "
+ "and versions of all databases for the origin.");
}, "Enumerate one database.");
promise_test(async testCase => {
@ -28,35 +37,81 @@ promise_test(async testCase => {
const db1 = await createNamedDatabase(testCase, db_name1, ()=>{});
const db2 = await createNamedDatabase(testCase, db_name2, ()=>{});
const db3 = await createNamedDatabase(testCase, db_name3, ()=>{});
const databases_promise = await indexedDB.databases();
db1.close();
db2.close();
db3.close();
const version_promise =
await migrateNamedDatabase(testCase, db_name2, 2, () => {});
const databases_result = await indexedDB.databases();
const expected_result = [
{"name": db_name1, "version": 1},
{"name": db_name2, "version": 1},
{"name": db_name2, "version": 2},
{"name": db_name3, "version": 1},
];
assert_object_equals(
databases_promise,
expected_result,
"Call to databases() did not retrieve the multiple expected results");
assert_equals(
databases_result.length,
expected_result.length,
"The result of databases() should contain one result per database.");
for ( let i = 0; i < expected_result.length; i += 1 ) {
result = expected_result[i];
assert_true(
databases_result.some(
e => e.name === result.name && e.version === result.version),
"The result of databases() should be a sequence of the correct names "
+ "and versions of all databases for the origin.");
}
}, "Enumerate multiple databases.");
promise_test(async testCase => {
// Add some databases and close their connections.
const db1 = await createNamedDatabase(testCase, "DB1", ()=>{});
const db2 = await createNamedDatabase(testCase, "DB2", ()=>{});
db1.onversionchange = () => { db1.close() };
db2.onversionchange = () => { db2.close() };
const db1 = await createNamedDatabase(testCase, "DB1", () => {});
const db2 = await createNamedDatabase(testCase, "DB2", () => {});
db1.close();
db2.close();
// Delete any databases that may not have been cleaned up after previous test
// runs as well as the two databases made above.
await deleteAllDatabases(testCase);
// Make sure the databases are no longer returned.
const databases_promise = await indexedDB.databases();
assert_object_equals(
databases_promise,
[],
"Call to databases() found database it should not have.")
const databases_result = await indexedDB.databases();
assert_equals(
databases_result.length,
0,
"The result of databases() should be an empty sequence for the case of "
+ "no databases for the origin.");
}, "Make sure an empty list is returned for the case of no databases.");
done();
promise_test(async testCase => {
// Delete any databases that may not have been cleaned up after previous test
// runs as well as the two databases made above.
await deleteAllDatabases(testCase);
const db1 = await createNamedDatabase(testCase, "DB1", ()=>{});
const db2 = await createNamedDatabase(testCase, "DB2", async () => {
const databases_result1 = await indexedDB.databases();
assert_equals(
databases_result1.length,
1,
"The result of databases() should be only those databases which have "
+ "been created at the time of calling, regardless of versionchange "
+ "transactions currently running.");
});
db1.close();
db2.close();
const databases_result2 = await indexedDB.databases();
assert_equals(
databases_result2.length,
2,
"The result of databases() should include all databases which have "
+ "been created at the time of calling.");
await migrateNamedDatabase(testCase, "DB2", 2, async () => {
const databases_result3 = await indexedDB.databases();
assert_true(
databases_result3[0].version === 1
&& databases_result3[1].version === 1,
"The result of databases() should contain the versions of databases "
+ "at the time of calling, regardless of versionchange transactions "
+ "currently running.");
});
}, "Ensure that databases() doesn't pick up changes that haven't commited.");