test_embed_sizing.html (2383B)
1 <!DOCTYPE html> 2 <script src="/tests/SimpleTest/SimpleTest.js"></script> 3 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 4 5 <p>Test intrinsic sizing of embed elements referencing SVG documents, both same 6 origin and cross origin.</p> 7 8 <div id="container" style="width: 500px;"></div> 9 10 <script> 11 const TESTS = [ 12 { outer: "none", inner: "none", expected: "300x150" }, 13 { outer: "none", inner: "size", expected: "200x900" }, 14 { outer: "none", inner: "ratio", expected: "500x2500" }, 15 { outer: "none", inner: "both", expected: "200x400" }, 16 { outer: "size", inner: "none", expected: "100x150" }, 17 { outer: "size", inner: "size", expected: "100x450" }, 18 { outer: "size", inner: "ratio", expected: "100x500" }, 19 { outer: "size", inner: "both", expected: "100x200" }, 20 { outer: "ratio", inner: "none", expected: "500x1500" }, 21 { outer: "ratio", inner: "size", expected: "200x900" }, 22 { outer: "ratio", inner: "ratio", expected: "500x1500" }, 23 { outer: "ratio", inner: "both", expected: "200x400" }, 24 { outer: "both", inner: "none", expected: "100x300" }, 25 { outer: "both", inner: "size", expected: "100x300" }, 26 { outer: "both", inner: "ratio", expected: "100x300" }, 27 { outer: "both", inner: "both", expected: "100x300" }, 28 ]; 29 30 add_task(async function() { 31 for (let test of TESTS) { 32 for (let crossorigin of [false, true]) { 33 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 34 let host = crossorigin ? "https://example.org" : "http://mochi.test:8888"; 35 let e = document.createElement("embed"); 36 37 switch (test.outer) { 38 case "none": 39 break; 40 case "size": 41 e.style.width = "100px"; 42 break; 43 case "ratio": 44 e.style.aspectRatio = "1 / 3"; 45 break; 46 case "both": 47 e.style.width = "100px"; 48 e.style.aspectRatio = "1 / 3"; 49 break; 50 default: 51 throw new Error("unexpected subtest"); 52 } 53 54 await new Promise(function(resolve) { 55 e.src = host + location.pathname.replace("test_embed_sizing.html", `file_embed_sizing_${test.inner}.svg`); 56 e.onload = resolve; 57 container.append(e); 58 }); 59 60 let desc = `Subtest (${test.outer}/${test.inner}/${crossorigin ? 'cross' : 'same'} origin)`; 61 is(`${e.offsetWidth}x${e.offsetHeight}`, test.expected, desc); 62 e.remove(); 63 } 64 } 65 }); 66 </script>