test_mixed_principals.html (2898B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=489415 5 --> 6 <head> 7 <title>Test for Bug 489415</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 <script type="text/javascript" src="manifest.js"></script> 11 <style> 12 video { 13 width: 40%; 14 border: solid black 1px; 15 } 16 </style> 17 </head> 18 19 <body> 20 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=489415">Mozilla Bug 489415</a> 21 <p id="display"></p> 22 <pre id="test"> 23 <script type="text/javascript"> 24 SimpleTest.waitForExplicitFinish(); 25 26 var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({ set: p }); 27 var count = 0; 28 29 function canReadBack(video) { 30 var c = document.createElement("canvas"); 31 var ctx = c.getContext("2d"); 32 ctx.drawImage(video, 0, 0); 33 try { 34 var data_url = c.toDataURL(); 35 var empty_canvas = document.createElement("canvas"); 36 if (empty_canvas.toDataURL() === data_url) { 37 info("Readback check returned same data URL as empty canvas."); 38 } else { 39 info("Readback check returned different data URL than empty canvas."); 40 } 41 return true; 42 } catch (ex) { 43 return false; 44 } 45 } 46 47 function runTest(origin, shouldReadBackOnLoad) { 48 return new Promise(function (resolve) { 49 // Load will redirect mid-flight, which will be detected and should error, 50 // and we should no longer be able to readback. 51 var video = document.createElement("video"); 52 video.preload = "metadata"; 53 video.controls = true; 54 var url = "http://" + origin + "/tests/dom/media/test/midflight-redirect.sjs" 55 + "?resource=pixel_aspect_ratio.mp4&type=video/mp4"; 56 SimpleTest.info("Loading from " + url); 57 video.src = url; 58 document.body.appendChild(video); 59 60 once(video, "loadeddata", () => { 61 is(canReadBack(video), shouldReadBackOnLoad, "Should be able to readback"); 62 video.play(); 63 }); 64 65 once(video, "error", () => { 66 if(video.readyState == video.HAVE_METADATA) { 67 is(canReadBack(video), true, "Should be able to readback with readyState == HAVE_METADATA"); 68 } else { 69 is(canReadBack(video), false, "Should not be able to readback with readyState != HAVE_METADATA"); 70 } 71 72 removeNodeAndSource(video); 73 resolve(); 74 }); 75 76 once(video, "ended", () => { 77 ok(false, "Should not be able to playback to end, we should have errored!"); 78 removeNodeAndSource(video); 79 resolve(); 80 }); 81 82 }); 83 } 84 85 Promise.all([ 86 runTest("mochi.test:8888", true), 87 runTest("example.org", false), 88 ]).then(SimpleTest.finish); 89 90 </script> 91 </pre> 92 </body> 93 </html>