1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug331959.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,151 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=331959 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 331959</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=331959">Mozilla Bug 331959</a> 1.17 +<p id="display"> 1.18 + <iframe id="link-in-link-mouse"></iframe> 1.19 + <iframe id="link-in-link-keyboard"></iframe> 1.20 + <iframe id="input-in-link-mouse"></iframe> 1.21 + <iframe id="input-in-link-keyboard"></iframe> 1.22 + <iframe id="button-in-link-mouse"></iframe> 1.23 + <iframe id="button-in-link-keyboard"></iframe> 1.24 +</p> 1.25 +<div id="content" style="display: none"> 1.26 + 1.27 +</div> 1.28 +<pre id="test"> 1.29 +<script type="application/javascript"> 1.30 + 1.31 +/** Test for Bug 331959 **/ 1.32 +SimpleTest.waitForExplicitFinish(); 1.33 + 1.34 +const FAILURL = "data:text/plain,FAIL"; 1.35 +const PASSURL = "data:text/plain,PASS"; 1.36 + 1.37 +var currentTest = 0; 1.38 +var tests = [ testLinkInLinkMouse, testLinkInLinkKeyboard, 1.39 + testInputInLinkMouse, testInputInLinkKeyboard, 1.40 + testButtonInLinkMouse, testButtonInLinkKeyboard ]; 1.41 +function doNextTest() { 1.42 + if (currentTest == tests.length) { 1.43 + SimpleTest.finish(); 1.44 + } else { 1.45 + tests[currentTest++](); 1.46 + } 1.47 +} 1.48 + 1.49 +function generateLinkInLink(id, desc) { 1.50 + var doc = $(id).contentDocument; 1.51 + var outerA = doc.createElement("a"); 1.52 + var innerA = doc.createElement("a"); 1.53 + outerA.id = "outer"; 1.54 + innerA.id = "inner"; 1.55 + innerA.href = PASSURL; 1.56 + outerA.href = FAILURL; 1.57 + innerA.appendChild(doc.createTextNode("Text")); 1.58 + outerA.appendChild(innerA); 1.59 + doc.body.appendChild(outerA); 1.60 + $(id).onload = function() { 1.61 + is(this.contentDocument.documentElement.textContent, "PASS", desc); 1.62 + // Have to remove the iframe we used from the DOM, because the harness is 1.63 + // stupid and doesn't have enough space for more than one iframe. 1.64 + $(id).parentNode.removeChild($(id)); 1.65 + doNextTest(); 1.66 + }; 1.67 + return [innerA, $(id).contentWindow]; 1.68 +} 1.69 + 1.70 +function testLinkInLinkMouse() { 1.71 + var [innerA, testWin] = 1.72 + generateLinkInLink("link-in-link-mouse", 1.73 + "Clicking an inner link should load the inner link"); 1.74 + synthesizeMouseAtCenter(innerA, {}, testWin); 1.75 +} 1.76 + 1.77 +function testLinkInLinkKeyboard() { 1.78 + var [innerA, testWin] = 1.79 + generateLinkInLink("link-in-link-keyboard", 1.80 + "Hitting enter on an inner link should load the inner link"); 1.81 + innerA.focus(); 1.82 + synthesizeKey("VK_RETURN", {}, testWin); 1.83 +} 1.84 + 1.85 +function generateInputInLink(id, desc) { 1.86 + var doc = $(id).contentDocument; 1.87 + doc.body.innerHTML = 1.88 + "<form action='" + PASSURL + "'><a href='" + FAILURL + 1.89 + "'><input type='submit' id='submit'>"; 1.90 + $(id).onload = function() { 1.91 + is(this.contentDocument.documentElement.textContent, "PASS?", desc); 1.92 + // Have to remove the iframe we used from the DOM, because the harness is 1.93 + // stupid and doesn't have enough space for more than one iframe. 1.94 + $(id).parentNode.removeChild($(id)); 1.95 + doNextTest(); 1.96 + }; 1.97 + var input = doc.getElementById("submit"); 1.98 + doc.body.offsetWidth; 1.99 + return [input, $(id).contentWindow]; 1.100 +} 1.101 + 1.102 +function testInputInLinkMouse() { 1.103 + var [input, testWin] = 1.104 + generateInputInLink("input-in-link-mouse", 1.105 + "Clicking an submit input inside an anchor should submit the form"); 1.106 + synthesizeMouseAtCenter(input, {}, testWin); 1.107 +} 1.108 + 1.109 +function testInputInLinkKeyboard() { 1.110 + var [input, testWin] = 1.111 + generateInputInLink("input-in-link-keyboard", 1.112 + "Return on submit input inside an anchor should submit the form"); 1.113 + input.focus(); 1.114 + synthesizeKey("VK_RETURN", {}, testWin); 1.115 +} 1.116 + 1.117 +function generateButtonInLink(id, desc) { 1.118 + var doc = $(id).contentDocument; 1.119 + doc.body.innerHTML = 1.120 + "<form action='" + PASSURL + "'><a href='" + FAILURL + 1.121 + "'><button type='submit' id='submit'>Submit</button>"; 1.122 + $(id).onload = function() { 1.123 + is(this.contentDocument.documentElement.textContent, "PASS?", desc); 1.124 + // Have to remove the iframe we used from the DOM, because the harness is 1.125 + // stupid and doesn't have enough space for more than one iframe. 1.126 + $(id).parentNode.removeChild($(id)); 1.127 + doNextTest(); 1.128 + }; 1.129 + var button = doc.getElementById("submit"); 1.130 + return [button, $(id).contentWindow]; 1.131 +} 1.132 + 1.133 +function testButtonInLinkMouse() { 1.134 + var [button, testWin] = 1.135 + generateButtonInLink("button-in-link-mouse", 1.136 + "Clicking an submit button inside an anchor should submit the form"); 1.137 + synthesizeMouseAtCenter(button, {}, testWin); 1.138 +} 1.139 + 1.140 +function testButtonInLinkKeyboard() { 1.141 + var [button, testWin] = 1.142 + generateButtonInLink("button-in-link-keyboard", 1.143 + "Return on submit button inside an anchor should submit the form"); 1.144 + button.focus(); 1.145 + synthesizeKey("VK_RETURN", {}, testWin); 1.146 +} 1.147 + 1.148 +// We need focus to handle clicks properly 1.149 +SimpleTest.waitForFocus(doNextTest); 1.150 + 1.151 +</script> 1.152 +</pre> 1.153 +</body> 1.154 +</html>