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