1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/devicestorage/test/test_fs_app_permissions.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,836 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=910412 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Permission test of FileSystem API for Device Storage</title> 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <link rel="stylesheet" type="text/css" 1.15 + href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.16 +</head> 1.17 +<body> 1.18 +<a target="_blank" 1.19 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=910412">Mozilla Bug 910412</a> 1.20 +<p id="display"></p> 1.21 +<div id="content"> 1.22 + 1.23 +</div> 1.24 +<pre id="test"> 1.25 +<script type="application/javascript;version=1.7"> 1.26 + 1.27 +function randomFilename(l) { 1.28 + let set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; 1.29 + let result = ""; 1.30 + for (let i=0; i<l; i++) { 1.31 + let r = Math.floor(set.length * Math.random()); 1.32 + result += set.substring(r, r + 1); 1.33 + } 1.34 + return result; 1.35 +} 1.36 + 1.37 +function getRandomBuffer() { 1.38 + var size = 1024; 1.39 + var buffer = new ArrayBuffer(size); 1.40 + var view = new Uint8Array(buffer); 1.41 + for (var i = 0; i < size; i++) { 1.42 + view[i] = parseInt(Math.random() * 255); 1.43 + } 1.44 + return buffer; 1.45 +} 1.46 + 1.47 +function createRandomBlob(mime) { 1.48 + let size = 1024; 1.49 + let buffer = new ArrayBuffer(size); 1.50 + let view = new Uint8Array(buffer); 1.51 + for (let i = 0; i < size; i++) { 1.52 + view[i] = parseInt(Math.random() * 255); 1.53 + } 1.54 + return blob = new Blob([buffer], {type: mime}); 1.55 +} 1.56 + 1.57 +let MockPermissionPrompt = SpecialPowers.MockPermissionPrompt; 1.58 +MockPermissionPrompt.init(); 1.59 + 1.60 +SimpleTest.waitForExplicitFinish(); 1.61 + 1.62 +function TestCreateDirectory(iframe, data) { 1.63 + function cbError(e) { 1.64 + is(e.name, "SecurityError", "[TestCreateDirectory] Should fire a SecurityError for type " + data.type); 1.65 + is(data.shouldPass, false, "[TestCreateDirectory] Error callback was called for type " + data.type + '. Error: ' + e.name); 1.66 + testComplete(iframe, data); 1.67 + } 1.68 + 1.69 + let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); 1.70 + isnot(storage, null, "[TestCreateDirectory] Should be able to get storage object for " + data.type); 1.71 + 1.72 + if (!storage) { 1.73 + testComplete(iframe, data); 1.74 + return; 1.75 + } 1.76 + 1.77 + storage.getRoot().then(function(root) { 1.78 + is(data.shouldPass, true, "[TestCreateDirectory] Success callback was called for type " + data.type); 1.79 + let filename = randomFilename(100); 1.80 + root.createDirectory(filename).then(function(d) { 1.81 + let passed = d && (d.name === filename); 1.82 + is(data.shouldPass, passed, "[TestCreateDirectory] Success callback was called for type " + data.type); 1.83 + testComplete(iframe, data); 1.84 + }, cbError); 1.85 + }, cbError); 1.86 +} 1.87 + 1.88 +function TestGet(iframe, data) { 1.89 + function cbError(e) { 1.90 + is(e.name, "SecurityError", "[TestGet] Should fire a SecurityError for type " + data.type); 1.91 + is(data.shouldPass, false, "[TestGet] Error callback was called for type " + data.type + '. Error: ' + e.name); 1.92 + testComplete(iframe, data); 1.93 + } 1.94 + 1.95 + createTestFile(data.fileExtension); 1.96 + 1.97 + let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); 1.98 + isnot(storage, null, "[TestGet] Should be able to get storage object for " + data.type); 1.99 + 1.100 + if (!storage) { 1.101 + testComplete(iframe, data); 1.102 + return; 1.103 + } 1.104 + 1.105 + storage.getRoot().then(function(root) { 1.106 + ok(true, "[TestGet] Success callback of getRoot was called for type " + data.type); 1.107 + root.get("testfile" + data.fileExtension).then(function() { 1.108 + is(data.shouldPass, true, "[TestGet] Success callback was called for type " + data.type); 1.109 + testComplete(iframe, data); 1.110 + }, cbError); 1.111 + }, cbError); 1.112 +} 1.113 + 1.114 +function TestCreateFile(iframe, data) { 1.115 + function cbError(e) { 1.116 + is(e.name, "SecurityError", "[TestCreateFile] Should fire a SecurityError for type " + data.type); 1.117 + is(data.shouldPass, false, "[TestCreateFile] Error callback was called for type " + data.type + '. Error: ' + e.name); 1.118 + testComplete(iframe, data); 1.119 + } 1.120 + 1.121 + let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); 1.122 + isnot(storage, null, "[TestCreateFile] Should be able to get storage object for " + data.type); 1.123 + 1.124 + if (!storage) { 1.125 + testComplete(iframe, data); 1.126 + return; 1.127 + } 1.128 + 1.129 + storage.getRoot().then(function(root) { 1.130 + ok(true, "[TestCreateFile] Success callback of getRoot was called for type " + data.type); 1.131 + let filename = randomFilename(100) + data.fileExtension; 1.132 + root.createFile(filename, { 1.133 + data: createRandomBlob(data.mimeType), 1.134 + ifExists: "replace" 1.135 + }).then(function() { 1.136 + is(data.shouldPass, true, "[TestCreateFile] Success callback was called for type " + data.type); 1.137 + testComplete(iframe, data); 1.138 + }, cbError); 1.139 + }, cbError); 1.140 +} 1.141 + 1.142 +function TestRemove(iframe, data) { 1.143 + function cbError(e) { 1.144 + is(e.name, "SecurityError", "[TestRemove] Should fire a SecurityError for type " + data.type); 1.145 + is(data.shouldPass, false, "[TestRemove] Error callback was called for type " + data.type + '. Error: ' + e.name); 1.146 + testComplete(iframe, data); 1.147 + } 1.148 + 1.149 + createTestFile(data.fileExtension); 1.150 + 1.151 + let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); 1.152 + isnot(storage, null, "[TestRemove] Should be able to get storage object for " + data.type); 1.153 + 1.154 + if (!storage) { 1.155 + testComplete(iframe, data); 1.156 + return; 1.157 + } 1.158 + 1.159 + storage.getRoot().then(function(root) { 1.160 + ok(true, "[TestRemove] Success callback of getRoot was called for type " + data.type); 1.161 + root.remove("testfile" + data.fileExtension).then(function() { 1.162 + is(data.shouldPass, true, "[TestRemove] Success callback was called for type " + data.type); 1.163 + testComplete(iframe, data); 1.164 + }, cbError); 1.165 + }, cbError); 1.166 +} 1.167 + 1.168 +let gTestUri = "https://example.com/tests/dom/devicestorage/test/test_fs_app_permissions.html" 1.169 + 1.170 +let gData = [ 1.171 + 1.172 + // Directory#get 1.173 + 1.174 + // Web applications with no permissions 1.175 + { 1.176 + type: 'pictures', 1.177 + shouldPass: false, 1.178 + fileExtension: '.png', 1.179 + test: TestGet 1.180 + }, 1.181 + { 1.182 + type: 'videos', 1.183 + shouldPass: false, 1.184 + fileExtension: '.ogv', 1.185 + test: TestGet 1.186 + }, 1.187 + { 1.188 + type: 'videos', 1.189 + shouldPass: false, 1.190 + fileExtension: '.ogg', 1.191 + test: TestGet 1.192 + }, 1.193 + { 1.194 + type: 'music', 1.195 + shouldPass: false, 1.196 + fileExtension: '.ogg', 1.197 + test: TestGet 1.198 + }, 1.199 + { 1.200 + type: 'music', 1.201 + shouldPass: false, 1.202 + fileExtension: '.txt', 1.203 + test: TestGet 1.204 + }, 1.205 + { 1.206 + type: 'sdcard', 1.207 + shouldPass: false, 1.208 + fileExtension: '.txt', 1.209 + test: TestGet 1.210 + }, 1.211 + 1.212 + // Web applications with permission granted 1.213 + { 1.214 + type: 'pictures', 1.215 + shouldPass: true, 1.216 + fileExtension: '.png', 1.217 + 1.218 + permissions: ["device-storage:pictures"], 1.219 + 1.220 + test: TestGet 1.221 + }, 1.222 + { 1.223 + type: 'videos', 1.224 + shouldPass: true, 1.225 + fileExtension: '.ogv', 1.226 + 1.227 + permissions: ["device-storage:videos"], 1.228 + 1.229 + test: TestGet 1.230 + }, 1.231 + { 1.232 + type: 'videos', 1.233 + shouldPass: true, 1.234 + fileExtension: '.ogg', 1.235 + 1.236 + permissions: ["device-storage:videos"], 1.237 + 1.238 + test: TestGet 1.239 + }, 1.240 + { 1.241 + type: 'music', 1.242 + shouldPass: true, 1.243 + fileExtension: '.ogg', 1.244 + 1.245 + permissions: ["device-storage:music"], 1.246 + 1.247 + test: TestGet 1.248 + }, 1.249 + { 1.250 + type: 'music', 1.251 + shouldPass: false, 1.252 + fileExtension: '.txt', 1.253 + 1.254 + permissions: ["device-storage:music"], 1.255 + 1.256 + test: TestGet 1.257 + }, 1.258 + { 1.259 + type: 'sdcard', 1.260 + shouldPass: true, 1.261 + fileExtension: '.txt', 1.262 + 1.263 + permissions: ["device-storage:sdcard"], 1.264 + 1.265 + test: TestGet 1.266 + }, 1.267 + 1.268 + // Certified application with permision granted 1.269 + { 1.270 + type: 'pictures', 1.271 + shouldPass: true, 1.272 + fileExtension: '.png', 1.273 + 1.274 + app: "https://example.com/manifest_cert.webapp", 1.275 + permissions: ["device-storage:pictures"], 1.276 + 1.277 + test: TestGet 1.278 + }, 1.279 + { 1.280 + type: 'videos', 1.281 + shouldPass: true, 1.282 + fileExtension: '.ogv', 1.283 + 1.284 + app: "https://example.com/manifest_cert.webapp", 1.285 + permissions: ["device-storage:videos"], 1.286 + 1.287 + test: TestGet 1.288 + }, 1.289 + { 1.290 + type: 'videos', 1.291 + shouldPass: true, 1.292 + fileExtension: '.ogg', 1.293 + 1.294 + app: "https://example.com/manifest_cert.webapp", 1.295 + permissions: ["device-storage:videos"], 1.296 + 1.297 + test: TestGet 1.298 + }, 1.299 + { 1.300 + type: 'music', 1.301 + shouldPass: true, 1.302 + fileExtension: '.ogg', 1.303 + 1.304 + app: "https://example.com/manifest_cert.webapp", 1.305 + permissions: ["device-storage:music"], 1.306 + 1.307 + test: TestGet 1.308 + }, 1.309 + { 1.310 + type: 'music', 1.311 + shouldPass: false, 1.312 + fileExtension: '.txt', 1.313 + 1.314 + app: "https://example.com/manifest_cert.webapp", 1.315 + permissions: ["device-storage:music"], 1.316 + 1.317 + test: TestGet 1.318 + }, 1.319 + { 1.320 + type: 'sdcard', 1.321 + shouldPass: true, 1.322 + fileExtension: '.txt', 1.323 + 1.324 + app: "https://example.com/manifest_cert.webapp", 1.325 + permissions: ["device-storage:sdcard"], 1.326 + 1.327 + test: TestGet 1.328 + }, 1.329 + 1.330 + // Directory#createDirectory 1.331 + 1.332 + // Web applications with no permissions 1.333 + { 1.334 + type: 'pictures', 1.335 + shouldPass: false, 1.336 + test: TestCreateDirectory 1.337 + }, 1.338 + { 1.339 + type: 'videos', 1.340 + shouldPass: false, 1.341 + test: TestCreateDirectory 1.342 + }, 1.343 + { 1.344 + type: 'music', 1.345 + shouldPass: false, 1.346 + test: TestCreateDirectory 1.347 + }, 1.348 + { 1.349 + type: 'sdcard', 1.350 + shouldPass: false, 1.351 + test: TestCreateDirectory 1.352 + }, 1.353 + 1.354 + // Web applications with permission granted 1.355 + { 1.356 + type: 'pictures', 1.357 + shouldPass: true, 1.358 + 1.359 + permissions: ["device-storage:pictures"], 1.360 + 1.361 + test: TestCreateDirectory 1.362 + }, 1.363 + { 1.364 + type: 'videos', 1.365 + shouldPass: true, 1.366 + 1.367 + permissions: ["device-storage:videos"], 1.368 + 1.369 + test: TestCreateDirectory 1.370 + }, 1.371 + { 1.372 + type: 'music', 1.373 + shouldPass: true, 1.374 + 1.375 + permissions: ["device-storage:music"], 1.376 + 1.377 + test: TestCreateDirectory 1.378 + }, 1.379 + { 1.380 + type: 'sdcard', 1.381 + shouldPass: true, 1.382 + 1.383 + permissions: ["device-storage:sdcard"], 1.384 + 1.385 + test: TestCreateDirectory 1.386 + }, 1.387 + 1.388 + // Certified application with permision granted 1.389 + { 1.390 + type: 'pictures', 1.391 + shouldPass: true, 1.392 + 1.393 + app: "https://example.com/manifest_cert.webapp", 1.394 + permissions: ["device-storage:pictures"], 1.395 + 1.396 + test: TestCreateDirectory 1.397 + }, 1.398 + { 1.399 + type: 'videos', 1.400 + shouldPass: true, 1.401 + 1.402 + app: "https://example.com/manifest_cert.webapp", 1.403 + permissions: ["device-storage:videos"], 1.404 + 1.405 + test: TestCreateDirectory 1.406 + }, 1.407 + { 1.408 + type: 'music', 1.409 + shouldPass: true, 1.410 + 1.411 + app: "https://example.com/manifest_cert.webapp", 1.412 + permissions: ["device-storage:music"], 1.413 + 1.414 + test: TestCreateDirectory 1.415 + }, 1.416 + { 1.417 + type: 'sdcard', 1.418 + shouldPass: true, 1.419 + 1.420 + app: "https://example.com/manifest_cert.webapp", 1.421 + permissions: ["device-storage:sdcard"], 1.422 + 1.423 + test: TestCreateDirectory 1.424 + }, 1.425 + 1.426 + // Directory#createFile 1.427 + 1.428 + // Web applications with no permissions 1.429 + { 1.430 + type: 'pictures', 1.431 + mimeType: 'image/png', 1.432 + shouldPass: false, 1.433 + fileExtension: '.png', 1.434 + test: TestCreateFile 1.435 + }, 1.436 + { 1.437 + type: 'videos', 1.438 + mimeType: 'video/ogv', 1.439 + shouldPass: false, 1.440 + fileExtension: '.ogv', 1.441 + test: TestCreateFile 1.442 + }, 1.443 + { 1.444 + type: 'videos', 1.445 + mimeType: 'video/ogg', 1.446 + shouldPass: false, 1.447 + fileExtension: '.ogg', 1.448 + test: TestCreateFile 1.449 + }, 1.450 + { 1.451 + type: 'music', 1.452 + mimeType: 'audio/ogg', 1.453 + shouldPass: false, 1.454 + fileExtension: '.ogg', 1.455 + test: TestCreateFile 1.456 + }, 1.457 + { 1.458 + type: 'music', 1.459 + mimeType: 'audio/ogg', 1.460 + shouldPass: false, 1.461 + fileExtension: '.txt', 1.462 + test: TestCreateFile 1.463 + }, 1.464 + { 1.465 + type: 'sdcard', 1.466 + mimeType: 'text/plain', 1.467 + shouldPass: false, 1.468 + fileExtension: '.txt', 1.469 + test: TestCreateFile 1.470 + }, 1.471 + 1.472 + // Web applications with permission granted 1.473 + { 1.474 + type: 'pictures', 1.475 + mimeType: 'image/png', 1.476 + shouldPass: true, 1.477 + fileExtension: '.png', 1.478 + 1.479 + permissions: ["device-storage:pictures"], 1.480 + 1.481 + test: TestCreateFile 1.482 + }, 1.483 + { 1.484 + type: 'videos', 1.485 + mimeType: 'video/ogv', 1.486 + shouldPass: true, 1.487 + fileExtension: '.ogv', 1.488 + 1.489 + permissions: ["device-storage:videos"], 1.490 + 1.491 + test: TestCreateFile 1.492 + }, 1.493 + { 1.494 + type: 'videos', 1.495 + mimeType: 'video/ogg', 1.496 + shouldPass: true, 1.497 + fileExtension: '.ogg', 1.498 + 1.499 + permissions: ["device-storage:videos"], 1.500 + 1.501 + test: TestCreateFile 1.502 + }, 1.503 + { 1.504 + type: 'music', 1.505 + mimeType: 'audio/ogg', 1.506 + shouldPass: true, 1.507 + fileExtension: '.ogg', 1.508 + 1.509 + permissions: ["device-storage:music"], 1.510 + 1.511 + test: TestCreateFile 1.512 + }, 1.513 + { 1.514 + type: 'music', 1.515 + mimeType: 'audio/ogg', 1.516 + shouldPass: false, 1.517 + fileExtension: '.txt', 1.518 + 1.519 + permissions: ["device-storage:music"], 1.520 + 1.521 + test: TestCreateFile 1.522 + }, 1.523 + { 1.524 + type: 'sdcard', 1.525 + mimeType: 'text/plain', 1.526 + shouldPass: true, 1.527 + fileExtension: '.txt', 1.528 + 1.529 + permissions: ["device-storage:sdcard"], 1.530 + 1.531 + test: TestCreateFile 1.532 + }, 1.533 + 1.534 + // Certified application with permision granted 1.535 + { 1.536 + type: 'pictures', 1.537 + mimeType: 'image/png', 1.538 + shouldPass: true, 1.539 + fileExtension: '.png', 1.540 + 1.541 + app: "https://example.com/manifest_cert.webapp", 1.542 + permissions: ["device-storage:pictures"], 1.543 + 1.544 + test: TestCreateFile 1.545 + }, 1.546 + { 1.547 + type: 'videos', 1.548 + mimeType: 'video/ogv', 1.549 + shouldPass: true, 1.550 + fileExtension: '.ogv', 1.551 + 1.552 + app: "https://example.com/manifest_cert.webapp", 1.553 + permissions: ["device-storage:videos"], 1.554 + 1.555 + test: TestCreateFile 1.556 + }, 1.557 + { 1.558 + type: 'videos', 1.559 + mimeType: 'video/ogg', 1.560 + shouldPass: true, 1.561 + fileExtension: '.ogg', 1.562 + 1.563 + app: "https://example.com/manifest_cert.webapp", 1.564 + permissions: ["device-storage:videos"], 1.565 + 1.566 + test: TestCreateFile 1.567 + }, 1.568 + { 1.569 + type: 'music', 1.570 + mimeType: 'audio/ogg', 1.571 + shouldPass: true, 1.572 + fileExtension: '.ogg', 1.573 + 1.574 + app: "https://example.com/manifest_cert.webapp", 1.575 + permissions: ["device-storage:music"], 1.576 + 1.577 + test: TestCreateFile 1.578 + }, 1.579 + { 1.580 + type: 'music', 1.581 + mimeType: 'audio/ogg', 1.582 + shouldPass: false, 1.583 + fileExtension: '.txt', 1.584 + 1.585 + app: "https://example.com/manifest_cert.webapp", 1.586 + permissions: ["device-storage:music"], 1.587 + 1.588 + test: TestCreateFile 1.589 + }, 1.590 + { 1.591 + type: 'sdcard', 1.592 + mimeType: 'text/plain', 1.593 + shouldPass: true, 1.594 + fileExtension: '.txt', 1.595 + 1.596 + app: "https://example.com/manifest_cert.webapp", 1.597 + permissions: ["device-storage:sdcard"], 1.598 + 1.599 + test: TestCreateFile 1.600 + }, 1.601 + 1.602 + // Directory#remove 1.603 + 1.604 + // Web applications with no permissions 1.605 + { 1.606 + type: 'pictures', 1.607 + shouldPass: false, 1.608 + fileExtension: '.png', 1.609 + test: TestRemove 1.610 + }, 1.611 + { 1.612 + type: 'videos', 1.613 + shouldPass: false, 1.614 + fileExtension: '.ogv', 1.615 + test: TestRemove 1.616 + }, 1.617 + { 1.618 + type: 'videos', 1.619 + shouldPass: false, 1.620 + fileExtension: '.ogg', 1.621 + test: TestRemove 1.622 + }, 1.623 + { 1.624 + type: 'music', 1.625 + shouldPass: false, 1.626 + fileExtension: '.ogg', 1.627 + test: TestRemove 1.628 + }, 1.629 + { 1.630 + type: 'music', 1.631 + shouldPass: false, 1.632 + fileExtension: '.txt', 1.633 + test: TestRemove 1.634 + }, 1.635 + { 1.636 + type: 'sdcard', 1.637 + shouldPass: false, 1.638 + fileExtension: '.txt', 1.639 + test: TestRemove 1.640 + }, 1.641 + 1.642 + // Web applications with permission granted 1.643 + { 1.644 + type: 'pictures', 1.645 + shouldPass: true, 1.646 + fileExtension: '.png', 1.647 + 1.648 + permissions: ["device-storage:pictures"], 1.649 + 1.650 + test: TestRemove 1.651 + }, 1.652 + { 1.653 + type: 'videos', 1.654 + shouldPass: true, 1.655 + fileExtension: '.ogv', 1.656 + 1.657 + permissions: ["device-storage:videos"], 1.658 + 1.659 + test: TestRemove 1.660 + }, 1.661 + { 1.662 + type: 'videos', 1.663 + shouldPass: true, 1.664 + fileExtension: '.ogg', 1.665 + 1.666 + permissions: ["device-storage:videos"], 1.667 + 1.668 + test: TestRemove 1.669 + }, 1.670 + { 1.671 + type: 'music', 1.672 + shouldPass: true, 1.673 + fileExtension: '.ogg', 1.674 + 1.675 + permissions: ["device-storage:music"], 1.676 + 1.677 + test: TestRemove 1.678 + }, 1.679 + { 1.680 + type: 'music', 1.681 + shouldPass: false, 1.682 + fileExtension: '.txt', 1.683 + 1.684 + permissions: ["device-storage:music"], 1.685 + 1.686 + test: TestRemove 1.687 + }, 1.688 + { 1.689 + type: 'sdcard', 1.690 + shouldPass: true, 1.691 + fileExtension: '.txt', 1.692 + 1.693 + permissions: ["device-storage:sdcard"], 1.694 + 1.695 + test: TestRemove 1.696 + }, 1.697 + 1.698 + // Certified application with permision granted 1.699 + { 1.700 + type: 'pictures', 1.701 + shouldPass: true, 1.702 + fileExtension: '.png', 1.703 + 1.704 + app: "https://example.com/manifest_cert.webapp", 1.705 + permissions: ["device-storage:pictures"], 1.706 + 1.707 + test: TestRemove 1.708 + }, 1.709 + { 1.710 + type: 'videos', 1.711 + shouldPass: true, 1.712 + fileExtension: '.ogv', 1.713 + 1.714 + app: "https://example.com/manifest_cert.webapp", 1.715 + permissions: ["device-storage:videos"], 1.716 + 1.717 + test: TestRemove 1.718 + }, 1.719 + { 1.720 + type: 'videos', 1.721 + shouldPass: true, 1.722 + fileExtension: '.ogg', 1.723 + 1.724 + app: "https://example.com/manifest_cert.webapp", 1.725 + permissions: ["device-storage:videos"], 1.726 + 1.727 + test: TestRemove 1.728 + }, 1.729 + { 1.730 + type: 'music', 1.731 + shouldPass: true, 1.732 + fileExtension: '.ogg', 1.733 + 1.734 + app: "https://example.com/manifest_cert.webapp", 1.735 + permissions: ["device-storage:music"], 1.736 + 1.737 + test: TestRemove 1.738 + }, 1.739 + { 1.740 + type: 'music', 1.741 + shouldPass: false, 1.742 + fileExtension: '.txt', 1.743 + 1.744 + app: "https://example.com/manifest_cert.webapp", 1.745 + permissions: ["device-storage:music"], 1.746 + 1.747 + test: TestRemove 1.748 + }, 1.749 + { 1.750 + type: 'sdcard', 1.751 + shouldPass: true, 1.752 + fileExtension: '.txt', 1.753 + 1.754 + app: "https://example.com/manifest_cert.webapp", 1.755 + permissions: ["device-storage:sdcard"], 1.756 + 1.757 + test: TestRemove 1.758 + } 1.759 + 1.760 +]; 1.761 + 1.762 +function setupTest(iframe,data) { 1.763 + if (data.permissions) { 1.764 + for (let j in data.permissions) { 1.765 + SpecialPowers.addPermission(data.permissions[j], true, iframe.contentDocument); 1.766 + } 1.767 + } 1.768 +} 1.769 + 1.770 +function testComplete(iframe, data) { 1.771 + if (data.permissions) { 1.772 + for (let j in data.permissions) { 1.773 + SpecialPowers.removePermission(data.permissions[j], iframe.contentDocument); 1.774 + } 1.775 + } 1.776 + 1.777 + document.getElementById('content').removeChild(iframe); 1.778 + 1.779 + if (gData.length == 0) { 1.780 + SimpleTest.finish(); 1.781 + } else { 1.782 + gTestRunner.next(); 1.783 + } 1.784 +} 1.785 + 1.786 +function runTest() { 1.787 + while (gData.length > 0) { 1.788 + let iframe = document.createElement('iframe'); 1.789 + let data = gData.shift(); 1.790 + 1.791 + iframe.setAttribute('mozbrowser', ''); 1.792 + if (data.app) { 1.793 + iframe.setAttribute('mozapp', data.app); 1.794 + } 1.795 + 1.796 + iframe.src = gTestUri; 1.797 + 1.798 + iframe.addEventListener('load', function(e) { 1.799 + setupTest(iframe, data) 1.800 + data.test(iframe, data); 1.801 + }); 1.802 + 1.803 + document.getElementById('content').appendChild(iframe); 1.804 + yield undefined; 1.805 + } 1.806 +} 1.807 + 1.808 +function createTestFile(extension) { 1.809 + try { 1.810 + const Cc = SpecialPowers.Cc; 1.811 + const Ci = SpecialPowers.Ci; 1.812 + let directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); 1.813 + let f = directoryService.get("TmpD", Ci.nsIFile); 1.814 + f.appendRelativePath("device-storage-testing"); 1.815 + f.remove(true); 1.816 + f.appendRelativePath("testfile" + extension); 1.817 + f.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); 1.818 + } catch(e) {} 1.819 +} 1.820 + 1.821 +let gTestRunner = runTest(); 1.822 +SpecialPowers.addPermission("browser", true, gTestUri); 1.823 + 1.824 +// We are more permissive with CSP in our testing environment.... 1.825 +const DEFAULT_CSP_PRIV = "default-src *; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'"; 1.826 +const DEFAULT_CSP_CERT = "default-src *; script-src 'self'; style-src 'self'; object-src 'none'"; 1.827 + 1.828 +SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true], 1.829 + ["device.storage.enabled", true], 1.830 + ["device.storage.testing", true], 1.831 + ["device.storage.prompt.testing", false], 1.832 + ["security.apps.privileged.CSP.default", DEFAULT_CSP_PRIV], 1.833 + ["security.apps.certified.CSP.default", DEFAULT_CSP_CERT]]}, 1.834 + function() { gTestRunner.next(); }); 1.835 + 1.836 +</script> 1.837 +</pre> 1.838 +</body> 1.839 +</html>