Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=910412 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Permission test of FileSystem API for Device Storage</title> |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" |
michael@0 | 12 | href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
michael@0 | 13 | </head> |
michael@0 | 14 | <body> |
michael@0 | 15 | <a target="_blank" |
michael@0 | 16 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=910412">Mozilla Bug 910412</a> |
michael@0 | 17 | <p id="display"></p> |
michael@0 | 18 | <div id="content"> |
michael@0 | 19 | |
michael@0 | 20 | </div> |
michael@0 | 21 | <pre id="test"> |
michael@0 | 22 | <script type="application/javascript;version=1.7"> |
michael@0 | 23 | |
michael@0 | 24 | function randomFilename(l) { |
michael@0 | 25 | let set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; |
michael@0 | 26 | let result = ""; |
michael@0 | 27 | for (let i=0; i<l; i++) { |
michael@0 | 28 | let r = Math.floor(set.length * Math.random()); |
michael@0 | 29 | result += set.substring(r, r + 1); |
michael@0 | 30 | } |
michael@0 | 31 | return result; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function getRandomBuffer() { |
michael@0 | 35 | var size = 1024; |
michael@0 | 36 | var buffer = new ArrayBuffer(size); |
michael@0 | 37 | var view = new Uint8Array(buffer); |
michael@0 | 38 | for (var i = 0; i < size; i++) { |
michael@0 | 39 | view[i] = parseInt(Math.random() * 255); |
michael@0 | 40 | } |
michael@0 | 41 | return buffer; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function createRandomBlob(mime) { |
michael@0 | 45 | let size = 1024; |
michael@0 | 46 | let buffer = new ArrayBuffer(size); |
michael@0 | 47 | let view = new Uint8Array(buffer); |
michael@0 | 48 | for (let i = 0; i < size; i++) { |
michael@0 | 49 | view[i] = parseInt(Math.random() * 255); |
michael@0 | 50 | } |
michael@0 | 51 | return blob = new Blob([buffer], {type: mime}); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | let MockPermissionPrompt = SpecialPowers.MockPermissionPrompt; |
michael@0 | 55 | MockPermissionPrompt.init(); |
michael@0 | 56 | |
michael@0 | 57 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 58 | |
michael@0 | 59 | function TestCreateDirectory(iframe, data) { |
michael@0 | 60 | function cbError(e) { |
michael@0 | 61 | is(e.name, "SecurityError", "[TestCreateDirectory] Should fire a SecurityError for type " + data.type); |
michael@0 | 62 | is(data.shouldPass, false, "[TestCreateDirectory] Error callback was called for type " + data.type + '. Error: ' + e.name); |
michael@0 | 63 | testComplete(iframe, data); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 67 | isnot(storage, null, "[TestCreateDirectory] Should be able to get storage object for " + data.type); |
michael@0 | 68 | |
michael@0 | 69 | if (!storage) { |
michael@0 | 70 | testComplete(iframe, data); |
michael@0 | 71 | return; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | storage.getRoot().then(function(root) { |
michael@0 | 75 | is(data.shouldPass, true, "[TestCreateDirectory] Success callback was called for type " + data.type); |
michael@0 | 76 | let filename = randomFilename(100); |
michael@0 | 77 | root.createDirectory(filename).then(function(d) { |
michael@0 | 78 | let passed = d && (d.name === filename); |
michael@0 | 79 | is(data.shouldPass, passed, "[TestCreateDirectory] Success callback was called for type " + data.type); |
michael@0 | 80 | testComplete(iframe, data); |
michael@0 | 81 | }, cbError); |
michael@0 | 82 | }, cbError); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function TestGet(iframe, data) { |
michael@0 | 86 | function cbError(e) { |
michael@0 | 87 | is(e.name, "SecurityError", "[TestGet] Should fire a SecurityError for type " + data.type); |
michael@0 | 88 | is(data.shouldPass, false, "[TestGet] Error callback was called for type " + data.type + '. Error: ' + e.name); |
michael@0 | 89 | testComplete(iframe, data); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | createTestFile(data.fileExtension); |
michael@0 | 93 | |
michael@0 | 94 | let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 95 | isnot(storage, null, "[TestGet] Should be able to get storage object for " + data.type); |
michael@0 | 96 | |
michael@0 | 97 | if (!storage) { |
michael@0 | 98 | testComplete(iframe, data); |
michael@0 | 99 | return; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | storage.getRoot().then(function(root) { |
michael@0 | 103 | ok(true, "[TestGet] Success callback of getRoot was called for type " + data.type); |
michael@0 | 104 | root.get("testfile" + data.fileExtension).then(function() { |
michael@0 | 105 | is(data.shouldPass, true, "[TestGet] Success callback was called for type " + data.type); |
michael@0 | 106 | testComplete(iframe, data); |
michael@0 | 107 | }, cbError); |
michael@0 | 108 | }, cbError); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function TestCreateFile(iframe, data) { |
michael@0 | 112 | function cbError(e) { |
michael@0 | 113 | is(e.name, "SecurityError", "[TestCreateFile] Should fire a SecurityError for type " + data.type); |
michael@0 | 114 | is(data.shouldPass, false, "[TestCreateFile] Error callback was called for type " + data.type + '. Error: ' + e.name); |
michael@0 | 115 | testComplete(iframe, data); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 119 | isnot(storage, null, "[TestCreateFile] Should be able to get storage object for " + data.type); |
michael@0 | 120 | |
michael@0 | 121 | if (!storage) { |
michael@0 | 122 | testComplete(iframe, data); |
michael@0 | 123 | return; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | storage.getRoot().then(function(root) { |
michael@0 | 127 | ok(true, "[TestCreateFile] Success callback of getRoot was called for type " + data.type); |
michael@0 | 128 | let filename = randomFilename(100) + data.fileExtension; |
michael@0 | 129 | root.createFile(filename, { |
michael@0 | 130 | data: createRandomBlob(data.mimeType), |
michael@0 | 131 | ifExists: "replace" |
michael@0 | 132 | }).then(function() { |
michael@0 | 133 | is(data.shouldPass, true, "[TestCreateFile] Success callback was called for type " + data.type); |
michael@0 | 134 | testComplete(iframe, data); |
michael@0 | 135 | }, cbError); |
michael@0 | 136 | }, cbError); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | function TestRemove(iframe, data) { |
michael@0 | 140 | function cbError(e) { |
michael@0 | 141 | is(e.name, "SecurityError", "[TestRemove] Should fire a SecurityError for type " + data.type); |
michael@0 | 142 | is(data.shouldPass, false, "[TestRemove] Error callback was called for type " + data.type + '. Error: ' + e.name); |
michael@0 | 143 | testComplete(iframe, data); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | createTestFile(data.fileExtension); |
michael@0 | 147 | |
michael@0 | 148 | let storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 149 | isnot(storage, null, "[TestRemove] Should be able to get storage object for " + data.type); |
michael@0 | 150 | |
michael@0 | 151 | if (!storage) { |
michael@0 | 152 | testComplete(iframe, data); |
michael@0 | 153 | return; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | storage.getRoot().then(function(root) { |
michael@0 | 157 | ok(true, "[TestRemove] Success callback of getRoot was called for type " + data.type); |
michael@0 | 158 | root.remove("testfile" + data.fileExtension).then(function() { |
michael@0 | 159 | is(data.shouldPass, true, "[TestRemove] Success callback was called for type " + data.type); |
michael@0 | 160 | testComplete(iframe, data); |
michael@0 | 161 | }, cbError); |
michael@0 | 162 | }, cbError); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | let gTestUri = "https://example.com/tests/dom/devicestorage/test/test_fs_app_permissions.html" |
michael@0 | 166 | |
michael@0 | 167 | let gData = [ |
michael@0 | 168 | |
michael@0 | 169 | // Directory#get |
michael@0 | 170 | |
michael@0 | 171 | // Web applications with no permissions |
michael@0 | 172 | { |
michael@0 | 173 | type: 'pictures', |
michael@0 | 174 | shouldPass: false, |
michael@0 | 175 | fileExtension: '.png', |
michael@0 | 176 | test: TestGet |
michael@0 | 177 | }, |
michael@0 | 178 | { |
michael@0 | 179 | type: 'videos', |
michael@0 | 180 | shouldPass: false, |
michael@0 | 181 | fileExtension: '.ogv', |
michael@0 | 182 | test: TestGet |
michael@0 | 183 | }, |
michael@0 | 184 | { |
michael@0 | 185 | type: 'videos', |
michael@0 | 186 | shouldPass: false, |
michael@0 | 187 | fileExtension: '.ogg', |
michael@0 | 188 | test: TestGet |
michael@0 | 189 | }, |
michael@0 | 190 | { |
michael@0 | 191 | type: 'music', |
michael@0 | 192 | shouldPass: false, |
michael@0 | 193 | fileExtension: '.ogg', |
michael@0 | 194 | test: TestGet |
michael@0 | 195 | }, |
michael@0 | 196 | { |
michael@0 | 197 | type: 'music', |
michael@0 | 198 | shouldPass: false, |
michael@0 | 199 | fileExtension: '.txt', |
michael@0 | 200 | test: TestGet |
michael@0 | 201 | }, |
michael@0 | 202 | { |
michael@0 | 203 | type: 'sdcard', |
michael@0 | 204 | shouldPass: false, |
michael@0 | 205 | fileExtension: '.txt', |
michael@0 | 206 | test: TestGet |
michael@0 | 207 | }, |
michael@0 | 208 | |
michael@0 | 209 | // Web applications with permission granted |
michael@0 | 210 | { |
michael@0 | 211 | type: 'pictures', |
michael@0 | 212 | shouldPass: true, |
michael@0 | 213 | fileExtension: '.png', |
michael@0 | 214 | |
michael@0 | 215 | permissions: ["device-storage:pictures"], |
michael@0 | 216 | |
michael@0 | 217 | test: TestGet |
michael@0 | 218 | }, |
michael@0 | 219 | { |
michael@0 | 220 | type: 'videos', |
michael@0 | 221 | shouldPass: true, |
michael@0 | 222 | fileExtension: '.ogv', |
michael@0 | 223 | |
michael@0 | 224 | permissions: ["device-storage:videos"], |
michael@0 | 225 | |
michael@0 | 226 | test: TestGet |
michael@0 | 227 | }, |
michael@0 | 228 | { |
michael@0 | 229 | type: 'videos', |
michael@0 | 230 | shouldPass: true, |
michael@0 | 231 | fileExtension: '.ogg', |
michael@0 | 232 | |
michael@0 | 233 | permissions: ["device-storage:videos"], |
michael@0 | 234 | |
michael@0 | 235 | test: TestGet |
michael@0 | 236 | }, |
michael@0 | 237 | { |
michael@0 | 238 | type: 'music', |
michael@0 | 239 | shouldPass: true, |
michael@0 | 240 | fileExtension: '.ogg', |
michael@0 | 241 | |
michael@0 | 242 | permissions: ["device-storage:music"], |
michael@0 | 243 | |
michael@0 | 244 | test: TestGet |
michael@0 | 245 | }, |
michael@0 | 246 | { |
michael@0 | 247 | type: 'music', |
michael@0 | 248 | shouldPass: false, |
michael@0 | 249 | fileExtension: '.txt', |
michael@0 | 250 | |
michael@0 | 251 | permissions: ["device-storage:music"], |
michael@0 | 252 | |
michael@0 | 253 | test: TestGet |
michael@0 | 254 | }, |
michael@0 | 255 | { |
michael@0 | 256 | type: 'sdcard', |
michael@0 | 257 | shouldPass: true, |
michael@0 | 258 | fileExtension: '.txt', |
michael@0 | 259 | |
michael@0 | 260 | permissions: ["device-storage:sdcard"], |
michael@0 | 261 | |
michael@0 | 262 | test: TestGet |
michael@0 | 263 | }, |
michael@0 | 264 | |
michael@0 | 265 | // Certified application with permision granted |
michael@0 | 266 | { |
michael@0 | 267 | type: 'pictures', |
michael@0 | 268 | shouldPass: true, |
michael@0 | 269 | fileExtension: '.png', |
michael@0 | 270 | |
michael@0 | 271 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 272 | permissions: ["device-storage:pictures"], |
michael@0 | 273 | |
michael@0 | 274 | test: TestGet |
michael@0 | 275 | }, |
michael@0 | 276 | { |
michael@0 | 277 | type: 'videos', |
michael@0 | 278 | shouldPass: true, |
michael@0 | 279 | fileExtension: '.ogv', |
michael@0 | 280 | |
michael@0 | 281 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 282 | permissions: ["device-storage:videos"], |
michael@0 | 283 | |
michael@0 | 284 | test: TestGet |
michael@0 | 285 | }, |
michael@0 | 286 | { |
michael@0 | 287 | type: 'videos', |
michael@0 | 288 | shouldPass: true, |
michael@0 | 289 | fileExtension: '.ogg', |
michael@0 | 290 | |
michael@0 | 291 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 292 | permissions: ["device-storage:videos"], |
michael@0 | 293 | |
michael@0 | 294 | test: TestGet |
michael@0 | 295 | }, |
michael@0 | 296 | { |
michael@0 | 297 | type: 'music', |
michael@0 | 298 | shouldPass: true, |
michael@0 | 299 | fileExtension: '.ogg', |
michael@0 | 300 | |
michael@0 | 301 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 302 | permissions: ["device-storage:music"], |
michael@0 | 303 | |
michael@0 | 304 | test: TestGet |
michael@0 | 305 | }, |
michael@0 | 306 | { |
michael@0 | 307 | type: 'music', |
michael@0 | 308 | shouldPass: false, |
michael@0 | 309 | fileExtension: '.txt', |
michael@0 | 310 | |
michael@0 | 311 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 312 | permissions: ["device-storage:music"], |
michael@0 | 313 | |
michael@0 | 314 | test: TestGet |
michael@0 | 315 | }, |
michael@0 | 316 | { |
michael@0 | 317 | type: 'sdcard', |
michael@0 | 318 | shouldPass: true, |
michael@0 | 319 | fileExtension: '.txt', |
michael@0 | 320 | |
michael@0 | 321 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 322 | permissions: ["device-storage:sdcard"], |
michael@0 | 323 | |
michael@0 | 324 | test: TestGet |
michael@0 | 325 | }, |
michael@0 | 326 | |
michael@0 | 327 | // Directory#createDirectory |
michael@0 | 328 | |
michael@0 | 329 | // Web applications with no permissions |
michael@0 | 330 | { |
michael@0 | 331 | type: 'pictures', |
michael@0 | 332 | shouldPass: false, |
michael@0 | 333 | test: TestCreateDirectory |
michael@0 | 334 | }, |
michael@0 | 335 | { |
michael@0 | 336 | type: 'videos', |
michael@0 | 337 | shouldPass: false, |
michael@0 | 338 | test: TestCreateDirectory |
michael@0 | 339 | }, |
michael@0 | 340 | { |
michael@0 | 341 | type: 'music', |
michael@0 | 342 | shouldPass: false, |
michael@0 | 343 | test: TestCreateDirectory |
michael@0 | 344 | }, |
michael@0 | 345 | { |
michael@0 | 346 | type: 'sdcard', |
michael@0 | 347 | shouldPass: false, |
michael@0 | 348 | test: TestCreateDirectory |
michael@0 | 349 | }, |
michael@0 | 350 | |
michael@0 | 351 | // Web applications with permission granted |
michael@0 | 352 | { |
michael@0 | 353 | type: 'pictures', |
michael@0 | 354 | shouldPass: true, |
michael@0 | 355 | |
michael@0 | 356 | permissions: ["device-storage:pictures"], |
michael@0 | 357 | |
michael@0 | 358 | test: TestCreateDirectory |
michael@0 | 359 | }, |
michael@0 | 360 | { |
michael@0 | 361 | type: 'videos', |
michael@0 | 362 | shouldPass: true, |
michael@0 | 363 | |
michael@0 | 364 | permissions: ["device-storage:videos"], |
michael@0 | 365 | |
michael@0 | 366 | test: TestCreateDirectory |
michael@0 | 367 | }, |
michael@0 | 368 | { |
michael@0 | 369 | type: 'music', |
michael@0 | 370 | shouldPass: true, |
michael@0 | 371 | |
michael@0 | 372 | permissions: ["device-storage:music"], |
michael@0 | 373 | |
michael@0 | 374 | test: TestCreateDirectory |
michael@0 | 375 | }, |
michael@0 | 376 | { |
michael@0 | 377 | type: 'sdcard', |
michael@0 | 378 | shouldPass: true, |
michael@0 | 379 | |
michael@0 | 380 | permissions: ["device-storage:sdcard"], |
michael@0 | 381 | |
michael@0 | 382 | test: TestCreateDirectory |
michael@0 | 383 | }, |
michael@0 | 384 | |
michael@0 | 385 | // Certified application with permision granted |
michael@0 | 386 | { |
michael@0 | 387 | type: 'pictures', |
michael@0 | 388 | shouldPass: true, |
michael@0 | 389 | |
michael@0 | 390 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 391 | permissions: ["device-storage:pictures"], |
michael@0 | 392 | |
michael@0 | 393 | test: TestCreateDirectory |
michael@0 | 394 | }, |
michael@0 | 395 | { |
michael@0 | 396 | type: 'videos', |
michael@0 | 397 | shouldPass: true, |
michael@0 | 398 | |
michael@0 | 399 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 400 | permissions: ["device-storage:videos"], |
michael@0 | 401 | |
michael@0 | 402 | test: TestCreateDirectory |
michael@0 | 403 | }, |
michael@0 | 404 | { |
michael@0 | 405 | type: 'music', |
michael@0 | 406 | shouldPass: true, |
michael@0 | 407 | |
michael@0 | 408 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 409 | permissions: ["device-storage:music"], |
michael@0 | 410 | |
michael@0 | 411 | test: TestCreateDirectory |
michael@0 | 412 | }, |
michael@0 | 413 | { |
michael@0 | 414 | type: 'sdcard', |
michael@0 | 415 | shouldPass: true, |
michael@0 | 416 | |
michael@0 | 417 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 418 | permissions: ["device-storage:sdcard"], |
michael@0 | 419 | |
michael@0 | 420 | test: TestCreateDirectory |
michael@0 | 421 | }, |
michael@0 | 422 | |
michael@0 | 423 | // Directory#createFile |
michael@0 | 424 | |
michael@0 | 425 | // Web applications with no permissions |
michael@0 | 426 | { |
michael@0 | 427 | type: 'pictures', |
michael@0 | 428 | mimeType: 'image/png', |
michael@0 | 429 | shouldPass: false, |
michael@0 | 430 | fileExtension: '.png', |
michael@0 | 431 | test: TestCreateFile |
michael@0 | 432 | }, |
michael@0 | 433 | { |
michael@0 | 434 | type: 'videos', |
michael@0 | 435 | mimeType: 'video/ogv', |
michael@0 | 436 | shouldPass: false, |
michael@0 | 437 | fileExtension: '.ogv', |
michael@0 | 438 | test: TestCreateFile |
michael@0 | 439 | }, |
michael@0 | 440 | { |
michael@0 | 441 | type: 'videos', |
michael@0 | 442 | mimeType: 'video/ogg', |
michael@0 | 443 | shouldPass: false, |
michael@0 | 444 | fileExtension: '.ogg', |
michael@0 | 445 | test: TestCreateFile |
michael@0 | 446 | }, |
michael@0 | 447 | { |
michael@0 | 448 | type: 'music', |
michael@0 | 449 | mimeType: 'audio/ogg', |
michael@0 | 450 | shouldPass: false, |
michael@0 | 451 | fileExtension: '.ogg', |
michael@0 | 452 | test: TestCreateFile |
michael@0 | 453 | }, |
michael@0 | 454 | { |
michael@0 | 455 | type: 'music', |
michael@0 | 456 | mimeType: 'audio/ogg', |
michael@0 | 457 | shouldPass: false, |
michael@0 | 458 | fileExtension: '.txt', |
michael@0 | 459 | test: TestCreateFile |
michael@0 | 460 | }, |
michael@0 | 461 | { |
michael@0 | 462 | type: 'sdcard', |
michael@0 | 463 | mimeType: 'text/plain', |
michael@0 | 464 | shouldPass: false, |
michael@0 | 465 | fileExtension: '.txt', |
michael@0 | 466 | test: TestCreateFile |
michael@0 | 467 | }, |
michael@0 | 468 | |
michael@0 | 469 | // Web applications with permission granted |
michael@0 | 470 | { |
michael@0 | 471 | type: 'pictures', |
michael@0 | 472 | mimeType: 'image/png', |
michael@0 | 473 | shouldPass: true, |
michael@0 | 474 | fileExtension: '.png', |
michael@0 | 475 | |
michael@0 | 476 | permissions: ["device-storage:pictures"], |
michael@0 | 477 | |
michael@0 | 478 | test: TestCreateFile |
michael@0 | 479 | }, |
michael@0 | 480 | { |
michael@0 | 481 | type: 'videos', |
michael@0 | 482 | mimeType: 'video/ogv', |
michael@0 | 483 | shouldPass: true, |
michael@0 | 484 | fileExtension: '.ogv', |
michael@0 | 485 | |
michael@0 | 486 | permissions: ["device-storage:videos"], |
michael@0 | 487 | |
michael@0 | 488 | test: TestCreateFile |
michael@0 | 489 | }, |
michael@0 | 490 | { |
michael@0 | 491 | type: 'videos', |
michael@0 | 492 | mimeType: 'video/ogg', |
michael@0 | 493 | shouldPass: true, |
michael@0 | 494 | fileExtension: '.ogg', |
michael@0 | 495 | |
michael@0 | 496 | permissions: ["device-storage:videos"], |
michael@0 | 497 | |
michael@0 | 498 | test: TestCreateFile |
michael@0 | 499 | }, |
michael@0 | 500 | { |
michael@0 | 501 | type: 'music', |
michael@0 | 502 | mimeType: 'audio/ogg', |
michael@0 | 503 | shouldPass: true, |
michael@0 | 504 | fileExtension: '.ogg', |
michael@0 | 505 | |
michael@0 | 506 | permissions: ["device-storage:music"], |
michael@0 | 507 | |
michael@0 | 508 | test: TestCreateFile |
michael@0 | 509 | }, |
michael@0 | 510 | { |
michael@0 | 511 | type: 'music', |
michael@0 | 512 | mimeType: 'audio/ogg', |
michael@0 | 513 | shouldPass: false, |
michael@0 | 514 | fileExtension: '.txt', |
michael@0 | 515 | |
michael@0 | 516 | permissions: ["device-storage:music"], |
michael@0 | 517 | |
michael@0 | 518 | test: TestCreateFile |
michael@0 | 519 | }, |
michael@0 | 520 | { |
michael@0 | 521 | type: 'sdcard', |
michael@0 | 522 | mimeType: 'text/plain', |
michael@0 | 523 | shouldPass: true, |
michael@0 | 524 | fileExtension: '.txt', |
michael@0 | 525 | |
michael@0 | 526 | permissions: ["device-storage:sdcard"], |
michael@0 | 527 | |
michael@0 | 528 | test: TestCreateFile |
michael@0 | 529 | }, |
michael@0 | 530 | |
michael@0 | 531 | // Certified application with permision granted |
michael@0 | 532 | { |
michael@0 | 533 | type: 'pictures', |
michael@0 | 534 | mimeType: 'image/png', |
michael@0 | 535 | shouldPass: true, |
michael@0 | 536 | fileExtension: '.png', |
michael@0 | 537 | |
michael@0 | 538 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 539 | permissions: ["device-storage:pictures"], |
michael@0 | 540 | |
michael@0 | 541 | test: TestCreateFile |
michael@0 | 542 | }, |
michael@0 | 543 | { |
michael@0 | 544 | type: 'videos', |
michael@0 | 545 | mimeType: 'video/ogv', |
michael@0 | 546 | shouldPass: true, |
michael@0 | 547 | fileExtension: '.ogv', |
michael@0 | 548 | |
michael@0 | 549 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 550 | permissions: ["device-storage:videos"], |
michael@0 | 551 | |
michael@0 | 552 | test: TestCreateFile |
michael@0 | 553 | }, |
michael@0 | 554 | { |
michael@0 | 555 | type: 'videos', |
michael@0 | 556 | mimeType: 'video/ogg', |
michael@0 | 557 | shouldPass: true, |
michael@0 | 558 | fileExtension: '.ogg', |
michael@0 | 559 | |
michael@0 | 560 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 561 | permissions: ["device-storage:videos"], |
michael@0 | 562 | |
michael@0 | 563 | test: TestCreateFile |
michael@0 | 564 | }, |
michael@0 | 565 | { |
michael@0 | 566 | type: 'music', |
michael@0 | 567 | mimeType: 'audio/ogg', |
michael@0 | 568 | shouldPass: true, |
michael@0 | 569 | fileExtension: '.ogg', |
michael@0 | 570 | |
michael@0 | 571 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 572 | permissions: ["device-storage:music"], |
michael@0 | 573 | |
michael@0 | 574 | test: TestCreateFile |
michael@0 | 575 | }, |
michael@0 | 576 | { |
michael@0 | 577 | type: 'music', |
michael@0 | 578 | mimeType: 'audio/ogg', |
michael@0 | 579 | shouldPass: false, |
michael@0 | 580 | fileExtension: '.txt', |
michael@0 | 581 | |
michael@0 | 582 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 583 | permissions: ["device-storage:music"], |
michael@0 | 584 | |
michael@0 | 585 | test: TestCreateFile |
michael@0 | 586 | }, |
michael@0 | 587 | { |
michael@0 | 588 | type: 'sdcard', |
michael@0 | 589 | mimeType: 'text/plain', |
michael@0 | 590 | shouldPass: true, |
michael@0 | 591 | fileExtension: '.txt', |
michael@0 | 592 | |
michael@0 | 593 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 594 | permissions: ["device-storage:sdcard"], |
michael@0 | 595 | |
michael@0 | 596 | test: TestCreateFile |
michael@0 | 597 | }, |
michael@0 | 598 | |
michael@0 | 599 | // Directory#remove |
michael@0 | 600 | |
michael@0 | 601 | // Web applications with no permissions |
michael@0 | 602 | { |
michael@0 | 603 | type: 'pictures', |
michael@0 | 604 | shouldPass: false, |
michael@0 | 605 | fileExtension: '.png', |
michael@0 | 606 | test: TestRemove |
michael@0 | 607 | }, |
michael@0 | 608 | { |
michael@0 | 609 | type: 'videos', |
michael@0 | 610 | shouldPass: false, |
michael@0 | 611 | fileExtension: '.ogv', |
michael@0 | 612 | test: TestRemove |
michael@0 | 613 | }, |
michael@0 | 614 | { |
michael@0 | 615 | type: 'videos', |
michael@0 | 616 | shouldPass: false, |
michael@0 | 617 | fileExtension: '.ogg', |
michael@0 | 618 | test: TestRemove |
michael@0 | 619 | }, |
michael@0 | 620 | { |
michael@0 | 621 | type: 'music', |
michael@0 | 622 | shouldPass: false, |
michael@0 | 623 | fileExtension: '.ogg', |
michael@0 | 624 | test: TestRemove |
michael@0 | 625 | }, |
michael@0 | 626 | { |
michael@0 | 627 | type: 'music', |
michael@0 | 628 | shouldPass: false, |
michael@0 | 629 | fileExtension: '.txt', |
michael@0 | 630 | test: TestRemove |
michael@0 | 631 | }, |
michael@0 | 632 | { |
michael@0 | 633 | type: 'sdcard', |
michael@0 | 634 | shouldPass: false, |
michael@0 | 635 | fileExtension: '.txt', |
michael@0 | 636 | test: TestRemove |
michael@0 | 637 | }, |
michael@0 | 638 | |
michael@0 | 639 | // Web applications with permission granted |
michael@0 | 640 | { |
michael@0 | 641 | type: 'pictures', |
michael@0 | 642 | shouldPass: true, |
michael@0 | 643 | fileExtension: '.png', |
michael@0 | 644 | |
michael@0 | 645 | permissions: ["device-storage:pictures"], |
michael@0 | 646 | |
michael@0 | 647 | test: TestRemove |
michael@0 | 648 | }, |
michael@0 | 649 | { |
michael@0 | 650 | type: 'videos', |
michael@0 | 651 | shouldPass: true, |
michael@0 | 652 | fileExtension: '.ogv', |
michael@0 | 653 | |
michael@0 | 654 | permissions: ["device-storage:videos"], |
michael@0 | 655 | |
michael@0 | 656 | test: TestRemove |
michael@0 | 657 | }, |
michael@0 | 658 | { |
michael@0 | 659 | type: 'videos', |
michael@0 | 660 | shouldPass: true, |
michael@0 | 661 | fileExtension: '.ogg', |
michael@0 | 662 | |
michael@0 | 663 | permissions: ["device-storage:videos"], |
michael@0 | 664 | |
michael@0 | 665 | test: TestRemove |
michael@0 | 666 | }, |
michael@0 | 667 | { |
michael@0 | 668 | type: 'music', |
michael@0 | 669 | shouldPass: true, |
michael@0 | 670 | fileExtension: '.ogg', |
michael@0 | 671 | |
michael@0 | 672 | permissions: ["device-storage:music"], |
michael@0 | 673 | |
michael@0 | 674 | test: TestRemove |
michael@0 | 675 | }, |
michael@0 | 676 | { |
michael@0 | 677 | type: 'music', |
michael@0 | 678 | shouldPass: false, |
michael@0 | 679 | fileExtension: '.txt', |
michael@0 | 680 | |
michael@0 | 681 | permissions: ["device-storage:music"], |
michael@0 | 682 | |
michael@0 | 683 | test: TestRemove |
michael@0 | 684 | }, |
michael@0 | 685 | { |
michael@0 | 686 | type: 'sdcard', |
michael@0 | 687 | shouldPass: true, |
michael@0 | 688 | fileExtension: '.txt', |
michael@0 | 689 | |
michael@0 | 690 | permissions: ["device-storage:sdcard"], |
michael@0 | 691 | |
michael@0 | 692 | test: TestRemove |
michael@0 | 693 | }, |
michael@0 | 694 | |
michael@0 | 695 | // Certified application with permision granted |
michael@0 | 696 | { |
michael@0 | 697 | type: 'pictures', |
michael@0 | 698 | shouldPass: true, |
michael@0 | 699 | fileExtension: '.png', |
michael@0 | 700 | |
michael@0 | 701 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 702 | permissions: ["device-storage:pictures"], |
michael@0 | 703 | |
michael@0 | 704 | test: TestRemove |
michael@0 | 705 | }, |
michael@0 | 706 | { |
michael@0 | 707 | type: 'videos', |
michael@0 | 708 | shouldPass: true, |
michael@0 | 709 | fileExtension: '.ogv', |
michael@0 | 710 | |
michael@0 | 711 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 712 | permissions: ["device-storage:videos"], |
michael@0 | 713 | |
michael@0 | 714 | test: TestRemove |
michael@0 | 715 | }, |
michael@0 | 716 | { |
michael@0 | 717 | type: 'videos', |
michael@0 | 718 | shouldPass: true, |
michael@0 | 719 | fileExtension: '.ogg', |
michael@0 | 720 | |
michael@0 | 721 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 722 | permissions: ["device-storage:videos"], |
michael@0 | 723 | |
michael@0 | 724 | test: TestRemove |
michael@0 | 725 | }, |
michael@0 | 726 | { |
michael@0 | 727 | type: 'music', |
michael@0 | 728 | shouldPass: true, |
michael@0 | 729 | fileExtension: '.ogg', |
michael@0 | 730 | |
michael@0 | 731 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 732 | permissions: ["device-storage:music"], |
michael@0 | 733 | |
michael@0 | 734 | test: TestRemove |
michael@0 | 735 | }, |
michael@0 | 736 | { |
michael@0 | 737 | type: 'music', |
michael@0 | 738 | shouldPass: false, |
michael@0 | 739 | fileExtension: '.txt', |
michael@0 | 740 | |
michael@0 | 741 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 742 | permissions: ["device-storage:music"], |
michael@0 | 743 | |
michael@0 | 744 | test: TestRemove |
michael@0 | 745 | }, |
michael@0 | 746 | { |
michael@0 | 747 | type: 'sdcard', |
michael@0 | 748 | shouldPass: true, |
michael@0 | 749 | fileExtension: '.txt', |
michael@0 | 750 | |
michael@0 | 751 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 752 | permissions: ["device-storage:sdcard"], |
michael@0 | 753 | |
michael@0 | 754 | test: TestRemove |
michael@0 | 755 | } |
michael@0 | 756 | |
michael@0 | 757 | ]; |
michael@0 | 758 | |
michael@0 | 759 | function setupTest(iframe,data) { |
michael@0 | 760 | if (data.permissions) { |
michael@0 | 761 | for (let j in data.permissions) { |
michael@0 | 762 | SpecialPowers.addPermission(data.permissions[j], true, iframe.contentDocument); |
michael@0 | 763 | } |
michael@0 | 764 | } |
michael@0 | 765 | } |
michael@0 | 766 | |
michael@0 | 767 | function testComplete(iframe, data) { |
michael@0 | 768 | if (data.permissions) { |
michael@0 | 769 | for (let j in data.permissions) { |
michael@0 | 770 | SpecialPowers.removePermission(data.permissions[j], iframe.contentDocument); |
michael@0 | 771 | } |
michael@0 | 772 | } |
michael@0 | 773 | |
michael@0 | 774 | document.getElementById('content').removeChild(iframe); |
michael@0 | 775 | |
michael@0 | 776 | if (gData.length == 0) { |
michael@0 | 777 | SimpleTest.finish(); |
michael@0 | 778 | } else { |
michael@0 | 779 | gTestRunner.next(); |
michael@0 | 780 | } |
michael@0 | 781 | } |
michael@0 | 782 | |
michael@0 | 783 | function runTest() { |
michael@0 | 784 | while (gData.length > 0) { |
michael@0 | 785 | let iframe = document.createElement('iframe'); |
michael@0 | 786 | let data = gData.shift(); |
michael@0 | 787 | |
michael@0 | 788 | iframe.setAttribute('mozbrowser', ''); |
michael@0 | 789 | if (data.app) { |
michael@0 | 790 | iframe.setAttribute('mozapp', data.app); |
michael@0 | 791 | } |
michael@0 | 792 | |
michael@0 | 793 | iframe.src = gTestUri; |
michael@0 | 794 | |
michael@0 | 795 | iframe.addEventListener('load', function(e) { |
michael@0 | 796 | setupTest(iframe, data) |
michael@0 | 797 | data.test(iframe, data); |
michael@0 | 798 | }); |
michael@0 | 799 | |
michael@0 | 800 | document.getElementById('content').appendChild(iframe); |
michael@0 | 801 | yield undefined; |
michael@0 | 802 | } |
michael@0 | 803 | } |
michael@0 | 804 | |
michael@0 | 805 | function createTestFile(extension) { |
michael@0 | 806 | try { |
michael@0 | 807 | const Cc = SpecialPowers.Cc; |
michael@0 | 808 | const Ci = SpecialPowers.Ci; |
michael@0 | 809 | let directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); |
michael@0 | 810 | let f = directoryService.get("TmpD", Ci.nsIFile); |
michael@0 | 811 | f.appendRelativePath("device-storage-testing"); |
michael@0 | 812 | f.remove(true); |
michael@0 | 813 | f.appendRelativePath("testfile" + extension); |
michael@0 | 814 | f.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 815 | } catch(e) {} |
michael@0 | 816 | } |
michael@0 | 817 | |
michael@0 | 818 | let gTestRunner = runTest(); |
michael@0 | 819 | SpecialPowers.addPermission("browser", true, gTestUri); |
michael@0 | 820 | |
michael@0 | 821 | // We are more permissive with CSP in our testing environment.... |
michael@0 | 822 | const DEFAULT_CSP_PRIV = "default-src *; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'"; |
michael@0 | 823 | const DEFAULT_CSP_CERT = "default-src *; script-src 'self'; style-src 'self'; object-src 'none'"; |
michael@0 | 824 | |
michael@0 | 825 | SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true], |
michael@0 | 826 | ["device.storage.enabled", true], |
michael@0 | 827 | ["device.storage.testing", true], |
michael@0 | 828 | ["device.storage.prompt.testing", false], |
michael@0 | 829 | ["security.apps.privileged.CSP.default", DEFAULT_CSP_PRIV], |
michael@0 | 830 | ["security.apps.certified.CSP.default", DEFAULT_CSP_CERT]]}, |
michael@0 | 831 | function() { gTestRunner.next(); }); |
michael@0 | 832 | |
michael@0 | 833 | </script> |
michael@0 | 834 | </pre> |
michael@0 | 835 | </body> |
michael@0 | 836 | </html> |