Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test MediaKeySession lifetime</title> | |
| 5 <script src="../w3c-media-utils.js"></script> | |
| 6 <script src="../../resources/testharness.js"></script> | |
| 7 <script src="../../resources/testharnessreport.js"></script> | |
| 8 <script src="../../resources/gc.js"></script> | |
| 9 </head> | |
| 10 <body> | |
| 11 <div id="log"></div> | |
| 12 <script> | |
| 13 setup({ timeout: 60000 }); // Timeout for all tests to run. | |
| 14 | |
| 15 // Since MediaKeySession (but not MediaKeys) are ActiveDOMObjects, | |
| 16 // we can determine when they are garbage collected. | |
| 17 // MediaKeySessions remain as long as: | |
| 18 // JavaScript has a reference to it | |
| 19 // OR (MediaKeys is around AND the session has not received a clos e() event) | |
| 20 async_test(function(test) | |
| 21 { | |
| 22 var startingActiveDOMObjectCount = window.internals.activeDOMObj ectCount(document); | |
| 23 | |
| 24 function numActiveDOMObjectsCreated() | |
| 25 { | |
| 26 return window.internals.activeDOMObjectCount(document) - sta rtingActiveDOMObjectCount; | |
| 27 } | |
| 28 | |
| 29 var mediaKeys = new MediaKeys("org.w3.clearkey"); | |
| 30 var mediaKeySession1 = null; | |
| 31 var mediaKeySession2 = null; | |
| 32 var sessionsCreated = 0; | |
| 33 | |
| 34 function onClose(event) | |
| 35 { | |
| 36 --sessionsCreated; | |
| 37 if (sessionsCreated > 0) | |
| 38 return; | |
| 39 | |
| 40 // Delay to give time for close to complete since | |
| 41 // event.target is a reference to the MediaKeySession. | |
|
xhwang
2014/03/27 00:46:40
So really it's used so that finish() is called asy
jrummell
2014/03/27 01:22:23
Done. If we get flakiness on ASAN tests, I'll know
xhwang
2014/03/27 17:07:00
:) well, then at least we know something isn't wor
| |
| 42 setTimeout(finish, 250); | |
| 43 } | |
| 44 | |
| 45 function finish() | |
| 46 { | |
| 47 // Since both sessions have been released, dropping the | |
| 48 // reference to them from JS will result in the session | |
| 49 // being garbage-collected. | |
| 50 consoleWrite("Finish"); | |
| 51 assert_not_equals(mediaKeys, null); | |
| 52 assert_equals(numActiveDOMObjectsCreated(), 2); | |
| 53 | |
| 54 mediaKeySession1 = null; | |
| 55 gc(); | |
| 56 assert_equals(numActiveDOMObjectsCreated(), 1, "mediaKeySess ion1 not collected"); | |
| 57 | |
| 58 mediaKeySession2 = null; | |
| 59 gc(); | |
| 60 assert_equals(numActiveDOMObjectsCreated(), 0, "mediaKeySess ion2 not collected"); | |
| 61 | |
| 62 test.done(); | |
| 63 } | |
| 64 | |
| 65 // Create 2 sessions. | |
| 66 mediaKeySession1 = mediaKeys.createSession('video/webm', new Uin t8Array([1, 2, 3])); | |
| 67 mediaKeySession1.release(); | |
| 68 waitForEventAndRunStep("close", mediaKeySession1, onClose, test) ; | |
| 69 mediaKeySession2 = mediaKeys.createSession('video/webm', new Uin t8Array([4, 5])); | |
| 70 mediaKeySession2.release(); | |
| 71 waitForEventAndRunStep("close", mediaKeySession2, onClose, test) ; | |
|
xhwang
2014/03/27 00:46:40
Can we move these up to replace l.30-31 to be cons
jrummell
2014/03/27 01:22:23
Done.
| |
| 72 sessionsCreated = 2; | |
| 73 }, "MediaKeySession lifetime after release()", { timeout: 60000 }); | |
| 74 </script> | |
| 75 </body> | |
| 76 </html> | |
| OLD | NEW |