dom/events/test/bug299673.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/bug299673.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +var popup;
     1.5 +
     1.6 +function OpenWindow()
     1.7 +{
     1.8 +log({},">>> OpenWindow");
     1.9 +	popup = window.open("","Test");
    1.10 +
    1.11 +	var output = "<html>";
    1.12 +	
    1.13 +	output+="<body>";
    1.14 +	output+="<form>"
    1.15 +	output+="<input id='popupText1' type='text' onfocus='opener.log(event)' onblur='opener.log(event)'>";
    1.16 +	output+="</form>"
    1.17 +	output+="</body>";
    1.18 +	output+="</html>";
    1.19 +	
    1.20 +	popup.document.open();
    1.21 +	popup.document.write(output);
    1.22 +	popup.document.close();
    1.23 +
    1.24 +        popup.document.onclick=function (event) { log(event,"popup-doc") };
    1.25 +        popup.document.onfocus=function (event) { log(event,"popup-doc") };
    1.26 +        popup.document.onblur=function (event) { log(event,"popup-doc") };
    1.27 +        popup.document.onchange=function (event) { log(event,"popup-doc") };
    1.28 +
    1.29 +	var e = popup.document.getElementById('popupText1');
    1.30 +	popup.focus();
    1.31 +	e.focus();
    1.32 +        is(popup.document.activeElement, e, "input element in popup should be focused");
    1.33 +log({},"<<< OpenWindow");
    1.34 +}
    1.35 +
    1.36 +var result;
    1.37 +
    1.38 +function log(event,message) {
    1.39 +  if (event&&event.eventPhase==3) return;
    1.40 +  e = event.currentTarget||event.target||event.srcElement;
    1.41 +  var id = e?(e.id?e.id:e.name?e.name:e.value?e.value:''):'';
    1.42 +  if (id) id = '(' + id + ')';
    1.43 +  result +=
    1.44 +    (e?(e.tagName?e.tagName:''):' ')+id+': '+
    1.45 +    (event.type?event.type:'')+' '+
    1.46 +    (message?message:'') + '\n';
    1.47 +}
    1.48 +
    1.49 +document.onclick=function (event) { log(event,"top-doc") };
    1.50 +document.onfocus=function (event) { log(event,"top-doc") };
    1.51 +document.onblur=function (event) { log(event,"top-doc") };
    1.52 +document.onchange=function (event) { log(event,"top-doc") };
    1.53 +
    1.54 +function doTest1_rest2(expectedEventLog,focusAfterCloseId) {
    1.55 +  try {
    1.56 +    is(document.activeElement, document.getElementById(focusAfterCloseId), "wrong element is focused after popup was closed");
    1.57 +    is(result, expectedEventLog, "unexpected events");
    1.58 +    SimpleTest.finish();
    1.59 +  } catch(e) {
    1.60 +    if (popup)
    1.61 +      popup.close();
    1.62 +    throw e;
    1.63 +  }
    1.64 +}
    1.65 +function doTest1_rest1(expectedEventLog,focusAfterCloseId) {
    1.66 +  try {
    1.67 +    synthesizeKey("V", {}, popup);
    1.68 +    synthesizeKey("A", {}, popup);
    1.69 +    synthesizeKey("L", {}, popup);
    1.70 +    is(popup.document.getElementById('popupText1').value, "VAL", "input element in popup did not accept input");
    1.71 +
    1.72 +    var p = popup;
    1.73 +    popup = null;
    1.74 +    p.close();
    1.75 +
    1.76 +    SimpleTest.waitForFocus(function () { doTest1_rest2(expectedEventLog,focusAfterCloseId); }, window);
    1.77 +  } catch(e) {
    1.78 +    if (popup)
    1.79 +      popup.close();
    1.80 +    throw e;
    1.81 +  }
    1.82 +}
    1.83 +
    1.84 +function doTest1(expectedEventLog,focusAfterCloseId) {
    1.85 +  try {
    1.86 +    var select1 = document.getElementById('Select1');
    1.87 +    select1.focus();
    1.88 +    is(document.activeElement, select1, "select element should be focused");
    1.89 +    synthesizeKey("VK_DOWN",{});
    1.90 +    synthesizeKey("VK_TAB", {});
    1.91 +    SimpleTest.waitForFocus(function () { doTest1_rest1(expectedEventLog,focusAfterCloseId); }, popup);
    1.92 +
    1.93 +  } catch(e) {
    1.94 +    if (popup)
    1.95 +      popup.close();
    1.96 +    throw e;
    1.97 +  }
    1.98 +}
    1.99 +
   1.100 +function setPrefAndDoTest(expectedEventLog,focusAfterCloseId,prefValue) {
   1.101 +  var origPrefValue = SpecialPowers.getIntPref("browser.link.open_newwindow");
   1.102 +  var select1 = document.getElementById('Select1');
   1.103 +  select1.blur();
   1.104 +  result = "";
   1.105 +  log({},"Test with browser.link.open_newwindow = "+prefValue);
   1.106 +  try {
   1.107 +    SpecialPowers.setIntPref("browser.link.open_newwindow", prefValue);
   1.108 +    doTest1(expectedEventLog,focusAfterCloseId);
   1.109 +  } finally {
   1.110 +    SpecialPowers.setIntPref("browser.link.open_newwindow", origPrefValue);
   1.111 +  }
   1.112 +}

mercurial