|
1 var popup; |
|
2 |
|
3 function OpenWindow() |
|
4 { |
|
5 log({},">>> OpenWindow"); |
|
6 popup = window.open("","Test"); |
|
7 |
|
8 var output = "<html>"; |
|
9 |
|
10 output+="<body>"; |
|
11 output+="<form>" |
|
12 output+="<input id='popupText1' type='text' onfocus='opener.log(event)' onblur='opener.log(event)'>"; |
|
13 output+="</form>" |
|
14 output+="</body>"; |
|
15 output+="</html>"; |
|
16 |
|
17 popup.document.open(); |
|
18 popup.document.write(output); |
|
19 popup.document.close(); |
|
20 |
|
21 popup.document.onclick=function (event) { log(event,"popup-doc") }; |
|
22 popup.document.onfocus=function (event) { log(event,"popup-doc") }; |
|
23 popup.document.onblur=function (event) { log(event,"popup-doc") }; |
|
24 popup.document.onchange=function (event) { log(event,"popup-doc") }; |
|
25 |
|
26 var e = popup.document.getElementById('popupText1'); |
|
27 popup.focus(); |
|
28 e.focus(); |
|
29 is(popup.document.activeElement, e, "input element in popup should be focused"); |
|
30 log({},"<<< OpenWindow"); |
|
31 } |
|
32 |
|
33 var result; |
|
34 |
|
35 function log(event,message) { |
|
36 if (event&&event.eventPhase==3) return; |
|
37 e = event.currentTarget||event.target||event.srcElement; |
|
38 var id = e?(e.id?e.id:e.name?e.name:e.value?e.value:''):''; |
|
39 if (id) id = '(' + id + ')'; |
|
40 result += |
|
41 (e?(e.tagName?e.tagName:''):' ')+id+': '+ |
|
42 (event.type?event.type:'')+' '+ |
|
43 (message?message:'') + '\n'; |
|
44 } |
|
45 |
|
46 document.onclick=function (event) { log(event,"top-doc") }; |
|
47 document.onfocus=function (event) { log(event,"top-doc") }; |
|
48 document.onblur=function (event) { log(event,"top-doc") }; |
|
49 document.onchange=function (event) { log(event,"top-doc") }; |
|
50 |
|
51 function doTest1_rest2(expectedEventLog,focusAfterCloseId) { |
|
52 try { |
|
53 is(document.activeElement, document.getElementById(focusAfterCloseId), "wrong element is focused after popup was closed"); |
|
54 is(result, expectedEventLog, "unexpected events"); |
|
55 SimpleTest.finish(); |
|
56 } catch(e) { |
|
57 if (popup) |
|
58 popup.close(); |
|
59 throw e; |
|
60 } |
|
61 } |
|
62 function doTest1_rest1(expectedEventLog,focusAfterCloseId) { |
|
63 try { |
|
64 synthesizeKey("V", {}, popup); |
|
65 synthesizeKey("A", {}, popup); |
|
66 synthesizeKey("L", {}, popup); |
|
67 is(popup.document.getElementById('popupText1').value, "VAL", "input element in popup did not accept input"); |
|
68 |
|
69 var p = popup; |
|
70 popup = null; |
|
71 p.close(); |
|
72 |
|
73 SimpleTest.waitForFocus(function () { doTest1_rest2(expectedEventLog,focusAfterCloseId); }, window); |
|
74 } catch(e) { |
|
75 if (popup) |
|
76 popup.close(); |
|
77 throw e; |
|
78 } |
|
79 } |
|
80 |
|
81 function doTest1(expectedEventLog,focusAfterCloseId) { |
|
82 try { |
|
83 var select1 = document.getElementById('Select1'); |
|
84 select1.focus(); |
|
85 is(document.activeElement, select1, "select element should be focused"); |
|
86 synthesizeKey("VK_DOWN",{}); |
|
87 synthesizeKey("VK_TAB", {}); |
|
88 SimpleTest.waitForFocus(function () { doTest1_rest1(expectedEventLog,focusAfterCloseId); }, popup); |
|
89 |
|
90 } catch(e) { |
|
91 if (popup) |
|
92 popup.close(); |
|
93 throw e; |
|
94 } |
|
95 } |
|
96 |
|
97 function setPrefAndDoTest(expectedEventLog,focusAfterCloseId,prefValue) { |
|
98 var origPrefValue = SpecialPowers.getIntPref("browser.link.open_newwindow"); |
|
99 var select1 = document.getElementById('Select1'); |
|
100 select1.blur(); |
|
101 result = ""; |
|
102 log({},"Test with browser.link.open_newwindow = "+prefValue); |
|
103 try { |
|
104 SpecialPowers.setIntPref("browser.link.open_newwindow", prefValue); |
|
105 doTest1(expectedEventLog,focusAfterCloseId); |
|
106 } finally { |
|
107 SpecialPowers.setIntPref("browser.link.open_newwindow", origPrefValue); |
|
108 } |
|
109 } |