OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Test MediaKeys lifetime when adding a session</title> | 4 <title>Test MediaKeys lifetime when adding a session</title> |
5 <script src="encrypted-media-utils.js"></script> | 5 <script src="encrypted-media-utils.js"></script> |
6 <script src="../../resources/testharness.js"></script> | 6 <script src="../../resources/testharness.js"></script> |
7 <script src="../../resources/testharnessreport.js"></script> | 7 <script src="../../resources/testharnessreport.js"></script> |
8 </head> | 8 </head> |
9 <body> | 9 <body> |
10 <div id="log"></div> | 10 <div id="log"></div> |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 // Create a MediaKeys object with a session. | 37 // Create a MediaKeys object with a session. |
38 navigator.requestMediaKeySystemAccess('org.w3.clearkey').then(fu
nction(access) { | 38 navigator.requestMediaKeySystemAccess('org.w3.clearkey').then(fu
nction(access) { |
39 assert_equals(access.keySystem, 'org.w3.clearkey'); | 39 assert_equals(access.keySystem, 'org.w3.clearkey'); |
40 return access.createMediaKeys(); | 40 return access.createMediaKeys(); |
41 }).then(function(result) { | 41 }).then(function(result) { |
42 mediaKeys = result; | 42 mediaKeys = result; |
43 | 43 |
44 // Verify MediaKeys are not an ActiveDOMObject. | 44 // Verify MediaKeys are not an ActiveDOMObject. |
45 assert_equals(numActiveDOMObjectsCreated(), 0, 'MediaKeys.cr
eate()'); | 45 // In non-Oilpan, numActiveDOMObjectsCreate() == 0. |
| 46 // In Oilpan, numActiveDOMObjectsCreate() <= 2. |
| 47 // (1 MediaKeysInitializer and |
| 48 // 1 MediaKeySystemAccessInitializer). |
| 49 assert_less_than_equal(numActiveDOMObjectsCreated(), 2, 'Med
iaKeys.create()'); |
46 | 50 |
47 var initDataType = getInitDataType(); | 51 var initDataType = getInitDataType(); |
48 var mediaKeySession = mediaKeys.createSession(); | 52 var mediaKeySession = mediaKeys.createSession(); |
49 return mediaKeySession.generateRequest(initDataType, getInit
Data(initDataType)); | 53 return mediaKeySession.generateRequest(initDataType, getInit
Data(initDataType)); |
50 }).then(function() { | 54 }).then(function() { |
51 // 1 MediaKeySession. | 55 // 1 MediaKeySession. |
52 assert_equals(numActiveDOMObjectsCreated(), 1, 'MediaKeys.cr
eateSession()'); | 56 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. |
| 57 // In Oilpan, numActiveDOMObjectsCreate() <= 4. |
| 58 // (1 MediaKeysInitializer, |
| 59 // 1 MediaKeySystemAccessInitializer, |
| 60 // 1 ContentDecryptionModuleResultPromise and |
| 61 // 1 MediaKeySession). |
| 62 assert_less_than_equal(numActiveDOMObjectsCreated(), 4, 'Med
iaKeys.createSession(1)'); |
53 | 63 |
54 // Run gc(), should not affect MediaKeys object nor the | 64 // Run gc(), should not affect MediaKeys object nor the |
55 // session since we still have a reference to it. | 65 // session since we still have a reference to it. |
| 66 |
| 67 // When enabling oilpan GC, the in-active |
| 68 // ScriptPromiseResolvers will be destroyed. |
56 return createGCPromise(); | 69 return createGCPromise(); |
57 }).then(function(result) { | 70 }).then(function(result) { |
58 assert_equals(typeof mediaKeys.createSession, 'function'); | 71 assert_equals(typeof mediaKeys.createSession, 'function'); |
59 // Ensure that MediaKeySession (but not PromiseResolver) is | 72 // Ensure that MediaKeySession (but not PromiseResolver) is |
60 // still around. | 73 // still around. |
61 assert_equals(numActiveDOMObjectsCreated(), 1, 'After gc()')
; | 74 assert_equals(numActiveDOMObjectsCreated(), 1, 'After gc()')
; |
62 | 75 |
63 // Drop reference to the MediaKeys object and run gc() | 76 // Drop reference to the MediaKeys object and run gc() |
64 // again. Object should be collected this time. Since | 77 // again. Object should be collected this time. Since |
65 // MediaKeySessions remain alive as long as MediaKeys is | 78 // MediaKeySessions remain alive as long as MediaKeys is |
66 // around, it is possible that gc() checks the | 79 // around, it is possible that gc() checks the |
67 // MediaKeySession object first, and doesn't collect it | 80 // MediaKeySession object first, and doesn't collect it |
68 // since MediaKeys hasn't been collected yet. Thus run gc() | 81 // since MediaKeys hasn't been collected yet. Thus run gc() |
69 // twice, to ensure that the unreferenced MediaKeySession | 82 // twice, to ensure that the unreferenced MediaKeySession |
70 // object get collected. | 83 // object get collected. |
71 mediaKeys = null; | 84 mediaKeys = null; |
72 return createGCPromise(); | 85 return createGCPromise(); |
73 }).then(function(result) { | 86 }).then(function(result) { |
74 return createGCPromise(); | 87 return createGCPromise(); |
75 }).then(function(result) { | 88 }).then(function(result) { |
76 assert_equals(numActiveDOMObjectsCreated(), 0); | 89 assert_equals(numActiveDOMObjectsCreated(), 0); |
77 test.done(); | 90 test.done(); |
78 }).catch(function(error) { | 91 }).catch(function(error) { |
79 forceTestFailureFromPromise(test, error); | 92 forceTestFailureFromPromise(test, error); |
80 }); | 93 }); |
81 }, 'MediaKeys lifetime with session'); | 94 }, 'MediaKeys lifetime with session'); |
82 </script> | 95 </script> |
83 </body> | 96 </body> |
84 </html> | 97 </html> |
OLD | NEW |