Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / encrypted-media / encrypted-media-encrypted-event-different-origin.html
blobde3962f06344e5a4aecb38d8551ced20a6ab3824
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Initialization Data not returned when using different origin</title>
5 <script src="/js-test-resources/testharness.js"></script>
6 <script src="/js-test-resources/testharnessreport.js"></script>
7 </head>
8 <body>
9 <video id="testVideo"></video>
10 <div id="log"></div>
11 <script>
12 async_test(function(test)
14 var video = document.getElementById('testVideo');
15 var encryptedEventCount = 0;
17 function logMessage(msg) {
18 var date = new Date();
19 var hours = ('0' + date.getHours()).slice(-2);
20 var minutes = ('0' + date.getMinutes()).slice(-2);
21 var secs = ('0' + date.getSeconds()).slice(-2);
22 var milliSecs = ('00' + date.getMilliseconds()).slice(-3);
23 console.log(hours + ':' + minutes + ':' + secs + '.' + milliSecs + ': ' + msg);
26 function onEncrypted(event)
28 logMessage('onEncrypted');
29 assert_equals(event.target, video);
30 assert_true(event instanceof window.MediaEncryptedEvent);
31 assert_equals(event.type, 'encrypted');
33 // Since the .src is in a different origin as this test,
34 // both initDataType and initData should be empty.
35 assert_equals(event.initDataType, '');
36 assert_equals(event.initData.byteLength, 0);
38 // Both the audio and the video tracks have initData,
39 // so finish once both events are received.
40 if (++encryptedEventCount == 2) {
41 logMessage('done');
42 test.done();
46 logMessage('starting');
47 navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
48 return access.createMediaKeys();
49 }).then(function(mediaKeys) {
50 video.addEventListener('encrypted', test.step_func(onEncrypted), true);
51 return video.setMediaKeys(mediaKeys);
52 }).then(function(result) {
53 // Verify that the current origin is different than what
54 // we use for the content.
55 logMessage('setting src');
56 assert_equals(document.origin, 'http://127.0.0.1:8000');
57 video.src = 'http://127.0.0.1:8080/media/encrypted-media/test-encrypted.webm';
58 video.play();
59 });
60 }, 'Initialization Data not returned when using different origin.');
61 </script>
62 </body>
63 </html>