test_eme_unsetMediaKeys_then_capture.html (3084B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test Encrypted Media Extensions</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 <script type="text/javascript" src="manifest.js"></script> 8 <script type="text/javascript" src="https://example.com:443/tests/dom/media/test/eme.js"></script> 9 </head> 10 <body> 11 <pre id="test"> 12 <script class="testbody" type="text/javascript"> 13 /* import-globals-from eme.js */ 14 var manager = new MediaTestManager; 15 16 // Test that if we can capture a video frame while playing clear content after 17 // removing the MediaKeys object which was used for a previous encrypted content 18 // playback on the same video element 19 function startTest(test, token) 20 { 21 manager.started(token); 22 var sessions = []; 23 function onSessionCreated(session) { 24 sessions.push(session); 25 } 26 27 function closeSessions() { 28 let p = new EMEPromise; 29 Promise.all(sessions.map(s => s.close())) 30 .then(p.resolve, p.reject); 31 return p.promise; 32 } 33 34 let v = document.createElement("video"); 35 document.body.appendChild(v); 36 37 let finish = new EMEPromise; 38 39 function onVideoEnded() { 40 ok(true, TimeStamp(token) + " (ENCRYPTED) content playback ended."); 41 42 function playClearVideo() { 43 var p1 = once(v, 'loadeddata', () => { 44 ok(true, TimeStamp(token) + " Receiving event 'loadeddata' for (CLEAR) content."); 45 let canvasElem = document.createElement('canvas'); 46 document.body.appendChild(canvasElem); 47 let ctx2d = canvasElem.getContext('2d'); 48 49 var gotTypeError = false; 50 try { 51 ctx2d.drawImage(v, 0, 0); 52 } catch (ex) { 53 if (ex instanceof TypeError) { 54 gotTypeError = true; 55 } 56 } 57 ok(!gotTypeError, TimeStamp(token) + " Canvas2D context drawImage succeed.") 58 }); 59 v.src = 'bipbop_225w_175kbps.mp4'; 60 v.play(); 61 Promise.all([p1]).then(() => { 62 manager.finished(token); 63 }, () => { 64 ok(false, TimeStamp(token) + " Something wrong."); 65 manager.finished(token); 66 }); 67 } 68 69 closeSessions() 70 .then(() => { 71 v.setMediaKeys(null) 72 .then(() => { 73 ok(true, TimeStamp(token) + " Setting MediaKeys to null."); 74 playClearVideo(); 75 }, () => { 76 ok(false, TimeStamp(token) + " Setting MediaKeys to null."); 77 });; 78 }); 79 } 80 81 once(v, "ended", onVideoEnded); 82 83 // Create a MediaKeys object and set to HTMLMediaElement then start the playback. 84 Promise.all([ 85 LoadInitData(v, test, token), 86 CreateAndSetMediaKeys(v, test, token), 87 LoadTest(test, v, token)]) 88 .then(values => { 89 let initData = values[0]; 90 v.play(); 91 initData.map(ev => { 92 let session = v.mediaKeys.createSession(); 93 onSessionCreated(session); 94 MakeRequest(test, token, ev, session); 95 }); 96 }) 97 .then(() => { 98 return finish.promise; 99 }) 100 .catch(reason => ok(false, reason)) 101 } 102 103 SimpleTest.waitForExplicitFinish(); 104 manager.runTests(gEMETests, startTest); 105 </script> 106 </pre> 107 </body> 108 </html>