Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / getdatabasenames-failed-open.html
blob3b436f5bf4a8d45080141dd5e2fdf6f9e3ac00ba
1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script>
3 <script src="resources/shared.js"></script>
4 <script>
6 description('webkitGetDatabaseNames should only return successfully created databases');
8 function deleteDatabase(dbname)
10 return new Promise(function(resolve, reject) {
11 var request = indexedDB.deleteDatabase(dbname);
12 request.onsuccess = function() {
13 resolve(request.result);
15 request.onerror = function() {
16 reject(request.error);
18 });
21 function getDatabaseNames()
23 return new Promise(function(resolve, reject) {
24 var request = indexedDB.webkitGetDatabaseNames();
25 request.onsuccess = function() {
26 resolve(request.result);
28 request.onerror = function() {
29 reject(request.error);
31 });
34 function openDatabaseAndAbortUpgrade(dbname)
36 return new Promise(function(resolve, reject) {
37 var request = indexedDB.open(dbname, 1);
38 request.onupgradeneeded = function() {
39 request.transaction.abort();
41 request.onsuccess = function() {
42 reject(new Error('Open should not succeed'));
44 request.onerror = function() {
45 resolve();
47 });
50 setDBNameFromPath();
51 deleteDatabase(dbname)
52 .then(getDatabaseNames)
53 .then(function(names) {
54 if (names.contains(dbname))
55 throw Error('Database should have been deleted if present');
57 return openDatabaseAndAbortUpgrade(dbname);
59 .then(getDatabaseNames)
60 .then(function(names) {
61 if (names.contains(dbname))
62 throw Error('Database name should not be present');
64 testPassed('Database name was not present');
65 finishJSTest();
67 .catch(function(reason) {
68 testFailed(reason.name + ': ' + reason.message);
69 finishJSTest();
70 });
72 </script>