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