| Youenn Fablet | 11ef9303 | 2018-10-30 20:15:45 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset="utf-8"> |
| 3 | <title>RTCCertificate persistent Tests</title> |
| 4 | <script src="/resources/testharness.js"></script> |
| 5 | <script src="/resources/testharnessreport.js"></script> |
| 6 | <script src="/common/get-host-info.sub.js"></script> |
| 7 | <body> |
| 8 | <script> |
| 9 | function findMatchingFingerprint(fingerprints, fingerprint) { |
| 10 | for (let f of fingerprints) { |
| 11 | if (f.value == fingerprint.value && f.algorithm == fingerprint.algorithm) |
| 12 | return true; |
| 13 | } |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | function with_iframe(url) { |
| 18 | return new Promise(function(resolve) { |
| 19 | var frame = document.createElement('iframe'); |
| 20 | frame.src = url; |
| 21 | frame.onload = function() { resolve(frame); }; |
| 22 | document.body.appendChild(frame); |
| 23 | }); |
| 24 | } |
| 25 | |
| 26 | function testPostMessageCertificate(isCrossOrigin) { |
| 27 | promise_test(async t => { |
| 28 | let certificate = await RTCPeerConnection.generateCertificate({ name: 'ECDSA', namedCurve: 'P-256' }); |
| 29 | |
| 30 | let url = "resources/RTCCertificate-postMessage-iframe.html"; |
| 31 | if (isCrossOrigin) |
| 32 | url = get_host_info().HTTP_REMOTE_ORIGIN + "/webrtc/" + url; |
| 33 | |
| 34 | let iframe = await with_iframe(url); |
| 35 | |
| 36 | let promise = new Promise((resolve, reject) => { |
| 37 | window.onmessage = (event) => { |
| 38 | resolve(event.data); |
| 39 | }; |
| 40 | t.step_timeout(() => reject("Timed out waiting for frame to send back certificate"), 5000); |
| 41 | }); |
| 42 | iframe.contentWindow.postMessage(certificate, "*"); |
| 43 | let certificate2 = await promise; |
| 44 | |
| 45 | new RTCPeerConnection({certificates: [certificate]}); |
| 46 | |
| 47 | new RTCPeerConnection({certificates: [certificate2]}); |
| 48 | |
| 49 | assert_equals(certificate.expires, certificate2.expires); |
| 50 | for (let fingerprint of certificate2.getFingerprints()) |
| 51 | assert_true(findMatchingFingerprint(certificate.getFingerprints(), fingerprint), "check fingerprints"); |
| 52 | |
| 53 | iframe.remove(); |
| 54 | }, "Check " + (isCrossOrigin ? "cross-origin" : "same-origin") + " RTCCertificate serialization"); |
| 55 | } |
| 56 | |
| 57 | testPostMessageCertificate(false); |
| 58 | testPostMessageCertificate(true); |
| 59 | |
| 60 | promise_test(async t => { |
| 61 | let url = get_host_info().HTTP_REMOTE_ORIGIN + "/webrtc/resources/RTCCertificate-postMessage-iframe.html"; |
| 62 | let iframe = await with_iframe(url); |
| 63 | |
| 64 | let promise = new Promise((resolve, reject) => { |
| 65 | window.onmessage = (event) => { |
| 66 | resolve(event.data); |
| 67 | }; |
| 68 | t.step_timeout(() => reject("Timed out waiting for frame to send back certificate"), 5000); |
| 69 | }); |
| 70 | iframe.contentWindow.postMessage(null, "*"); |
| 71 | let certificate2 = await promise; |
| 72 | |
| 73 | assert_throws("InvalidAccessError", () => { new RTCPeerConnection({certificates: [certificate2]}) }); |
| 74 | iframe.remove(); |
| 75 | }, "Check cross-origin created RTCCertificate"); |
| 76 | </script> |
| 77 | </body> |