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> |
11 <script> | 11 <script> |
12 // Since MediaKeys are not ActiveDOMObjects, it is hard to | 12 // Since MediaKeys are not ActiveDOMObjects, it is hard to |
13 // determine when they are garbage collected. For the test below | 13 // determine when they are garbage collected. For the test below |
14 // a MediaKeySession (which is an ActiveDOMObject) is added so | 14 // a MediaKeySession (which is an ActiveDOMObject) is added so |
15 // there is something to count. | 15 // there is something to count. |
16 | 16 |
17 // MediaKeySessions remain as long as: | 17 // MediaKeySessions remain as long as: |
18 // JavaScript has a reference to it | 18 // JavaScript has a reference to it |
19 // OR (MediaKeys is around | 19 // OR (MediaKeys is around |
20 // AND the session has not received a close() event) | 20 // AND the session has not received a close() event) |
21 // In the tests below, we do not close any session nor keep a | 21 // In the tests below, we do not close any session nor keep a |
22 // Javascript reference to any session, so MediaKeySessions remain | 22 // Javascript reference to any session, so MediaKeySessions remain |
23 // as long as the associated MediaKeys object is around. | 23 // as long as the associated MediaKeys object is around. |
24 | 24 |
25 // For this test, create a MediaKeySession (which is an | 25 // For this test, create a MediaKeySession (which is an |
26 // ActiveDOMObject) and verify lifetime. | 26 // ActiveDOMObject) and verify lifetime. |
27 async_test(function(test) | 27 async_test(function(test) |
28 { | 28 { |
| 29 var initDataType; |
| 30 var initData; |
29 var mediaKeys; | 31 var mediaKeys; |
30 var startingActiveDOMObjectCount = window.internals.activeDOMObj
ectCount(document); | 32 var startingActiveDOMObjectCount = window.internals.activeDOMObj
ectCount(document); |
31 | 33 |
32 function numActiveDOMObjectsCreated() | 34 function numActiveDOMObjectsCreated() |
33 { | 35 { |
34 return window.internals.activeDOMObjectCount(document) - sta
rtingActiveDOMObjectCount; | 36 return window.internals.activeDOMObjectCount(document) - sta
rtingActiveDOMObjectCount; |
35 } | 37 } |
36 | 38 |
37 // Create a MediaKeys object with a session. | 39 // Create a MediaKeys object with a session. |
38 navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).t
hen(function(access) { | 40 getSupportedInitDataType().then(function(type) { |
| 41 initDataType = type; |
| 42 initData = getInitData(initDataType); |
| 43 return navigator.requestMediaKeySystemAccess('org.w3.clearke
y', [{}]); |
| 44 }).then(function(access) { |
39 assert_equals(access.keySystem, 'org.w3.clearkey'); | 45 assert_equals(access.keySystem, 'org.w3.clearkey'); |
40 return access.createMediaKeys(); | 46 return access.createMediaKeys(); |
41 }).then(function(result) { | 47 }).then(function(result) { |
42 mediaKeys = result; | 48 mediaKeys = result; |
43 | 49 |
44 // Verify MediaKeys are not an ActiveDOMObject. | 50 // Verify MediaKeys are not an ActiveDOMObject. |
45 // In non-Oilpan, numActiveDOMObjectsCreate() == 0. | 51 // In non-Oilpan, numActiveDOMObjectsCreate() == 0. |
46 // In Oilpan, numActiveDOMObjectsCreate() <= 2. | 52 // In Oilpan, numActiveDOMObjectsCreate() <= 2. |
47 // (1 MediaKeysInitializer and | 53 // (1 MediaKeysInitializer and |
48 // 1 MediaKeySystemAccessInitializer). | 54 // 1 MediaKeySystemAccessInitializer). |
49 assert_less_than_equal(numActiveDOMObjectsCreated(), 2, 'Med
iaKeys.create()'); | 55 assert_less_than_equal(numActiveDOMObjectsCreated(), 2, 'Med
iaKeys.create()'); |
50 | 56 |
51 var initDataType = getInitDataType(); | |
52 var mediaKeySession = mediaKeys.createSession(); | 57 var mediaKeySession = mediaKeys.createSession(); |
53 return mediaKeySession.generateRequest(initDataType, getInit
Data(initDataType)); | 58 return mediaKeySession.generateRequest(initDataType, initDat
a); |
54 }).then(function() { | 59 }).then(function() { |
55 // 1 MediaKeySession. | 60 // 1 MediaKeySession. |
56 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. | 61 // In non-Oilpan, numActiveDOMObjectsCreate() == 1. |
57 // In Oilpan, numActiveDOMObjectsCreate() <= 4. | 62 // In Oilpan, numActiveDOMObjectsCreate() <= 4. |
58 // (1 MediaKeysInitializer, | 63 // (1 MediaKeysInitializer, |
59 // 1 MediaKeySystemAccessInitializer, | 64 // 1 MediaKeySystemAccessInitializer, |
60 // 1 ContentDecryptionModuleResultPromise and | 65 // 1 ContentDecryptionModuleResultPromise and |
61 // 1 MediaKeySession). | 66 // 1 MediaKeySession). |
62 assert_less_than_equal(numActiveDOMObjectsCreated(), 4, 'Med
iaKeys.createSession(1)'); | 67 assert_less_than_equal(numActiveDOMObjectsCreated(), 4, 'Med
iaKeys.createSession(1)'); |
63 | 68 |
(...skipping 24 matching lines...) Expand all Loading... |
88 }).then(function(result) { | 93 }).then(function(result) { |
89 assert_less_than_equal(numActiveDOMObjectsCreated(), 1); | 94 assert_less_than_equal(numActiveDOMObjectsCreated(), 1); |
90 test.done(); | 95 test.done(); |
91 }).catch(function(error) { | 96 }).catch(function(error) { |
92 forceTestFailureFromPromise(test, error); | 97 forceTestFailureFromPromise(test, error); |
93 }); | 98 }); |
94 }, 'MediaKeys lifetime with session'); | 99 }, 'MediaKeys lifetime with session'); |
95 </script> | 100 </script> |
96 </body> | 101 </body> |
97 </html> | 102 </html> |
OLD | NEW |