michael@0: var popup; michael@0: michael@0: function OpenWindow() michael@0: { michael@0: log({},">>> OpenWindow"); michael@0: popup = window.open("","Test"); michael@0: michael@0: var output = ""; michael@0: michael@0: output+=""; michael@0: output+="
" michael@0: output+=""; michael@0: output+="
" michael@0: output+=""; michael@0: output+=""; michael@0: michael@0: popup.document.open(); michael@0: popup.document.write(output); michael@0: popup.document.close(); michael@0: michael@0: popup.document.onclick=function (event) { log(event,"popup-doc") }; michael@0: popup.document.onfocus=function (event) { log(event,"popup-doc") }; michael@0: popup.document.onblur=function (event) { log(event,"popup-doc") }; michael@0: popup.document.onchange=function (event) { log(event,"popup-doc") }; michael@0: michael@0: var e = popup.document.getElementById('popupText1'); michael@0: popup.focus(); michael@0: e.focus(); michael@0: is(popup.document.activeElement, e, "input element in popup should be focused"); michael@0: log({},"<<< OpenWindow"); michael@0: } michael@0: michael@0: var result; michael@0: michael@0: function log(event,message) { michael@0: if (event&&event.eventPhase==3) return; michael@0: e = event.currentTarget||event.target||event.srcElement; michael@0: var id = e?(e.id?e.id:e.name?e.name:e.value?e.value:''):''; michael@0: if (id) id = '(' + id + ')'; michael@0: result += michael@0: (e?(e.tagName?e.tagName:''):' ')+id+': '+ michael@0: (event.type?event.type:'')+' '+ michael@0: (message?message:'') + '\n'; michael@0: } michael@0: michael@0: document.onclick=function (event) { log(event,"top-doc") }; michael@0: document.onfocus=function (event) { log(event,"top-doc") }; michael@0: document.onblur=function (event) { log(event,"top-doc") }; michael@0: document.onchange=function (event) { log(event,"top-doc") }; michael@0: michael@0: function doTest1_rest2(expectedEventLog,focusAfterCloseId) { michael@0: try { michael@0: is(document.activeElement, document.getElementById(focusAfterCloseId), "wrong element is focused after popup was closed"); michael@0: is(result, expectedEventLog, "unexpected events"); michael@0: SimpleTest.finish(); michael@0: } catch(e) { michael@0: if (popup) michael@0: popup.close(); michael@0: throw e; michael@0: } michael@0: } michael@0: function doTest1_rest1(expectedEventLog,focusAfterCloseId) { michael@0: try { michael@0: synthesizeKey("V", {}, popup); michael@0: synthesizeKey("A", {}, popup); michael@0: synthesizeKey("L", {}, popup); michael@0: is(popup.document.getElementById('popupText1').value, "VAL", "input element in popup did not accept input"); michael@0: michael@0: var p = popup; michael@0: popup = null; michael@0: p.close(); michael@0: michael@0: SimpleTest.waitForFocus(function () { doTest1_rest2(expectedEventLog,focusAfterCloseId); }, window); michael@0: } catch(e) { michael@0: if (popup) michael@0: popup.close(); michael@0: throw e; michael@0: } michael@0: } michael@0: michael@0: function doTest1(expectedEventLog,focusAfterCloseId) { michael@0: try { michael@0: var select1 = document.getElementById('Select1'); michael@0: select1.focus(); michael@0: is(document.activeElement, select1, "select element should be focused"); michael@0: synthesizeKey("VK_DOWN",{}); michael@0: synthesizeKey("VK_TAB", {}); michael@0: SimpleTest.waitForFocus(function () { doTest1_rest1(expectedEventLog,focusAfterCloseId); }, popup); michael@0: michael@0: } catch(e) { michael@0: if (popup) michael@0: popup.close(); michael@0: throw e; michael@0: } michael@0: } michael@0: michael@0: function setPrefAndDoTest(expectedEventLog,focusAfterCloseId,prefValue) { michael@0: var origPrefValue = SpecialPowers.getIntPref("browser.link.open_newwindow"); michael@0: var select1 = document.getElementById('Select1'); michael@0: select1.blur(); michael@0: result = ""; michael@0: log({},"Test with browser.link.open_newwindow = "+prefValue); michael@0: try { michael@0: SpecialPowers.setIntPref("browser.link.open_newwindow", prefValue); michael@0: doTest1(expectedEventLog,focusAfterCloseId); michael@0: } finally { michael@0: SpecialPowers.setIntPref("browser.link.open_newwindow", origPrefValue); michael@0: } michael@0: }