1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/apps/tests/test_receipt_operations.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,246 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id={757226} 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug {757226} Implement mozApps app.replaceReceipt</title> 1.11 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 + 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={757226}">Mozilla Bug {757226}</a> 1.18 +<p id="display"></p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="application/javascript;version=1.7"> 1.24 + 1.25 +var gManifestURL = "http://test/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true"; 1.26 +var gGenerator = runTest(); 1.27 + 1.28 +function debug(aMsg) { 1.29 + //dump("== Tests debug == " + aMsg + "\n"); 1.30 +} 1.31 + 1.32 +function go() { 1.33 + SpecialPowers.pushPermissions( 1.34 + [{ "type": "webapps-manage", "allow": 1, "context": document }], 1.35 + function() { gGenerator.next() }); 1.36 +} 1.37 + 1.38 +function continueTest() { 1.39 + try { 1.40 + gGenerator.next(); 1.41 + } catch (e if e instanceof StopIteration) { 1.42 + finish(); 1.43 + } 1.44 +} 1.45 + 1.46 +function finish() { 1.47 + SimpleTest.finish(); 1.48 +} 1.49 + 1.50 +function cbError(aError) { 1.51 + ok(false, "Error callback invoked " + aError); 1.52 + finish(); 1.53 +} 1.54 + 1.55 +SimpleTest.waitForExplicitFinish(); 1.56 + 1.57 +function runTest() { 1.58 + SpecialPowers.setAllAppsLaunchable(true); 1.59 + 1.60 + SpecialPowers.autoConfirmAppInstall(continueTest); 1.61 + yield undefined; 1.62 + 1.63 + var request = navigator.mozApps.install(gManifestURL); 1.64 + request.onerror = cbError; 1.65 + request.onsuccess = continueTest; 1.66 + yield undefined; 1.67 + 1.68 + var app = request.result; 1.69 + ok(app, "App is non-null"); 1.70 + ok(app.receipts.length == 0, "No receipts"); 1.71 + 1.72 + let receipt1 = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJwcm9kdWN0IjogeyJ1cmwiOiAiaHR0cHM6Ly93d3cubW96aWxsYS5vcmciLCAic3RvcmVkYXRhIjogIjUxNjkzMTQzNTYifSwgInJlaXNzdWUiOiAiaHR0cDovL21vY2hpLnRlc3Q6ODg4OC9yZWlzc3VlLzUxNjkzMTQzNTYiLCAidXNlciI6IHsidHlwZSI6ICJkaXJlY3RlZC1pZGVudGlmaWVyIiwgInZhbHVlIjogIjRmYjM1MTUxLTJiOWItNGJhMi04MjgzLWM0OWQzODE2NDBiZCJ9LCAidmVyaWZ5IjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgvdmVyaWZ5LzUxNjkzMTQzNTYiLCAiaXNzIjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgiLCAiaWF0IjogMTMxMzYwMTg4LCAidHlwIjogInB1cmNoYXNlLXJlY2VpcHQiLCAibmJmIjogMTMxMzYwMTg1LCAiZGV0YWlsIjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgvcmVjZWlwdC81MTY5MzE0MzU2In0.eZpTEnCLUR3iP3rm9WyJOqx1k66mQaAxqcrvX11r5E0'; 1.73 + 1.74 + let receipt2 = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJwcm9kdWN0IjogeyJ1cmwiOiAiaHR0cHM6Ly93d3cubW96aWxsYS5vcmciLCAic3RvcmVkYXRhIjogIjUxNjkzMTQzNTcifSwgInJlaXNzdWUiOiAiaHR0cDovL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Ly9tYXJrZXRwbGFjZS5maXJlZm94LmNvbSIsICJ2ZXJpZnkiOiAiaHR0cHM6Ly9yZWNlaXB0Y2hlY2subWFya2V0cGxhY2UuZmlyZWZveC5jb20vdmVyaWZ5LyIsICJkZXRhaWwiOiAiaHR0cHM6Ly9tYXJrZXRwbGFjZS5maXJlZm94LmNvbS9hcGkvdjEvcmVjZWlwdHMvcmVpc3N1ZS8iLCAicmVpc3N1ZSI6ICJodHRwczovL21hcmtldHBsYWNlLmZpcmVmb3guY29tL2FwaS92MS9yZWNlaXB0cy9yZWlzc3VlLyIsICJ1c2VyIjogeyJ0eXBlIjogImRpcmVjdGVkLWlkZW50aWZpZXIiLCAidmFsdWUiOiAiMTkzMzI2LTVjMTUzNmQ1LWUxMDQtNDAzYy04NDBlLTQ5YjMyMmQ5Yjg4NSJ9LCAiZXhwIjogMTQwMTgyNTEyOCwgImlhdCI6IDEzODYxMDAzMjgsICJ0eXAiOiAicHVyY2hhc2UtcmVjZWlwdCIsICJuYmYiOiAxMzg2MTAwMzI4fQ.r2DVUpouRDJYqZe61LJBcIwmeF2mI8FmbGMRlfNFcinKAIs8nMVVNX8xSWJ6jXXgZ62VfHJCLHapADX8rCg6NgxFV_FdP7j2H_2Ufo0E0TREifTN6V4v1dCnzDulNhZmO8G-nQJUVOAtNfNC95PY7tVa8WC7dYXnKZsD6NhIxxVEtBGuiiySpWArI-g3pcl41rXNHHpJbRfrOD4QgVNrsV83TWILYRr6PWr3aqOM2XT_x2SzEfhBNvdG8AJmR0MKQytvfcgz3Vt1hMak88nFrzTLiKkuuPAXpwB5q83LZIl4EYG3UAnte4-XWlLb-NJ78vgXa64myy-3fPr7EO6LaQ'; 1.77 + 1.78 + // Test removeReceipt or replaceReceipt when there the app doesn't have any receipt 1.79 + request = app.replaceReceipt(receipt1, receipt3); 1.80 + request.onsuccess = function() { 1.81 + ok(false, "replaceReceipt should fail if the app doesn't have any receipt"); 1.82 + } 1.83 + request.onerror = function() { 1.84 + ok(this.error.name == "NO_SUCH_RECEIPT", 1.85 + "Request failed because there isn't any receipt"); 1.86 + continueTest(); 1.87 + } 1.88 + yield undefined; 1.89 + 1.90 + request = app.removeReceipt(receipt1); 1.91 + request.onsuccess = function() { 1.92 + ok(false, "removeReceipt should fail if the app doesn't have any receipt"); 1.93 + } 1.94 + request.onerror = function() { 1.95 + ok(this.error.name == "NO_SUCH_RECEIPT", 1.96 + "Request failed because there isn't any receipt"); 1.97 + continueTest(); 1.98 + } 1.99 + yield undefined; 1.100 + 1.101 + // Test addReceipt 1.102 + request = app.addReceipt(null); 1.103 + request.onsuccess = function() { 1.104 + ok(false, "Call with missing parameter should've failed"); 1.105 + } 1.106 + request.onerror = function() { 1.107 + ok(this.error.name == "INVALID_PARAMETERS", 1.108 + "Request failed because of a missing parameter"); 1.109 + continueTest(); 1.110 + } 1.111 + yield undefined; 1.112 + 1.113 + request = app.addReceipt(receipt1); 1.114 + request.onerror = cbError; 1.115 + request.onsuccess = function() { 1.116 + ok(app.receipts.length == 1, "One receipt"); 1.117 + ok(app.receipts[0] == receipt1, "Receipt correctly added"); 1.118 + continueTest(); 1.119 + }; 1.120 + yield undefined; 1.121 + 1.122 + request = app.addReceipt(receipt1); 1.123 + request.onerror = function() { 1.124 + ok(this.error.name == "RECEIPT_ALREADY_EXISTS", 1.125 + "Request failed because the receipt already exists"); 1.126 + continueTest(); 1.127 + }; 1.128 + request.onsuccess = function() { 1.129 + ok(false, "addReceipt should fail if the receipt already exists"); 1.130 + }; 1.131 + yield undefined; 1.132 + 1.133 + request = app.addReceipt(receipt2); 1.134 + request.onerror = cbError; 1.135 + request.onsuccess = function() { 1.136 + ok(app.receipts.length == 2, "Two receipts"); 1.137 + ok(app.receipts[0] == receipt1, "First receipt is still there"); 1.138 + ok(app.receipts[1] == receipt2, "Second receipt correctly added"); 1.139 + continueTest(); 1.140 + } 1.141 + yield undefined; 1.142 + 1.143 + // Test replace receipts 1.144 + request = app.replaceReceipt(null, null); 1.145 + request.onsuccess = function() { 1.146 + ok(false, "Call with missing parameters should've failed"); 1.147 + } 1.148 + request.onerror = function() { 1.149 + ok(this.error.name == "INVALID_PARAMETERS", 1.150 + "Request failed because of missing parameters"); 1.151 + continueTest(); 1.152 + } 1.153 + yield undefined; 1.154 + 1.155 + request = app.replaceReceipt(null, receipt1); 1.156 + request.onsuccess = function() { 1.157 + ok(false, "Call with missing parameter should've failed"); 1.158 + } 1.159 + request.onerror = function() { 1.160 + ok(this.error.name == "INVALID_PARAMETERS", 1.161 + "Request failed because of a missing parameter"); 1.162 + continueTest(); 1.163 + } 1.164 + yield undefined; 1.165 + 1.166 + request = app.replaceReceipt(receipt1, null); 1.167 + request.onsuccess = function() { 1.168 + ok(false, "Call with missing parameter should've failed"); 1.169 + } 1.170 + request.onerror = function() { 1.171 + ok(this.error.name == "INVALID_PARAMETERS", 1.172 + "Request failed because of a missing parameter"); 1.173 + continueTest(); 1.174 + } 1.175 + yield undefined; 1.176 + 1.177 + request = app.replaceReceipt(receipt3, receipt1); 1.178 + request.onsuccess = function() { 1.179 + ok(false, "Call with non-existent receipt should've failed"); 1.180 + } 1.181 + request.onerror = function() { 1.182 + ok(this.error.name == "NO_SUCH_RECEIPT", 1.183 + "Exception thrown because of a non-existent receipt"); 1.184 + ok(app.receipts.length == 2, "Two receipts"); 1.185 + ok(app.receipts[0] == receipt1 && app.receipts[1] == receipt2, 1.186 + "No receipt was replaced"); 1.187 + continueTest(); 1.188 + } 1.189 + yield undefined; 1.190 + 1.191 + request = app.replaceReceipt(receipt1, receipt3); 1.192 + request.onerror = cbError; 1.193 + request.onsuccess = function() { 1.194 + ok(app.receipts.length == 2, "Two receipts"); 1.195 + ok(app.receipts[0] == receipt3, "First receipt was replaced"); 1.196 + ok(app.receipts[1] == receipt2, "Second receipt wasn't replaced"); 1.197 + continueTest(); 1.198 + } 1.199 + yield undefined; 1.200 + 1.201 + // Test remove receipt 1.202 + request = app.removeReceipt(null); 1.203 + request.onsuccess = function() { 1.204 + ok(false, "Call with missing parameter should've failed"); 1.205 + } 1.206 + request.onerror = function() { 1.207 + ok(this.error.name == "INVALID_PARAMETERS", 1.208 + "Request failed because of a missing parameter"); 1.209 + continueTest(); 1.210 + } 1.211 + yield undefined; 1.212 + 1.213 + request = app.removeReceipt(receipt1); 1.214 + request.onsuccess = function() { 1.215 + ok(false, "Call with non-existent receipt should've failed"); 1.216 + } 1.217 + request.onerror = function() { 1.218 + ok(this.error.name == "NO_SUCH_RECEIPT", 1.219 + "Exception thrown because of a non-existent receipt"); 1.220 + ok(app.receipts.length == 2, "Two receipts"); 1.221 + ok(app.receipts[0] == receipt3 && app.receipts[1] == receipt2, 1.222 + "No receipt was removed"); 1.223 + continueTest(); 1.224 + } 1.225 + yield undefined; 1.226 + 1.227 + request = app.removeReceipt(receipt3); 1.228 + request.onerror = cbError; 1.229 + request.onsuccess = function() { 1.230 + ok(app.receipts.length == 1, "One receipt"); 1.231 + ok(app.receipts[0] == receipt2, "The receipt is still alive"); 1.232 + continueTest(); 1.233 + } 1.234 + yield undefined; 1.235 + 1.236 + // Uninstall the app. 1.237 + request = navigator.mozApps.mgmt.uninstall(app); 1.238 + request.onerror = cbError; 1.239 + request.onsuccess = continueTest; 1.240 + yield undefined; 1.241 + ok(true, "App uninstalled"); 1.242 +} 1.243 + 1.244 +addLoadEvent(go); 1.245 + 1.246 +</script> 1.247 +</pre> 1.248 +</body> 1.249 +</html> 1.250 \ No newline at end of file