test_bug1260704.html (2876B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1260704 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1260704</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 <script type="text/javascript"> 13 /** Test for Bug 1260704 */ 14 15 function runTests() { 16 let testIdx = -1; 17 let testUrls = [ 18 "bug1260704_iframe.html?noDefault=true&isMap=true", 19 "bug1260704_iframe.html?noDefault=true&isMap=false", 20 "bug1260704_iframe.html?noDefault=false&isMap=true", 21 "bug1260704_iframe.html?noDefault=false&isMap=false" 22 ]; 23 24 let runningTest = false; 25 let iframe = document.getElementById("testFrame"); 26 let iframeWin = iframe.contentWindow; 27 let rect; 28 let x; 29 let y; 30 31 window.addEventListener("message", event => { 32 if (event.data == "started") { 33 ok(!runningTest, "Start to test " + testIdx); 34 runningTest = true; 35 rect = iframeWin.document.getElementById("testImage").getBoundingClientRect(); 36 x = rect.width / 2; 37 y = rect.height / 2; 38 synthesizeMouseAtPoint(rect.left + x, rect.top + y, { type: 'mousedown' }, iframeWin); 39 synthesizeMouseAtPoint(rect.left + x, rect.top + y, { type: 'mouseup' }, iframeWin); 40 } 41 else if (runningTest && event.data == "empty_frame_loaded") { 42 ok(testUrls[testIdx].includes("noDefault=false"), "Page unload"); 43 let search = iframeWin.location.search; 44 if (testUrls[testIdx].includes("isMap=true")) { 45 // url trigger by image with ismap attribute should contains coordinates 46 // try to parse coordinates and check them with small tolerance 47 let coorStr = search.split("?"); 48 let coordinates = coorStr[1].split(","); 49 ok(Math.abs(coordinates[0] - x) <= 1, "expect X=" + x + " got " + coordinates[0]); 50 ok(Math.abs(coordinates[1] - y) <= 1, "expect Y=" + y + " got " + coordinates[1]); 51 } else { 52 ok(search == "", "expect empty search string got:" + search); 53 } 54 nextTest(); 55 } 56 else if (runningTest && event.data == "finished") { 57 ok(testUrls[testIdx].includes("noDefault=true"), "Page should not leave"); 58 nextTest(); 59 } 60 }); 61 62 function nextTest() { 63 testIdx++; 64 runningTest = false; 65 if (testIdx >= testUrls.length) { 66 SimpleTest.finish(); 67 } else { 68 ok(true, "Test " + testIdx + " - Set url to " + testUrls[testIdx]); 69 iframeWin.location.href = testUrls[testIdx]; 70 } 71 } 72 nextTest(); 73 } 74 75 SimpleTest.waitForExplicitFinish(); 76 SimpleTest.waitForFocus(runTests); 77 78 </script> 79 </head> 80 <body> 81 82 <p id="display"></p> 83 <div id="content" style="display: none"> 84 </div> 85 <iframe id="testFrame" src="about:blank" width="400" height="400"> 86 </iframe> 87 <pre id="test"> 88 </pre> 89 </body> 90 </html>