Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/LayoutTests/media/encrypted-media/prefixed/encrypted-media-events.html

Issue 1712903002: Remove prefixed EME. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix isRenewalMessage() in browser tests. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <html lang="en">
3 <head>
4 </head>
5 <body>
6 <video></video>
7 <p>Test all the key-related events.</p>
8
9 <script src="../encrypted-media-utils.js"></script>
10 <script src=../../media-file.js></script>
11 <script src=../../video-test.js></script>
12 <script>
13 // First, try explicitly creating those events with specific IDL.
14 var keyNeededEvent = document.createEvent("MediaKeyEvent");
15 testExpected("keyNeededEvent", null, "!=");
16 testExpected("keyNeededEvent instanceof window.MediaKeyEvent", true) ;
17
18 // Next, The test runs twice, once using on* and then using addEvent Listener().
19 var isFirstRun = true;
20
21 // The Initialization Data in test-encrypted.webm.
22 var expectedInitData = stringToUint8Array('0123456789012345');
23 // A 128-bit key. It is not the actual key for test-encrypted.webm.
24 var key = new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
25 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70]);
26 // This key will cause an asynchronous error because it is too short .
27 var invalidKey = new Uint8Array([0x61]);
28
29 // After the first keyMessage event, the sessionId should always be the same.
30 // Initialize it to an invalid value until then.
31 var keyMessageSessionId = -1;
32 // Remember the first ID to make sure the second one is different.
33 var firstRunKeyMessageSessionId = -1;
34
35 function keyAdded(event)
36 {
37 consoleWrite("keyadded event occurred");
38
39 testExpected("event.target", video);
40 testExpected("event instanceof window.MediaKeyEvent", true);
41
42 testExpected("event.keySystem", "webkit-org.w3.clearkey");
43 testExpected("event.sessionId == keyMessageSessionId", true);
44 // The other attributes are not used for this event.
45 testExpected("event.initData", null, "===");
46 testExpected("event.message", null, "===");
47 testExpected("event.defaultURL", "");
48 testExpected("event.errorCode", null, "===");
49 testExpected("event.systemCode", 0);
50
51 consoleWrite("");
52 // Cause a keyerror by passing an invalid key.
53 run("video.webkitAddKey('webkit-org.w3.clearkey', invalidKey, nu ll, event.sessionId)");
54 }
55
56 function keyError(event)
57 {
58 consoleWrite("keyerror event occurred");
59
60 testExpected("event.target", video);
61 testExpected("event instanceof window.MediaKeyEvent", true);
62
63 testExpected("event.keySystem", "webkit-org.w3.clearkey");
64 testExpected("event.sessionId == keyMessageSessionId", true);
65 // The next three attributes are not used for this event.
66 testExpected("event.initData", null, "===");
67 testExpected("event.message", null, "===");
68 testExpected("event.defaultURL", "");
69 testExpected("event.errorCode.code", MediaKeyError.MEDIA_KEYERR_ UNKNOWN);
70 // systemCode is not supported by the Clear Key key system.
71 testExpected("event.systemCode", 0);
72
73 if (isFirstRun) {
74 isFirstRun = false;
75 runTest();
76 } else {
77 consoleWrite("");
78 consoleWrite("Attributes are read-only.");
79 run("event.keySystem = 'blah'");
80 run("event.sessionId = 'blah'");
81 run("event.initData = new Uint8Array([0x12])");
82 run("event.message = new Uint8Array([0x12])");
83 run("event.defaultURL = 'example.com'");
84 run("event.errorCode.code = MediaKeyError.MEDIA_KEYERR_CLIEN T");
85 run("event.systemCode = 123");
86
87 testExpected("event.keySystem", "webkit-org.w3.clearkey");
88 testExpected("event.sessionId == keyMessageSessionId", true) ;
89 testExpected("event.initData", null, "===");
90 testExpected("event.message", null, "===");
91 testExpected("event.defaultURL", "");
92 testExpected("event.errorCode.code", MediaKeyError.MEDIA_KEY ERR_UNKNOWN);
93 testExpected("event.systemCode", 0);
94
95 endTest();
96 }
97 }
98
99 function keyMessage(event)
100 {
101 consoleWrite("keymessage event occurred");
102
103 testExpected("event.target", video);
104 testExpected("event instanceof window.MediaKeyEvent", true);
105
106 testExpected("event.keySystem", "webkit-org.w3.clearkey");
107
108 consoleWrite("The sessionId should be a non-empty string contain ing an integer.");
109 testExpected("event.sessionId", "", "!=");
110 testExpected("event.sessionId", null, "!=");
111 testExpected("event.sessionId", undefined, "!=");
112 testExpected("isNaN(event.sessionId)", false);
113 // Make sure the number is not a float.
114 testExpected("String(event.sessionId) == String(parseInt(event.s essionId))", true);
115 consoleWrite("Implementations should avoid sessionIds of 0.");
116 testExpected("event.sessionId", 0, ">");
117 // All other events should have this same sessionId.
118 keyMessageSessionId = event.sessionId;
119 if (isFirstRun)
120 firstRunKeyMessageSessionId = keyMessageSessionId;
121 else {
122 consoleWrite("The sessionsId should be different from the fi rst run.");
123 testExpected("event.sessionId != firstRunKeyMessageSessionId ", true);
124 }
125
126 // initData is not used for this event.
127 testExpected("event.initData", null, "===");
128 // At least for now, the Clear Key message is the initData.
129 testArraysEqual("event.message", expectedInitData);
130 // Not supported by the test file.
131 testExpected("event.defaultURL", "");
132 // The error attributes are not used for this event.
133 testExpected("event.errorCode", null, "===");
134 testExpected("event.systemCode", 0);
135
136 consoleWrite("");
137 run("video.webkitAddKey('webkit-org.w3.clearkey', key, event.ini tData, event.sessionId)");
138 }
139
140 function needKey(event)
141 {
142 consoleWrite("needkey event occurred");
143 // Clear the handler (for the first case) to prevent the second needkey event
144 // (there will be one each for audio and video) from being handl ed.
145 video.onwebkitneedkey=null;
146
147 testExpected("event.target", video);
148 testExpected("event instanceof window.MediaKeyEvent", true);
149
150 testExpected("event.keySystem", "");
151 testExpected("event.sessionId", "");
152 testArraysEqual("event.initData", expectedInitData);
153 // The other attributes are not used for this event.
154 testExpected("event.message", null, "===");
155 testExpected("event.defaultURL", "");
156 testExpected("event.errorCode", null, "===");
157 testExpected("event.systemCode", 0);
158
159 consoleWrite("");
160 run("video.webkitGenerateKeyRequest('webkit-org.w3.clearkey', ev ent.initData)");
161 }
162
163 function runTest()
164 {
165 consoleWrite("");
166 if (isFirstRun) {
167 consoleWrite("*** Test events using on* attributes. ***");
168 video.onwebkitkeyadded=keyAdded;
169 video.onwebkitkeyerror=keyError;
170 video.onwebkitkeymessage=keyMessage;
171 video.onwebkitneedkey=needKey;
172 } else {
173 consoleWrite("*** Test events using addEventListener(). ***" );
174
175 // Clear the on* handlers.
176 video.onwebkitkeyadded=null;
177 video.onwebkitkeyerror=null;
178 video.onwebkitkeymessage=null;
179 video.onwebkitneedkey=null;
180
181 waitForEvent('webkitkeyadded', keyAdded);
182 waitForEvent('webkitkeyerror', keyError);
183 waitForEvent('webkitkeymessage', keyMessage);
184 waitForEventOnce('webkitneedkey', needKey);
185 }
186
187 video.src = "../../content/test-encrypted.webm";
188 }
189
190 consoleWrite("");
191 consoleWrite("*** Verify the presence of on* attributes. These would return undefined if they are not present. ***");
192 testExpected("video.onwebkitkeyadded", null, "===");
193 testExpected("video.onwebkitkeyerror", null, "===");
194 testExpected("video.onwebkitkeymessage", null, "===");
195 testExpected("video.onwebkitneedkey", null, "===");
196
197 runTest();
198
199 </script>
200 </body>
201 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698