Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=331959 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 331959</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=331959">Mozilla Bug 331959</a> |
michael@0 | 14 | <p id="display"> |
michael@0 | 15 | <iframe id="link-in-link-mouse"></iframe> |
michael@0 | 16 | <iframe id="link-in-link-keyboard"></iframe> |
michael@0 | 17 | <iframe id="input-in-link-mouse"></iframe> |
michael@0 | 18 | <iframe id="input-in-link-keyboard"></iframe> |
michael@0 | 19 | <iframe id="button-in-link-mouse"></iframe> |
michael@0 | 20 | <iframe id="button-in-link-keyboard"></iframe> |
michael@0 | 21 | </p> |
michael@0 | 22 | <div id="content" style="display: none"> |
michael@0 | 23 | |
michael@0 | 24 | </div> |
michael@0 | 25 | <pre id="test"> |
michael@0 | 26 | <script type="application/javascript"> |
michael@0 | 27 | |
michael@0 | 28 | /** Test for Bug 331959 **/ |
michael@0 | 29 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 30 | |
michael@0 | 31 | const FAILURL = "data:text/plain,FAIL"; |
michael@0 | 32 | const PASSURL = "data:text/plain,PASS"; |
michael@0 | 33 | |
michael@0 | 34 | var currentTest = 0; |
michael@0 | 35 | var tests = [ testLinkInLinkMouse, testLinkInLinkKeyboard, |
michael@0 | 36 | testInputInLinkMouse, testInputInLinkKeyboard, |
michael@0 | 37 | testButtonInLinkMouse, testButtonInLinkKeyboard ]; |
michael@0 | 38 | function doNextTest() { |
michael@0 | 39 | if (currentTest == tests.length) { |
michael@0 | 40 | SimpleTest.finish(); |
michael@0 | 41 | } else { |
michael@0 | 42 | tests[currentTest++](); |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function generateLinkInLink(id, desc) { |
michael@0 | 47 | var doc = $(id).contentDocument; |
michael@0 | 48 | var outerA = doc.createElement("a"); |
michael@0 | 49 | var innerA = doc.createElement("a"); |
michael@0 | 50 | outerA.id = "outer"; |
michael@0 | 51 | innerA.id = "inner"; |
michael@0 | 52 | innerA.href = PASSURL; |
michael@0 | 53 | outerA.href = FAILURL; |
michael@0 | 54 | innerA.appendChild(doc.createTextNode("Text")); |
michael@0 | 55 | outerA.appendChild(innerA); |
michael@0 | 56 | doc.body.appendChild(outerA); |
michael@0 | 57 | $(id).onload = function() { |
michael@0 | 58 | is(this.contentDocument.documentElement.textContent, "PASS", desc); |
michael@0 | 59 | // Have to remove the iframe we used from the DOM, because the harness is |
michael@0 | 60 | // stupid and doesn't have enough space for more than one iframe. |
michael@0 | 61 | $(id).parentNode.removeChild($(id)); |
michael@0 | 62 | doNextTest(); |
michael@0 | 63 | }; |
michael@0 | 64 | return [innerA, $(id).contentWindow]; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function testLinkInLinkMouse() { |
michael@0 | 68 | var [innerA, testWin] = |
michael@0 | 69 | generateLinkInLink("link-in-link-mouse", |
michael@0 | 70 | "Clicking an inner link should load the inner link"); |
michael@0 | 71 | synthesizeMouseAtCenter(innerA, {}, testWin); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function testLinkInLinkKeyboard() { |
michael@0 | 75 | var [innerA, testWin] = |
michael@0 | 76 | generateLinkInLink("link-in-link-keyboard", |
michael@0 | 77 | "Hitting enter on an inner link should load the inner link"); |
michael@0 | 78 | innerA.focus(); |
michael@0 | 79 | synthesizeKey("VK_RETURN", {}, testWin); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function generateInputInLink(id, desc) { |
michael@0 | 83 | var doc = $(id).contentDocument; |
michael@0 | 84 | doc.body.innerHTML = |
michael@0 | 85 | "<form action='" + PASSURL + "'><a href='" + FAILURL + |
michael@0 | 86 | "'><input type='submit' id='submit'>"; |
michael@0 | 87 | $(id).onload = function() { |
michael@0 | 88 | is(this.contentDocument.documentElement.textContent, "PASS?", desc); |
michael@0 | 89 | // Have to remove the iframe we used from the DOM, because the harness is |
michael@0 | 90 | // stupid and doesn't have enough space for more than one iframe. |
michael@0 | 91 | $(id).parentNode.removeChild($(id)); |
michael@0 | 92 | doNextTest(); |
michael@0 | 93 | }; |
michael@0 | 94 | var input = doc.getElementById("submit"); |
michael@0 | 95 | doc.body.offsetWidth; |
michael@0 | 96 | return [input, $(id).contentWindow]; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function testInputInLinkMouse() { |
michael@0 | 100 | var [input, testWin] = |
michael@0 | 101 | generateInputInLink("input-in-link-mouse", |
michael@0 | 102 | "Clicking an submit input inside an anchor should submit the form"); |
michael@0 | 103 | synthesizeMouseAtCenter(input, {}, testWin); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | function testInputInLinkKeyboard() { |
michael@0 | 107 | var [input, testWin] = |
michael@0 | 108 | generateInputInLink("input-in-link-keyboard", |
michael@0 | 109 | "Return on submit input inside an anchor should submit the form"); |
michael@0 | 110 | input.focus(); |
michael@0 | 111 | synthesizeKey("VK_RETURN", {}, testWin); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function generateButtonInLink(id, desc) { |
michael@0 | 115 | var doc = $(id).contentDocument; |
michael@0 | 116 | doc.body.innerHTML = |
michael@0 | 117 | "<form action='" + PASSURL + "'><a href='" + FAILURL + |
michael@0 | 118 | "'><button type='submit' id='submit'>Submit</button>"; |
michael@0 | 119 | $(id).onload = function() { |
michael@0 | 120 | is(this.contentDocument.documentElement.textContent, "PASS?", desc); |
michael@0 | 121 | // Have to remove the iframe we used from the DOM, because the harness is |
michael@0 | 122 | // stupid and doesn't have enough space for more than one iframe. |
michael@0 | 123 | $(id).parentNode.removeChild($(id)); |
michael@0 | 124 | doNextTest(); |
michael@0 | 125 | }; |
michael@0 | 126 | var button = doc.getElementById("submit"); |
michael@0 | 127 | return [button, $(id).contentWindow]; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function testButtonInLinkMouse() { |
michael@0 | 131 | var [button, testWin] = |
michael@0 | 132 | generateButtonInLink("button-in-link-mouse", |
michael@0 | 133 | "Clicking an submit button inside an anchor should submit the form"); |
michael@0 | 134 | synthesizeMouseAtCenter(button, {}, testWin); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | function testButtonInLinkKeyboard() { |
michael@0 | 138 | var [button, testWin] = |
michael@0 | 139 | generateButtonInLink("button-in-link-keyboard", |
michael@0 | 140 | "Return on submit button inside an anchor should submit the form"); |
michael@0 | 141 | button.focus(); |
michael@0 | 142 | synthesizeKey("VK_RETURN", {}, testWin); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | // We need focus to handle clicks properly |
michael@0 | 146 | SimpleTest.waitForFocus(doNextTest); |
michael@0 | 147 | |
michael@0 | 148 | </script> |
michael@0 | 149 | </pre> |
michael@0 | 150 | </body> |
michael@0 | 151 | </html> |