test_metadataRestore.js (3039B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 /* exported testGenerator */ 7 var testGenerator = testSteps(); 8 9 function* testSteps() { 10 const openParams = [ 11 // This one lives in storage/default/http+++localhost+81 12 { 13 url: "http://localhost:81", 14 dbName: "dbC", 15 dbVersion: 1, 16 }, 17 18 // This one lives in storage/default/http+++localhost+82 19 { 20 url: "http://localhost:82", 21 dbName: "dbD", 22 dbVersion: 1, 23 }, 24 25 // This one lives in storage/default/http+++localhost+83 26 { 27 url: "http://localhost:83", 28 dbName: "dbE", 29 dbVersion: 1, 30 }, 31 32 // This one lives in storage/default/http+++localhost+84 33 { 34 url: "http://localhost:84", 35 dbName: "dbF", 36 dbVersion: 1, 37 }, 38 39 // This one lives in storage/default/http+++localhost+85 40 { 41 url: "http://localhost:85", 42 dbName: "dbG", 43 dbVersion: 1, 44 }, 45 46 // This one lives in storage/default/http+++localhost+86 47 { 48 url: "http://localhost:86", 49 dbName: "dbH", 50 dbVersion: 1, 51 }, 52 53 // This one lives in storage/default/http+++localhost+87 54 { 55 url: "http://localhost:87", 56 dbName: "dbI", 57 dbVersion: 1, 58 }, 59 60 // This one lives in storage/default/http+++localhost+88 61 { 62 url: "http://localhost:88", 63 dbName: "dbJ", 64 dbVersion: 1, 65 }, 66 67 // This one lives in storage/default/http+++localhost+89 68 { 69 url: "http://localhost:89", 70 dbName: "dbK", 71 dbVersion: 1, 72 }, 73 74 // This one lives in storage/default/http+++localhost+90 75 { 76 url: "http://localhost:90", 77 dbName: "dbL", 78 dbVersion: 1, 79 }, 80 ]; 81 82 function openDatabase(params) { 83 let request; 84 if ("url" in params) { 85 let uri = Services.io.newURI(params.url); 86 let principal = Services.scriptSecurityManager.createContentPrincipal( 87 uri, 88 {} 89 ); 90 request = indexedDB.openForPrincipal( 91 principal, 92 params.dbName, 93 params.dbVersion 94 ); 95 } else { 96 request = indexedDB.open(params.dbName, params.dbVersion); 97 } 98 return request; 99 } 100 101 clearAllDatabases(continueToNextStepSync); 102 yield undefined; 103 104 installPackagedProfile("metadataRestore_profile"); 105 106 for (let params of openParams) { 107 let request = openDatabase(params); 108 request.onerror = errorHandler; 109 request.onupgradeneeded = unexpectedSuccessHandler; 110 request.onsuccess = grabEventAndContinueHandler; 111 let event = yield undefined; 112 113 is(event.type, "success", "Correct event type"); 114 } 115 116 resetAllDatabases(continueToNextStepSync); 117 yield undefined; 118 119 for (let params of openParams) { 120 let request = openDatabase(params); 121 request.onerror = errorHandler; 122 request.onupgradeneeded = unexpectedSuccessHandler; 123 request.onsuccess = grabEventAndContinueHandler; 124 let event = yield undefined; 125 126 is(event.type, "success", "Correct event type"); 127 } 128 129 finishTest(); 130 yield undefined; 131 }