Bug 1413427 - Part5 - Fix cross origin test failure. draft
authorJames Cheng <jacheng@mozilla.com>
Fri, 03 Nov 2017 17:57:52 +0800
changeset 695355 55b240f88d1c406055bd47479f47c4cb8e139a92
parent 695354 1eee8556cdab60512d11fc8b6eba2410f975a460
child 739578 4ed193b7b61f5d85a657ef6742fa18959219b42a
push id88402
push userbmo:jacheng@mozilla.com
push dateThu, 09 Nov 2017 04:25:32 +0000
bugs1413427, 1322517
milestone58.0a1
Bug 1413427 - Part5 - Fix cross origin test failure. Bug 1322517 will make the EME APIs only run on secure context. This bug will try to make WPT test run with https. According to the spec https://www.w3.org/TR/secure-contexts/#is-url-trustworthy I got "TypeError: navigator.requestMediaKeySystemAccess is not a function" by the original code. So I need this patch to make the test work as expected. MozReview-Commit-ID: Gp23IcscXHE
testing/web-platform/tests/encrypted-media/scripts/unique-origin.js
--- a/testing/web-platform/tests/encrypted-media/scripts/unique-origin.js
+++ b/testing/web-platform/tests/encrypted-media/scripts/unique-origin.js
@@ -5,32 +5,32 @@ function runTest(config) {
 
     function load_iframe(src, sandbox) {
         return new Promise(function (resolve) {
             var iframe = document.createElement('iframe');
             iframe.onload = function () {
                 resolve(iframe);
             };
             iframe.sandbox = sandbox;
-            iframe.src = src;
+            iframe.srcdoc = src;
             document.documentElement.appendChild(iframe);
         });
     }
 
     function wait_for_message() {
         return new Promise(function (resolve) {
             self.addEventListener('message', function listener(e) {
                 resolve(e.data);
                 self.removeEventListener('message', listener);
             });
         });
     }
 
     promise_test(function (test) {
-        var script = 'data:text/html,' +
+        var script =
           '<script>' +
           '    window.onmessage = function(e) {' +
           '        navigator.requestMediaKeySystemAccess("' + config.keysystem + '", [{' +
           '           initDataTypes: [\"' + config.initDataType + '\"],' +
           '           audioCapabilities: [' +
           '               { contentType:\'' + config.audioType + '\'},' +
           '           ]' +
           '       }]).then(function(access) {' +
@@ -48,17 +48,17 @@ function runTest(config) {
             initDataTypes: [config.initDataType],
             audioCapabilities: [
                 {contentType: config.audioType},
             ]
         }]).then(function (access) {
             return access.createMediaKeys();
         }).then(function (mediaKeys) {
             // Success, so now create the iframe and try there.
-            return load_iframe(script, 'allow-scripts');
+            return load_iframe(script, 'allow-scripts allow-secure-context');
         }).then(function (iframe) {
             iframe.contentWindow.postMessage({}, '*');
             return wait_for_message();
         }).then(function (message) {
             assert_equals(message.result, 'failed');
         });
     }, 'Unique origin is unable to create MediaKeys');
 }