Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / encrypted-media / encrypted-media-lifetime-mediakeysession-release.html
blob499e24e642efff610a05ffd3f7bad2687c3a2845
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>MediaKeySession lifetime after release()</title>
5 <script src="encrypted-media-utils.js"></script>
6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script>
8 </head>
9 <body>
10 <div id="log"></div>
11 <script>
12 // Since MediaKeySession (and MediaKeys) are ActiveDOMObjects,
13 // we can determine when they are garbage collected.
14 // MediaKeySessions remain as long as:
15 // JavaScript has a reference to it
16 // OR (MediaKeys is around
17 // AND the session has not received a close() event)
18 async_test(function(test)
20 var mediaKeys;
21 var mediaKeySession1;
22 var mediaKeySession2;
23 var initDataType;
24 var initData;
25 var startingActiveDOMObjectCount = window.internals.activeDOMObjectCount(document);
27 function numActiveDOMObjectsCreated()
29 return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount;
32 // Create 2 sessions.
33 getSupportedInitDataType().then(function(type) {
34 initDataType = type;
35 initData = getInitData(initDataType);
36 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
37 }).then(function(access) {
38 return access.createMediaKeys();
39 }).then(function(result) {
40 mediaKeys = result;
42 // Verify MediaKeys is an ActiveDOMObject.
43 // In non-Oilpan, numActiveDOMObjectsCreate() == 1.
44 // In Oilpan, numActiveDOMObjectsCreate() <= 4.
45 // (1 MediaKeys,
46 // 1 MediaKeysInitializer and
47 // 1 MediaKeySystemAccessInitializer (navigator.requestMediaKeySystemAccess() use above),
48 // 1 MediaKeySystemAccessInitializer (isInitDataSupported() (via getSupportedInitDataType())))
49 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 4, 'MediaKeys.create()');
51 mediaKeySession1 = mediaKeys.createSession();
52 return mediaKeySession1.generateRequest(initDataType, initData);
53 }).then(function() {
54 // Should be 1 MediaKeys + 1 MediaKeySession.
55 // In non-Oilpan, numActiveDOMObjectsCreate() == 2.
56 // In Oilpan, numActiveDOMObjectsCreate() <= 6.
57 // (1 MediaKeys,
58 // 1 MediaKeysInitializer,
59 // 2 MediaKeySystemAccessInitializers,
60 // 1 ContentDecryptionModuleResultPromise and
61 // 1 MediaKeySession).
62 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 6, 'MediaKeys.createSession(1)');
64 mediaKeySession2 = mediaKeys.createSession();
65 return mediaKeySession2.generateRequest(initDataType, initData);
66 }).then(function() {
67 // Should be 1 MediaKeys + 2 MediaKeySessions.
68 // In non-Oilpan, numActiveDOMObjectsCreate() == 3.
69 // In Oilpan, numActiveDOMObjectsCreate() <= 8.
70 // (1 MediaKeys,
71 // 1 MediaKeysInitializer,
72 // 2 MediaKeySystemAccessInitializers,
73 // 2 ContentDecryptionModuleResultPromise and
74 // 2 MediaKeySession).
75 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 8, 'mediaKeys.createSession(2)');
77 // Close the sessions. Once completed, only the JS
78 // reference to them keeps them around.
79 return mediaKeySession1.close();
80 }).then(function(result) {
81 return mediaKeySession2.close();
82 }).then(function(result) {
83 // Since both sessions have been closed, dropping the
84 // reference to them from JS will result in the session
85 // being garbage-collected.
86 // Should be 1 MediaKeys + 2 MediaKeySessions.
87 // In non-Oilpan, numActiveDOMObjectsCreate() == 3.
88 // In Oilpan, numActiveDOMObjectsCreate() <= 10.
89 // (1 MediaKeys,
90 // 1 MediaKeysInitializer,
91 // 2 MediaKeySystemAccessInitializers,
92 // 4 ContentDecryptionModuleResultPromise and
93 // 2 MediaKeySession).
94 assert_between_inclusive(numActiveDOMObjectsCreated(), 3, 10, 'after close');
96 mediaKeySession1 = null;
97 return createGCPromise();
98 }).then(function() {
99 // Only MediaKeys + mediaKeySession2 should remain.
100 // In non-Oilpan, there is also something from createGCPromise().
101 assert_between_inclusive(numActiveDOMObjectsCreated(), 2, 3, 'mediaKeySession1 not collected');
103 mediaKeySession2 = null;
104 return createGCPromise();
105 }).then(function() {
106 // Only MediaKeys should remain.
107 // In non-Oilpan, there is also something from createGCPromise().
108 assert_between_inclusive(numActiveDOMObjectsCreated(), 1, 2, 'mediaKeySession2 not collected');
109 test.done();
110 }).catch(function(error) {
111 forceTestFailureFromPromise(test, error);
113 }, 'MediaKeySession lifetime after release()');
114 </script>
115 </body>
116 </html>