bug299673.js 3.1 KB

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