OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>MediaKeySession lifetime after release()</title> | 4 <title>MediaKeySession lifetime after release()</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 <script> | 10 <script> |
11 // MediaKeySessions remain as long as: | 11 // MediaKeySessions remain as long as: |
12 // JavaScript has a reference to it | 12 // JavaScript has a reference to it |
13 // OR (MediaKeys is around | 13 // OR (MediaKeys is around |
14 // AND the session has not received a close() event) | 14 // AND the session has not received a close() event) |
15 async_test(function(test) | 15 promise_test(function(test) |
16 { | 16 { |
17 gc(); | |
18 var mediaKeys; | 17 var mediaKeys; |
19 var mediaKeySession1; | 18 var mediaKeySession1; |
20 var mediaKeySession2; | 19 var mediaKeySession2; |
21 var initDataType; | 20 var initDataType; |
22 var initData; | 21 var initData; |
23 var startingMediaKeysCount = window.internals.mediaKeysCount(); | |
24 var startingMediaKeySessionCount = window.internals.mediaKeySess
ionCount(); | |
25 | |
26 function numMediaKeysCreated() | |
27 { | |
28 return window.internals.mediaKeysCount() - startingMediaKeys
Count; | |
29 } | |
30 | |
31 function numMediaKeySessionCreated() | |
32 { | |
33 return window.internals.mediaKeySessionCount() - startingMed
iaKeySessionCount; | |
34 } | |
35 | 22 |
36 // Create 2 sessions. | 23 // Create 2 sessions. |
37 navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimp
leConfiguration()).then(function(access) { | 24 // Even though there should be no existing objects, start by |
| 25 // running gc() and verifying that none exist. This also |
| 26 // allows the failures to be reported from inside a promise |
| 27 // so that the test fails properly. |
| 28 return createGCPromise().then(function() { |
| 29 verifyMediaKeyAndMediaKeySessionCount(0, 0, 'After initial g
c()'); |
| 30 |
| 31 return navigator.requestMediaKeySystemAccess('org.w3.clearke
y', getSimpleConfiguration()); |
| 32 }).then(function(access) { |
38 initDataType = access.getConfiguration().initDataTypes[0]; | 33 initDataType = access.getConfiguration().initDataTypes[0]; |
39 initData = getInitData(initDataType); | 34 initData = getInitData(initDataType); |
40 return access.createMediaKeys(); | 35 return access.createMediaKeys(); |
41 }).then(function(result) { | 36 }).then(function(result) { |
42 mediaKeys = result; | 37 mediaKeys = result; |
43 | 38 verifyMediaKeyAndMediaKeySessionCount(1, 0, 'MediaKeys.creat
e()'); |
44 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.create()'
); | |
45 assert_equals(numMediaKeySessionCreated(), 0, 'MediaKeys.cre
ate()'); | |
46 | 39 |
47 mediaKeySession1 = mediaKeys.createSession(); | 40 mediaKeySession1 = mediaKeys.createSession(); |
48 return mediaKeySession1.generateRequest(initDataType, initDa
ta); | 41 return mediaKeySession1.generateRequest(initDataType, initDa
ta); |
49 }).then(function() { | 42 }).then(function() { |
50 assert_equals(numMediaKeysCreated(), 1, 'MediaKeys.createSes
sion(1)'); | 43 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'MediaKeys.creat
eSession(1)'); |
51 assert_equals(numMediaKeySessionCreated(), 1, 'MediaKeys.cre
ateSession(1)'); | |
52 | 44 |
53 mediaKeySession2 = mediaKeys.createSession(); | 45 mediaKeySession2 = mediaKeys.createSession(); |
54 return mediaKeySession2.generateRequest(initDataType, initDa
ta); | 46 return mediaKeySession2.generateRequest(initDataType, initDa
ta); |
55 }).then(function() { | 47 }).then(function() { |
56 assert_equals(numMediaKeysCreated(), 1, 'mediaKeys.createSes
sion(2)'); | 48 verifyMediaKeyAndMediaKeySessionCount(1, 2, 'mediaKeys.creat
eSession(2)'); |
57 assert_equals(numMediaKeySessionCreated(), 2, 'mediaKeys.cre
ateSession(2)'); | |
58 | 49 |
59 // Close the sessions. Once completed, only the JS | 50 // Close the sessions. Once completed, only the JS |
60 // reference to them keeps them around. | 51 // reference to them keeps them around. |
61 return mediaKeySession1.close(); | 52 return mediaKeySession1.close(); |
62 }).then(function(result) { | 53 }).then(function(result) { |
63 return mediaKeySession2.close(); | 54 return mediaKeySession2.close(); |
64 }).then(function(result) { | 55 }).then(function(result) { |
65 // Since both sessions have been closed, dropping the | 56 // Since both sessions have been closed, dropping the |
66 // reference to them from JS will result in the session | 57 // reference to them from JS will result in the session |
67 // being garbage-collected. | 58 // being garbage-collected. |
68 assert_equals(numMediaKeysCreated(), 1, 'after close'); | 59 verifyMediaKeyAndMediaKeySessionCount(1, 2, 'after close'); |
69 assert_equals(numMediaKeySessionCreated(), 2, 'after close')
; | |
70 | 60 |
71 mediaKeySession1 = null; | 61 mediaKeySession1 = null; |
72 return createGCPromise(); | 62 return createGCPromise(); |
73 }).then(function() { | 63 }).then(function() { |
74 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession1 no
t collected'); | 64 verifyMediaKeyAndMediaKeySessionCount(1, 1, 'mediaKeySession
1 not collected'); |
75 assert_equals(numMediaKeySessionCreated(), 1, 'mediaKeySessi
on1 not collected'); | |
76 | 65 |
77 mediaKeySession2 = null; | 66 mediaKeySession2 = null; |
78 return createGCPromise(); | 67 return createGCPromise(); |
79 }).then(function() { | 68 }).then(function() { |
80 assert_equals(numMediaKeysCreated(), 1, 'mediaKeySession2 no
t collected'); | 69 verifyMediaKeyAndMediaKeySessionCount(1, 0, 'mediaKeySession
2 not collected'); |
81 assert_equals(numMediaKeySessionCreated(), 0, 'mediaKeySessi
on2 not collected'); | |
82 test.done(); | |
83 }).catch(function(error) { | |
84 forceTestFailureFromPromise(test, error); | |
85 }); | 70 }); |
86 }, 'MediaKeySession lifetime after release()'); | 71 }, 'MediaKeySession lifetime after release()'); |
87 </script> | 72 </script> |
88 </body> | 73 </body> |
89 </html> | 74 </html> |
OLD | NEW |