Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id={757226} |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug {757226} Implement mozApps app.replaceReceipt</title> |
michael@0 | 8 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={757226}">Mozilla Bug {757226}</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content" style="display: none"> |
michael@0 | 17 | |
michael@0 | 18 | </div> |
michael@0 | 19 | <pre id="test"> |
michael@0 | 20 | <script class="testbody" type="application/javascript;version=1.7"> |
michael@0 | 21 | |
michael@0 | 22 | var gManifestURL = "http://test/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true"; |
michael@0 | 23 | var gGenerator = runTest(); |
michael@0 | 24 | |
michael@0 | 25 | function debug(aMsg) { |
michael@0 | 26 | //dump("== Tests debug == " + aMsg + "\n"); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function go() { |
michael@0 | 30 | SpecialPowers.pushPermissions( |
michael@0 | 31 | [{ "type": "webapps-manage", "allow": 1, "context": document }], |
michael@0 | 32 | function() { gGenerator.next() }); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function continueTest() { |
michael@0 | 36 | try { |
michael@0 | 37 | gGenerator.next(); |
michael@0 | 38 | } catch (e if e instanceof StopIteration) { |
michael@0 | 39 | finish(); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function finish() { |
michael@0 | 44 | SimpleTest.finish(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function cbError(aError) { |
michael@0 | 48 | ok(false, "Error callback invoked " + aError); |
michael@0 | 49 | finish(); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 53 | |
michael@0 | 54 | function runTest() { |
michael@0 | 55 | SpecialPowers.setAllAppsLaunchable(true); |
michael@0 | 56 | |
michael@0 | 57 | SpecialPowers.autoConfirmAppInstall(continueTest); |
michael@0 | 58 | yield undefined; |
michael@0 | 59 | |
michael@0 | 60 | var request = navigator.mozApps.install(gManifestURL); |
michael@0 | 61 | request.onerror = cbError; |
michael@0 | 62 | request.onsuccess = continueTest; |
michael@0 | 63 | yield undefined; |
michael@0 | 64 | |
michael@0 | 65 | var app = request.result; |
michael@0 | 66 | ok(app, "App is non-null"); |
michael@0 | 67 | ok(app.receipts.length == 0, "No receipts"); |
michael@0 | 68 | |
michael@0 | 69 | let receipt1 = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJwcm9kdWN0IjogeyJ1cmwiOiAiaHR0cHM6Ly93d3cubW96aWxsYS5vcmciLCAic3RvcmVkYXRhIjogIjUxNjkzMTQzNTYifSwgInJlaXNzdWUiOiAiaHR0cDovL21vY2hpLnRlc3Q6ODg4OC9yZWlzc3VlLzUxNjkzMTQzNTYiLCAidXNlciI6IHsidHlwZSI6ICJkaXJlY3RlZC1pZGVudGlmaWVyIiwgInZhbHVlIjogIjRmYjM1MTUxLTJiOWItNGJhMi04MjgzLWM0OWQzODE2NDBiZCJ9LCAidmVyaWZ5IjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgvdmVyaWZ5LzUxNjkzMTQzNTYiLCAiaXNzIjogImh0dHA6Ly9tb2NoaS50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8rCg6NgxFV_FdP7j2H_2Ufo0E0TREifTN6V4v1dCnzDulNhZmO8G-nQJUVOAtNfNC95PY7tVa8WC7dYXnKZsD6NhIxxVEtBGuiiySpWArI-g3pcl41rXNHHpJbRfrOD4QgVNrsV83TWILYRr6PWr3aqOM2XT_x2SzEfhBNvdG8AJmR0MKQytvfcgz3Vt1hMak88nFrzTLiKkuuPAXpwB5q83LZIl4EYG3UAnte4-XWlLb-NJ78vgXa64myy-3fPr7EO6LaQ'; |
michael@0 | 74 | |
michael@0 | 75 | // Test removeReceipt or replaceReceipt when there the app doesn't have any receipt |
michael@0 | 76 | request = app.replaceReceipt(receipt1, receipt3); |
michael@0 | 77 | request.onsuccess = function() { |
michael@0 | 78 | ok(false, "replaceReceipt should fail if the app doesn't have any receipt"); |
michael@0 | 79 | } |
michael@0 | 80 | request.onerror = function() { |
michael@0 | 81 | ok(this.error.name == "NO_SUCH_RECEIPT", |
michael@0 | 82 | "Request failed because there isn't any receipt"); |
michael@0 | 83 | continueTest(); |
michael@0 | 84 | } |
michael@0 | 85 | yield undefined; |
michael@0 | 86 | |
michael@0 | 87 | request = app.removeReceipt(receipt1); |
michael@0 | 88 | request.onsuccess = function() { |
michael@0 | 89 | ok(false, "removeReceipt should fail if the app doesn't have any receipt"); |
michael@0 | 90 | } |
michael@0 | 91 | request.onerror = function() { |
michael@0 | 92 | ok(this.error.name == "NO_SUCH_RECEIPT", |
michael@0 | 93 | "Request failed because there isn't any receipt"); |
michael@0 | 94 | continueTest(); |
michael@0 | 95 | } |
michael@0 | 96 | yield undefined; |
michael@0 | 97 | |
michael@0 | 98 | // Test addReceipt |
michael@0 | 99 | request = app.addReceipt(null); |
michael@0 | 100 | request.onsuccess = function() { |
michael@0 | 101 | ok(false, "Call with missing parameter should've failed"); |
michael@0 | 102 | } |
michael@0 | 103 | request.onerror = function() { |
michael@0 | 104 | ok(this.error.name == "INVALID_PARAMETERS", |
michael@0 | 105 | "Request failed because of a missing parameter"); |
michael@0 | 106 | continueTest(); |
michael@0 | 107 | } |
michael@0 | 108 | yield undefined; |
michael@0 | 109 | |
michael@0 | 110 | request = app.addReceipt(receipt1); |
michael@0 | 111 | request.onerror = cbError; |
michael@0 | 112 | request.onsuccess = function() { |
michael@0 | 113 | ok(app.receipts.length == 1, "One receipt"); |
michael@0 | 114 | ok(app.receipts[0] == receipt1, "Receipt correctly added"); |
michael@0 | 115 | continueTest(); |
michael@0 | 116 | }; |
michael@0 | 117 | yield undefined; |
michael@0 | 118 | |
michael@0 | 119 | request = app.addReceipt(receipt1); |
michael@0 | 120 | request.onerror = function() { |
michael@0 | 121 | ok(this.error.name == "RECEIPT_ALREADY_EXISTS", |
michael@0 | 122 | "Request failed because the receipt already exists"); |
michael@0 | 123 | continueTest(); |
michael@0 | 124 | }; |
michael@0 | 125 | request.onsuccess = function() { |
michael@0 | 126 | ok(false, "addReceipt should fail if the receipt already exists"); |
michael@0 | 127 | }; |
michael@0 | 128 | yield undefined; |
michael@0 | 129 | |
michael@0 | 130 | request = app.addReceipt(receipt2); |
michael@0 | 131 | request.onerror = cbError; |
michael@0 | 132 | request.onsuccess = function() { |
michael@0 | 133 | ok(app.receipts.length == 2, "Two receipts"); |
michael@0 | 134 | ok(app.receipts[0] == receipt1, "First receipt is still there"); |
michael@0 | 135 | ok(app.receipts[1] == receipt2, "Second receipt correctly added"); |
michael@0 | 136 | continueTest(); |
michael@0 | 137 | } |
michael@0 | 138 | yield undefined; |
michael@0 | 139 | |
michael@0 | 140 | // Test replace receipts |
michael@0 | 141 | request = app.replaceReceipt(null, null); |
michael@0 | 142 | request.onsuccess = function() { |
michael@0 | 143 | ok(false, "Call with missing parameters should've failed"); |
michael@0 | 144 | } |
michael@0 | 145 | request.onerror = function() { |
michael@0 | 146 | ok(this.error.name == "INVALID_PARAMETERS", |
michael@0 | 147 | "Request failed because of missing parameters"); |
michael@0 | 148 | continueTest(); |
michael@0 | 149 | } |
michael@0 | 150 | yield undefined; |
michael@0 | 151 | |
michael@0 | 152 | request = app.replaceReceipt(null, receipt1); |
michael@0 | 153 | request.onsuccess = function() { |
michael@0 | 154 | ok(false, "Call with missing parameter should've failed"); |
michael@0 | 155 | } |
michael@0 | 156 | request.onerror = function() { |
michael@0 | 157 | ok(this.error.name == "INVALID_PARAMETERS", |
michael@0 | 158 | "Request failed because of a missing parameter"); |
michael@0 | 159 | continueTest(); |
michael@0 | 160 | } |
michael@0 | 161 | yield undefined; |
michael@0 | 162 | |
michael@0 | 163 | request = app.replaceReceipt(receipt1, null); |
michael@0 | 164 | request.onsuccess = function() { |
michael@0 | 165 | ok(false, "Call with missing parameter should've failed"); |
michael@0 | 166 | } |
michael@0 | 167 | request.onerror = function() { |
michael@0 | 168 | ok(this.error.name == "INVALID_PARAMETERS", |
michael@0 | 169 | "Request failed because of a missing parameter"); |
michael@0 | 170 | continueTest(); |
michael@0 | 171 | } |
michael@0 | 172 | yield undefined; |
michael@0 | 173 | |
michael@0 | 174 | request = app.replaceReceipt(receipt3, receipt1); |
michael@0 | 175 | request.onsuccess = function() { |
michael@0 | 176 | ok(false, "Call with non-existent receipt should've failed"); |
michael@0 | 177 | } |
michael@0 | 178 | request.onerror = function() { |
michael@0 | 179 | ok(this.error.name == "NO_SUCH_RECEIPT", |
michael@0 | 180 | "Exception thrown because of a non-existent receipt"); |
michael@0 | 181 | ok(app.receipts.length == 2, "Two receipts"); |
michael@0 | 182 | ok(app.receipts[0] == receipt1 && app.receipts[1] == receipt2, |
michael@0 | 183 | "No receipt was replaced"); |
michael@0 | 184 | continueTest(); |
michael@0 | 185 | } |
michael@0 | 186 | yield undefined; |
michael@0 | 187 | |
michael@0 | 188 | request = app.replaceReceipt(receipt1, receipt3); |
michael@0 | 189 | request.onerror = cbError; |
michael@0 | 190 | request.onsuccess = function() { |
michael@0 | 191 | ok(app.receipts.length == 2, "Two receipts"); |
michael@0 | 192 | ok(app.receipts[0] == receipt3, "First receipt was replaced"); |
michael@0 | 193 | ok(app.receipts[1] == receipt2, "Second receipt wasn't replaced"); |
michael@0 | 194 | continueTest(); |
michael@0 | 195 | } |
michael@0 | 196 | yield undefined; |
michael@0 | 197 | |
michael@0 | 198 | // Test remove receipt |
michael@0 | 199 | request = app.removeReceipt(null); |
michael@0 | 200 | request.onsuccess = function() { |
michael@0 | 201 | ok(false, "Call with missing parameter should've failed"); |
michael@0 | 202 | } |
michael@0 | 203 | request.onerror = function() { |
michael@0 | 204 | ok(this.error.name == "INVALID_PARAMETERS", |
michael@0 | 205 | "Request failed because of a missing parameter"); |
michael@0 | 206 | continueTest(); |
michael@0 | 207 | } |
michael@0 | 208 | yield undefined; |
michael@0 | 209 | |
michael@0 | 210 | request = app.removeReceipt(receipt1); |
michael@0 | 211 | request.onsuccess = function() { |
michael@0 | 212 | ok(false, "Call with non-existent receipt should've failed"); |
michael@0 | 213 | } |
michael@0 | 214 | request.onerror = function() { |
michael@0 | 215 | ok(this.error.name == "NO_SUCH_RECEIPT", |
michael@0 | 216 | "Exception thrown because of a non-existent receipt"); |
michael@0 | 217 | ok(app.receipts.length == 2, "Two receipts"); |
michael@0 | 218 | ok(app.receipts[0] == receipt3 && app.receipts[1] == receipt2, |
michael@0 | 219 | "No receipt was removed"); |
michael@0 | 220 | continueTest(); |
michael@0 | 221 | } |
michael@0 | 222 | yield undefined; |
michael@0 | 223 | |
michael@0 | 224 | request = app.removeReceipt(receipt3); |
michael@0 | 225 | request.onerror = cbError; |
michael@0 | 226 | request.onsuccess = function() { |
michael@0 | 227 | ok(app.receipts.length == 1, "One receipt"); |
michael@0 | 228 | ok(app.receipts[0] == receipt2, "The receipt is still alive"); |
michael@0 | 229 | continueTest(); |
michael@0 | 230 | } |
michael@0 | 231 | yield undefined; |
michael@0 | 232 | |
michael@0 | 233 | // Uninstall the app. |
michael@0 | 234 | request = navigator.mozApps.mgmt.uninstall(app); |
michael@0 | 235 | request.onerror = cbError; |
michael@0 | 236 | request.onsuccess = continueTest; |
michael@0 | 237 | yield undefined; |
michael@0 | 238 | ok(true, "App uninstalled"); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | addLoadEvent(go); |
michael@0 | 242 | |
michael@0 | 243 | </script> |
michael@0 | 244 | </pre> |
michael@0 | 245 | </body> |
michael@0 | 246 | </html> |