Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=805322 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Permission test 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=805322">Mozilla Bug 805322</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 | var set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; |
michael@0 | 26 | var result = ""; |
michael@0 | 27 | for (var i=0; i<l; i++) { |
michael@0 | 28 | var 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 | var MockPermissionPrompt = SpecialPowers.MockPermissionPrompt; |
michael@0 | 35 | MockPermissionPrompt.init(); |
michael@0 | 36 | |
michael@0 | 37 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 38 | |
michael@0 | 39 | function TestAdd(iframe, data) { |
michael@0 | 40 | |
michael@0 | 41 | var storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 42 | isnot(storage, null, "Should be able to get storage object for " + data.type); |
michael@0 | 43 | |
michael@0 | 44 | var blob = new Blob(["Kyle Huey is not a helicopter."], {type: data.mimeType}); |
michael@0 | 45 | |
michael@0 | 46 | request = storage.addNamed(blob, randomFilename(100) + "hi" + data.fileExtension); |
michael@0 | 47 | isnot(request, null, "Should be able to get request"); |
michael@0 | 48 | |
michael@0 | 49 | request.onsuccess = function() { |
michael@0 | 50 | is(data.shouldPass, true, "onsuccess was called for type " + data.type); |
michael@0 | 51 | testComplete(iframe, data); |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | request.onerror = function(e) { |
michael@0 | 55 | isnot(data.shouldPass, true, "onfailure was called for type " + data.type + " Error: " + e.target.error.name); |
michael@0 | 56 | is(e.target.error.name, "SecurityError", "onerror should fire a SecurityError"); |
michael@0 | 57 | testComplete(iframe, data); |
michael@0 | 58 | }; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function TestGet(iframe, data) { |
michael@0 | 62 | |
michael@0 | 63 | createTestFile(data.fileExtension); |
michael@0 | 64 | |
michael@0 | 65 | var storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 66 | isnot(storage, null, "Should be able to get storage object for " + data.type); |
michael@0 | 67 | |
michael@0 | 68 | request = storage.get("testfile" + data.fileExtension); |
michael@0 | 69 | isnot(request, null, "Should be able to get request"); |
michael@0 | 70 | |
michael@0 | 71 | request.onsuccess = function() { |
michael@0 | 72 | is(data.shouldPass, true, "onsuccess was called for type " + data.type); |
michael@0 | 73 | testComplete(iframe, data); |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | request.onerror = function(e) { |
michael@0 | 77 | isnot(data.shouldPass, true, "onfailure was called for type " + data.type + " Error: " + e.target.error.name); |
michael@0 | 78 | testComplete(iframe, data); |
michael@0 | 79 | }; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function TestDelete(iframe, data) { |
michael@0 | 83 | |
michael@0 | 84 | createTestFile(data.fileExtension); |
michael@0 | 85 | |
michael@0 | 86 | var storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 87 | isnot(storage, null, "Should be able to get storage object for " + data.type); |
michael@0 | 88 | |
michael@0 | 89 | request = storage.delete("testfile" + data.fileExtension); |
michael@0 | 90 | isnot(request, null, "Should be able to get request"); |
michael@0 | 91 | |
michael@0 | 92 | request.onsuccess = function() { |
michael@0 | 93 | is(data.shouldPass, true, "onsuccess was called for type " + data.type); |
michael@0 | 94 | testComplete(iframe, data); |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | request.onerror = function(e) { |
michael@0 | 98 | isnot(data.shouldPass, true, "onfailure was called for type " + data.type + " Error: " + e.target.error.name); |
michael@0 | 99 | is(e.target.error.name, "SecurityError", "onerror should fire a SecurityError"); |
michael@0 | 100 | testComplete(iframe, data); |
michael@0 | 101 | }; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function TestEnumerate(iframe, data) { |
michael@0 | 105 | |
michael@0 | 106 | createTestFile(data.fileExtension); |
michael@0 | 107 | |
michael@0 | 108 | var storage = iframe.contentDocument.defaultView.navigator.getDeviceStorage(data.type); |
michael@0 | 109 | isnot(storage, null, "Should be able to get storage object for " + data.type); |
michael@0 | 110 | |
michael@0 | 111 | request = storage.enumerate(); |
michael@0 | 112 | isnot(request, null, "Should be able to get request"); |
michael@0 | 113 | |
michael@0 | 114 | request.onsuccess = function(e) { |
michael@0 | 115 | is(data.shouldPass, true, "onsuccess was called for type " + data.type); |
michael@0 | 116 | |
michael@0 | 117 | if (e.target.result == null) { |
michael@0 | 118 | testComplete(iframe, data); |
michael@0 | 119 | return; |
michael@0 | 120 | } |
michael@0 | 121 | e.target.continue(); |
michael@0 | 122 | }; |
michael@0 | 123 | |
michael@0 | 124 | request.onerror = function(e) { |
michael@0 | 125 | isnot(data.shouldPass, true, "onfailure was called for type " + data.type + " Error: " + e.target.error.name); |
michael@0 | 126 | is(e.target.error.name, "SecurityError", "onerror should fire a SecurityError"); |
michael@0 | 127 | testComplete(iframe, data); |
michael@0 | 128 | }; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | var gTestUri = "https://example.com/tests/dom/devicestorage/test/test_app_permissions.html" |
michael@0 | 132 | |
michael@0 | 133 | var gData = [ |
michael@0 | 134 | |
michael@0 | 135 | // Get |
michael@0 | 136 | // Web applications with no permissions |
michael@0 | 137 | { |
michael@0 | 138 | type: 'pictures', |
michael@0 | 139 | shouldPass: false, |
michael@0 | 140 | fileExtension: '.png', |
michael@0 | 141 | test: TestGet |
michael@0 | 142 | }, |
michael@0 | 143 | { |
michael@0 | 144 | type: 'videos', |
michael@0 | 145 | shouldPass: false, |
michael@0 | 146 | fileExtension: '.ogv', |
michael@0 | 147 | test: TestGet |
michael@0 | 148 | }, |
michael@0 | 149 | { |
michael@0 | 150 | type: 'music', |
michael@0 | 151 | shouldPass: false, |
michael@0 | 152 | fileExtension: '.ogg', |
michael@0 | 153 | test: TestGet |
michael@0 | 154 | }, |
michael@0 | 155 | { |
michael@0 | 156 | type: 'sdcard', |
michael@0 | 157 | shouldPass: false, |
michael@0 | 158 | fileExtension: '.txt', |
michael@0 | 159 | test: TestGet |
michael@0 | 160 | }, |
michael@0 | 161 | |
michael@0 | 162 | // Web applications with permission granted |
michael@0 | 163 | { |
michael@0 | 164 | type: 'pictures', |
michael@0 | 165 | shouldPass: true, |
michael@0 | 166 | fileExtension: '.png', |
michael@0 | 167 | |
michael@0 | 168 | permissions: ["device-storage:pictures"], |
michael@0 | 169 | |
michael@0 | 170 | test: TestGet |
michael@0 | 171 | }, |
michael@0 | 172 | { |
michael@0 | 173 | type: 'videos', |
michael@0 | 174 | shouldPass: true, |
michael@0 | 175 | fileExtension: '.ogv', |
michael@0 | 176 | |
michael@0 | 177 | permissions: ["device-storage:videos"], |
michael@0 | 178 | |
michael@0 | 179 | test: TestGet |
michael@0 | 180 | }, |
michael@0 | 181 | { |
michael@0 | 182 | type: 'music', |
michael@0 | 183 | shouldPass: true, |
michael@0 | 184 | fileExtension: '.ogg', |
michael@0 | 185 | |
michael@0 | 186 | permissions: ["device-storage:music"], |
michael@0 | 187 | |
michael@0 | 188 | test: TestGet |
michael@0 | 189 | }, |
michael@0 | 190 | { |
michael@0 | 191 | type: 'sdcard', |
michael@0 | 192 | shouldPass: true, |
michael@0 | 193 | fileExtension: '.txt', |
michael@0 | 194 | |
michael@0 | 195 | permissions: ["device-storage:sdcard"], |
michael@0 | 196 | |
michael@0 | 197 | test: TestGet |
michael@0 | 198 | }, |
michael@0 | 199 | |
michael@0 | 200 | // Certified application with permision granted |
michael@0 | 201 | { |
michael@0 | 202 | type: 'pictures', |
michael@0 | 203 | shouldPass: true, |
michael@0 | 204 | fileExtension: '.png', |
michael@0 | 205 | |
michael@0 | 206 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 207 | permissions: ["device-storage:pictures"], |
michael@0 | 208 | |
michael@0 | 209 | test: TestGet |
michael@0 | 210 | }, |
michael@0 | 211 | { |
michael@0 | 212 | type: 'videos', |
michael@0 | 213 | shouldPass: true, |
michael@0 | 214 | fileExtension: '.ogv', |
michael@0 | 215 | |
michael@0 | 216 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 217 | permissions: ["device-storage:videos"], |
michael@0 | 218 | |
michael@0 | 219 | test: TestGet |
michael@0 | 220 | }, |
michael@0 | 221 | { |
michael@0 | 222 | type: 'music', |
michael@0 | 223 | shouldPass: true, |
michael@0 | 224 | fileExtension: '.ogg', |
michael@0 | 225 | |
michael@0 | 226 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 227 | permissions: ["device-storage:music"], |
michael@0 | 228 | |
michael@0 | 229 | test: TestGet |
michael@0 | 230 | }, |
michael@0 | 231 | { |
michael@0 | 232 | type: 'sdcard', |
michael@0 | 233 | shouldPass: true, |
michael@0 | 234 | fileExtension: '.txt', |
michael@0 | 235 | |
michael@0 | 236 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 237 | permissions: ["device-storage:sdcard"], |
michael@0 | 238 | |
michael@0 | 239 | test: TestGet |
michael@0 | 240 | }, |
michael@0 | 241 | |
michael@0 | 242 | |
michael@0 | 243 | // Add |
michael@0 | 244 | |
michael@0 | 245 | |
michael@0 | 246 | // Web applications with no permissions |
michael@0 | 247 | { |
michael@0 | 248 | type: 'pictures', |
michael@0 | 249 | mimeType: 'image/png', |
michael@0 | 250 | fileExtension: '.png', |
michael@0 | 251 | shouldPass: false, |
michael@0 | 252 | test: TestAdd |
michael@0 | 253 | }, |
michael@0 | 254 | { |
michael@0 | 255 | type: 'videos', |
michael@0 | 256 | mimeType: 'video/ogv', |
michael@0 | 257 | fileExtension: '.ogv', |
michael@0 | 258 | shouldPass: false, |
michael@0 | 259 | test: TestAdd |
michael@0 | 260 | }, |
michael@0 | 261 | { |
michael@0 | 262 | type: 'music', |
michael@0 | 263 | mimeType: 'audio/ogg', |
michael@0 | 264 | fileExtension: '.ogg', |
michael@0 | 265 | shouldPass: false, |
michael@0 | 266 | test: TestAdd |
michael@0 | 267 | }, |
michael@0 | 268 | { |
michael@0 | 269 | type: 'sdcard', |
michael@0 | 270 | mimeType: 'text/plain', |
michael@0 | 271 | fileExtension: '.txt', |
michael@0 | 272 | shouldPass: false, |
michael@0 | 273 | test: TestAdd |
michael@0 | 274 | }, |
michael@0 | 275 | |
michael@0 | 276 | // Web applications with permission granted |
michael@0 | 277 | { |
michael@0 | 278 | type: 'pictures', |
michael@0 | 279 | mimeType: 'image/png', |
michael@0 | 280 | fileExtension: '.png', |
michael@0 | 281 | shouldPass: true, |
michael@0 | 282 | |
michael@0 | 283 | permissions: ["device-storage:pictures"], |
michael@0 | 284 | |
michael@0 | 285 | test: TestAdd |
michael@0 | 286 | }, |
michael@0 | 287 | { |
michael@0 | 288 | type: 'videos', |
michael@0 | 289 | mimeType: 'video/ogv', |
michael@0 | 290 | fileExtension: '.ogv', |
michael@0 | 291 | shouldPass: true, |
michael@0 | 292 | |
michael@0 | 293 | permissions: ["device-storage:videos"], |
michael@0 | 294 | |
michael@0 | 295 | test: TestAdd |
michael@0 | 296 | }, |
michael@0 | 297 | { |
michael@0 | 298 | type: 'music', |
michael@0 | 299 | mimeType: 'audio/ogg', |
michael@0 | 300 | fileExtension: '.ogg', |
michael@0 | 301 | shouldPass: true, |
michael@0 | 302 | |
michael@0 | 303 | permissions: ["device-storage:music"], |
michael@0 | 304 | |
michael@0 | 305 | test: TestAdd |
michael@0 | 306 | }, |
michael@0 | 307 | { |
michael@0 | 308 | type: 'sdcard', |
michael@0 | 309 | mimeType: 'text/plain', |
michael@0 | 310 | fileExtension: '.txt', |
michael@0 | 311 | shouldPass: true, |
michael@0 | 312 | |
michael@0 | 313 | permissions: ["device-storage:sdcard"], |
michael@0 | 314 | |
michael@0 | 315 | test: TestAdd |
michael@0 | 316 | }, |
michael@0 | 317 | |
michael@0 | 318 | // Certified application with permision granted |
michael@0 | 319 | { |
michael@0 | 320 | type: 'pictures', |
michael@0 | 321 | mimeType: 'image/png', |
michael@0 | 322 | fileExtension: '.png', |
michael@0 | 323 | shouldPass: true, |
michael@0 | 324 | |
michael@0 | 325 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 326 | permissions: ["device-storage:pictures"], |
michael@0 | 327 | |
michael@0 | 328 | test: TestAdd |
michael@0 | 329 | }, |
michael@0 | 330 | { |
michael@0 | 331 | type: 'videos', |
michael@0 | 332 | mimeType: 'video/ogv', |
michael@0 | 333 | fileExtension: '.ogv', |
michael@0 | 334 | shouldPass: true, |
michael@0 | 335 | |
michael@0 | 336 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 337 | permissions: ["device-storage:videos"], |
michael@0 | 338 | |
michael@0 | 339 | test: TestAdd |
michael@0 | 340 | }, |
michael@0 | 341 | { |
michael@0 | 342 | type: 'music', |
michael@0 | 343 | mimeType: 'audio/ogg', |
michael@0 | 344 | fileExtension: '.ogg', |
michael@0 | 345 | shouldPass: true, |
michael@0 | 346 | |
michael@0 | 347 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 348 | permissions: ["device-storage:music"], |
michael@0 | 349 | |
michael@0 | 350 | test: TestAdd |
michael@0 | 351 | }, |
michael@0 | 352 | { |
michael@0 | 353 | type: 'sdcard', |
michael@0 | 354 | mimeType: 'text/plain', |
michael@0 | 355 | fileExtension: '.txt', |
michael@0 | 356 | shouldPass: true, |
michael@0 | 357 | |
michael@0 | 358 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 359 | permissions: ["device-storage:sdcard"], |
michael@0 | 360 | |
michael@0 | 361 | test: TestAdd |
michael@0 | 362 | }, |
michael@0 | 363 | |
michael@0 | 364 | |
michael@0 | 365 | // Delete |
michael@0 | 366 | |
michael@0 | 367 | // Web applications with no permissions |
michael@0 | 368 | { |
michael@0 | 369 | type: 'pictures', |
michael@0 | 370 | shouldPass: false, |
michael@0 | 371 | fileExtension: '.png', |
michael@0 | 372 | test: TestDelete |
michael@0 | 373 | }, |
michael@0 | 374 | { |
michael@0 | 375 | type: 'videos', |
michael@0 | 376 | shouldPass: false, |
michael@0 | 377 | fileExtension: '.ogv', |
michael@0 | 378 | test: TestDelete |
michael@0 | 379 | }, |
michael@0 | 380 | { |
michael@0 | 381 | type: 'music', |
michael@0 | 382 | shouldPass: false, |
michael@0 | 383 | fileExtension: '.ogg', |
michael@0 | 384 | test: TestDelete |
michael@0 | 385 | }, |
michael@0 | 386 | { |
michael@0 | 387 | type: 'sdcard', |
michael@0 | 388 | shouldPass: false, |
michael@0 | 389 | fileExtension: '.txt', |
michael@0 | 390 | test: TestDelete |
michael@0 | 391 | }, |
michael@0 | 392 | |
michael@0 | 393 | // Web applications with permission granted |
michael@0 | 394 | { |
michael@0 | 395 | type: 'pictures', |
michael@0 | 396 | shouldPass: true, |
michael@0 | 397 | fileExtension: '.png', |
michael@0 | 398 | |
michael@0 | 399 | permissions: ["device-storage:pictures"], |
michael@0 | 400 | |
michael@0 | 401 | test: TestDelete |
michael@0 | 402 | }, |
michael@0 | 403 | { |
michael@0 | 404 | type: 'videos', |
michael@0 | 405 | shouldPass: true, |
michael@0 | 406 | fileExtension: '.ogv', |
michael@0 | 407 | |
michael@0 | 408 | permissions: ["device-storage:videos"], |
michael@0 | 409 | |
michael@0 | 410 | test: TestDelete |
michael@0 | 411 | }, |
michael@0 | 412 | { |
michael@0 | 413 | type: 'music', |
michael@0 | 414 | shouldPass: true, |
michael@0 | 415 | fileExtension: '.ogg', |
michael@0 | 416 | |
michael@0 | 417 | permissions: ["device-storage:music"], |
michael@0 | 418 | |
michael@0 | 419 | test: TestDelete |
michael@0 | 420 | }, |
michael@0 | 421 | { |
michael@0 | 422 | type: 'sdcard', |
michael@0 | 423 | shouldPass: true, |
michael@0 | 424 | fileExtension: '.txt', |
michael@0 | 425 | |
michael@0 | 426 | permissions: ["device-storage:sdcard"], |
michael@0 | 427 | |
michael@0 | 428 | test: TestDelete |
michael@0 | 429 | }, |
michael@0 | 430 | |
michael@0 | 431 | // Certified application with permision granted |
michael@0 | 432 | { |
michael@0 | 433 | type: 'pictures', |
michael@0 | 434 | shouldPass: true, |
michael@0 | 435 | fileExtension: '.png', |
michael@0 | 436 | |
michael@0 | 437 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 438 | permissions: ["device-storage:pictures"], |
michael@0 | 439 | |
michael@0 | 440 | test: TestDelete |
michael@0 | 441 | }, |
michael@0 | 442 | { |
michael@0 | 443 | type: 'videos', |
michael@0 | 444 | shouldPass: true, |
michael@0 | 445 | fileExtension: '.ogv', |
michael@0 | 446 | |
michael@0 | 447 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 448 | permissions: ["device-storage:videos"], |
michael@0 | 449 | |
michael@0 | 450 | test: TestDelete |
michael@0 | 451 | }, |
michael@0 | 452 | { |
michael@0 | 453 | type: 'music', |
michael@0 | 454 | shouldPass: true, |
michael@0 | 455 | fileExtension: '.ogg', |
michael@0 | 456 | |
michael@0 | 457 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 458 | permissions: ["device-storage:music"], |
michael@0 | 459 | |
michael@0 | 460 | test: TestDelete |
michael@0 | 461 | }, |
michael@0 | 462 | { |
michael@0 | 463 | type: 'sdcard', |
michael@0 | 464 | shouldPass: true, |
michael@0 | 465 | fileExtension: '.txt', |
michael@0 | 466 | |
michael@0 | 467 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 468 | permissions: ["device-storage:sdcard"], |
michael@0 | 469 | |
michael@0 | 470 | test: TestDelete |
michael@0 | 471 | }, |
michael@0 | 472 | |
michael@0 | 473 | // Enumeration |
michael@0 | 474 | |
michael@0 | 475 | // Web applications with no permissions |
michael@0 | 476 | { |
michael@0 | 477 | type: 'pictures', |
michael@0 | 478 | shouldPass: false, |
michael@0 | 479 | fileExtension: '.png', |
michael@0 | 480 | test: TestEnumerate |
michael@0 | 481 | }, |
michael@0 | 482 | { |
michael@0 | 483 | type: 'videos', |
michael@0 | 484 | shouldPass: false, |
michael@0 | 485 | fileExtension: '.ogv', |
michael@0 | 486 | test: TestEnumerate |
michael@0 | 487 | }, |
michael@0 | 488 | { |
michael@0 | 489 | type: 'music', |
michael@0 | 490 | shouldPass: false, |
michael@0 | 491 | fileExtension: '.ogg', |
michael@0 | 492 | test: TestEnumerate |
michael@0 | 493 | }, |
michael@0 | 494 | { |
michael@0 | 495 | type: 'sdcard', |
michael@0 | 496 | shouldPass: false, |
michael@0 | 497 | fileExtension: '.txt', |
michael@0 | 498 | test: TestEnumerate |
michael@0 | 499 | }, |
michael@0 | 500 | |
michael@0 | 501 | // Web applications with permission granted |
michael@0 | 502 | { |
michael@0 | 503 | type: 'pictures', |
michael@0 | 504 | shouldPass: true, |
michael@0 | 505 | fileExtension: '.png', |
michael@0 | 506 | |
michael@0 | 507 | permissions: ["device-storage:pictures"], |
michael@0 | 508 | |
michael@0 | 509 | test: TestEnumerate |
michael@0 | 510 | }, |
michael@0 | 511 | { |
michael@0 | 512 | type: 'videos', |
michael@0 | 513 | shouldPass: true, |
michael@0 | 514 | fileExtension: '.ogv', |
michael@0 | 515 | |
michael@0 | 516 | permissions: ["device-storage:videos"], |
michael@0 | 517 | |
michael@0 | 518 | test: TestEnumerate |
michael@0 | 519 | }, |
michael@0 | 520 | { |
michael@0 | 521 | type: 'music', |
michael@0 | 522 | shouldPass: true, |
michael@0 | 523 | fileExtension: '.ogg', |
michael@0 | 524 | |
michael@0 | 525 | permissions: ["device-storage:music"], |
michael@0 | 526 | |
michael@0 | 527 | test: TestEnumerate |
michael@0 | 528 | }, |
michael@0 | 529 | { |
michael@0 | 530 | type: 'sdcard', |
michael@0 | 531 | shouldPass: true, |
michael@0 | 532 | fileExtension: '.txt', |
michael@0 | 533 | |
michael@0 | 534 | permissions: ["device-storage:sdcard"], |
michael@0 | 535 | |
michael@0 | 536 | test: TestEnumerate |
michael@0 | 537 | }, |
michael@0 | 538 | |
michael@0 | 539 | // Certified application with permision granted |
michael@0 | 540 | { |
michael@0 | 541 | type: 'pictures', |
michael@0 | 542 | shouldPass: true, |
michael@0 | 543 | fileExtension: '.png', |
michael@0 | 544 | |
michael@0 | 545 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 546 | permissions: ["device-storage:pictures"], |
michael@0 | 547 | |
michael@0 | 548 | test: TestEnumerate |
michael@0 | 549 | }, |
michael@0 | 550 | { |
michael@0 | 551 | type: 'videos', |
michael@0 | 552 | shouldPass: true, |
michael@0 | 553 | fileExtension: '.ogv', |
michael@0 | 554 | |
michael@0 | 555 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 556 | permissions: ["device-storage:videos"], |
michael@0 | 557 | |
michael@0 | 558 | test: TestEnumerate |
michael@0 | 559 | }, |
michael@0 | 560 | { |
michael@0 | 561 | type: 'music', |
michael@0 | 562 | shouldPass: true, |
michael@0 | 563 | fileExtension: '.ogg', |
michael@0 | 564 | |
michael@0 | 565 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 566 | permissions: ["device-storage:music"], |
michael@0 | 567 | |
michael@0 | 568 | test: TestEnumerate |
michael@0 | 569 | }, |
michael@0 | 570 | { |
michael@0 | 571 | type: 'sdcard', |
michael@0 | 572 | shouldPass: true, |
michael@0 | 573 | fileExtension: '.txt', |
michael@0 | 574 | |
michael@0 | 575 | app: "https://example.com/manifest_cert.webapp", |
michael@0 | 576 | permissions: ["device-storage:sdcard"], |
michael@0 | 577 | |
michael@0 | 578 | test: TestEnumerate |
michael@0 | 579 | }, |
michael@0 | 580 | |
michael@0 | 581 | ]; |
michael@0 | 582 | |
michael@0 | 583 | function setupTest(iframe,data) { |
michael@0 | 584 | if (data.permissions) { |
michael@0 | 585 | for (var j in data.permissions) { |
michael@0 | 586 | SpecialPowers.addPermission(data.permissions[j], true, iframe.contentDocument); |
michael@0 | 587 | } |
michael@0 | 588 | } |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | function testComplete(iframe, data) { |
michael@0 | 592 | if (data.permissions) { |
michael@0 | 593 | for (var j in data.permissions) { |
michael@0 | 594 | SpecialPowers.removePermission(data.permissions[j], iframe.contentDocument); |
michael@0 | 595 | } |
michael@0 | 596 | } |
michael@0 | 597 | |
michael@0 | 598 | document.getElementById('content').removeChild(iframe); |
michael@0 | 599 | |
michael@0 | 600 | if (gData.length == 0) { |
michael@0 | 601 | SimpleTest.finish(); |
michael@0 | 602 | } else { |
michael@0 | 603 | gTestRunner.next(); |
michael@0 | 604 | } |
michael@0 | 605 | } |
michael@0 | 606 | |
michael@0 | 607 | function runTest() { |
michael@0 | 608 | while (gData.length > 0) { |
michael@0 | 609 | var iframe = document.createElement('iframe'); |
michael@0 | 610 | var data = gData.pop(); |
michael@0 | 611 | |
michael@0 | 612 | iframe.setAttribute('mozbrowser', ''); |
michael@0 | 613 | if (data.app) { |
michael@0 | 614 | iframe.setAttribute('mozapp', data.app); |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | iframe.src = gTestUri; |
michael@0 | 618 | |
michael@0 | 619 | iframe.addEventListener('load', function(e) { |
michael@0 | 620 | setupTest(iframe, data) |
michael@0 | 621 | data.test(iframe, data); |
michael@0 | 622 | }); |
michael@0 | 623 | |
michael@0 | 624 | document.getElementById('content').appendChild(iframe); |
michael@0 | 625 | yield undefined; |
michael@0 | 626 | } |
michael@0 | 627 | } |
michael@0 | 628 | |
michael@0 | 629 | function createTestFile(extension) { |
michael@0 | 630 | try { |
michael@0 | 631 | const Cc = SpecialPowers.Cc; |
michael@0 | 632 | const Ci = SpecialPowers.Ci; |
michael@0 | 633 | var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); |
michael@0 | 634 | var f = directoryService.get("TmpD", Ci.nsIFile); |
michael@0 | 635 | f.appendRelativePath("device-storage-testing"); |
michael@0 | 636 | f.remove(true); |
michael@0 | 637 | f.appendRelativePath("testfile" + extension); |
michael@0 | 638 | f.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 639 | } catch(e) {} |
michael@0 | 640 | } |
michael@0 | 641 | |
michael@0 | 642 | createTestFile('.txt'); |
michael@0 | 643 | var gTestRunner = runTest(); |
michael@0 | 644 | SpecialPowers.addPermission("browser", true, gTestUri); |
michael@0 | 645 | |
michael@0 | 646 | // We are more permissive with CSP in our testing environment.... |
michael@0 | 647 | const DEFAULT_CSP_PRIV = "default-src *; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'"; |
michael@0 | 648 | const DEFAULT_CSP_CERT = "default-src *; script-src 'self'; style-src 'self'; object-src 'none'"; |
michael@0 | 649 | |
michael@0 | 650 | SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true], |
michael@0 | 651 | ["device.storage.enabled", true], |
michael@0 | 652 | ["device.storage.testing", true], |
michael@0 | 653 | ["device.storage.prompt.testing", false], |
michael@0 | 654 | ["security.apps.privileged.CSP.default", DEFAULT_CSP_PRIV], |
michael@0 | 655 | ["security.apps.certified.CSP.default", DEFAULT_CSP_CERT]]}, |
michael@0 | 656 | function() { gTestRunner.next(); }); |
michael@0 | 657 | |
michael@0 | 658 | </script> |
michael@0 | 659 | </pre> |
michael@0 | 660 | </body> |
michael@0 | 661 | </html> |