Test for bug 299673.

This commit is contained in:
Mats Palmgren 2009-06-13 01:11:55 +02:00
parent aa354453bd
commit ec3e79fa2e
2 changed files with 174 additions and 0 deletions

View File

@ -47,6 +47,7 @@ include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_bug238987.html \
test_bug288392.html \
test_bug299673.html \
test_bug328885.html \
test_bug336682_1.html \
test_bug336682_2.xul \

View File

@ -0,0 +1,173 @@
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=299673
-->
<head>
<title>Test for Bug 299673</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body id="Body">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=299673">Mozilla Bug 299673</a>
<p id="display">
<SELECT id="Select1" onchange="log(event); OpenWindow()" onfocus="log(event); " onblur="log(event)">
<OPTION selected>option1</OPTION>
<OPTION>option2</OPTION>
<OPTION>option3</OPTION>
</SELECT>
<INPUT id="Text1" type="text" onfocus="log(event)" onblur="log(event)">
<INPUT id="Text2" type="text" onfocus="log(event)" onblur="log(event)">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 299673 **/
var popup;
function OpenWindow()
{
log({},">>> OpenWindow");
popup = window.open("","Test");
var output = "<html>";
output+="<body>";
output+="<form>"
output+="<input id='popupText1' type='text' onfocus='opener.log(event)' onblur='opener.log(event)'>";
output+="</form>"
output+="</body>";
output+="</html>";
popup.document.open();
popup.document.write(output);
popup.document.close();
popup.document.onclick=function (event) { log(event,"popup-doc") };
popup.document.onfocus=function (event) { log(event,"popup-doc") };
popup.document.onblur=function (event) { log(event,"popup-doc") };
popup.document.onchange=function (event) { log(event,"popup-doc") };
var e = popup.document.getElementById('popupText1');
popup.focus();
e.focus();
is(popup.document.activeElement, e, "input element in popup should be focused");
log({},"<<< OpenWindow");
}
var result;
function log(event,message) {
if (event&&event.eventPhase==3) return;
e = event.currentTarget||event.target||event.srcElement;
var id = e?(e.id?e.id:e.name?e.name:e.value?e.value:''):'';
if (id) id = '(' + id + ')';
result +=
(e?(e.tagName?e.tagName:''):' ')+id+': '+
(event.type?event.type:'')+' '+
(message?message:'') + '\n';
}
document.onclick=function (event) { log(event,"top-doc") };
document.onfocus=function (event) { log(event,"top-doc") };
document.onblur=function (event) { log(event,"top-doc") };
document.onchange=function (event) { log(event,"top-doc") };
function doTest1(expectedEventLog,focusAfterCloseId) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
try {
var select1 = document.getElementById('Select1');
select1.focus();
is(document.activeElement, select1, "select element should be focused");
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
synthesizeKey("VK_DOWN",{});
synthesizeKey("VK_TAB", {});
synthesizeKey("V", {}, popup);
synthesizeKey("A", {}, popup);
synthesizeKey("L", {}, popup);
is(popup.document.getElementById('popupText1').value, "VAL", "input element in popup did not accept input");
var p = popup;
popup = null;
p.close();
is(document.activeElement, document.getElementById(focusAfterCloseId), "wrong element is focused after popup was closed");
is(result, expectedEventLog, "unexpected events");
} catch(e) {
if (popup)
popup.close();
throw e;
}
}
function setPrefAndDoTest(expectedEventLog,focusAfterCloseId,prefValue) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var origPrefValue = prefs.getIntPref("browser.link.open_newwindow");
var select1 = document.getElementById('Select1');
select1.blur();
result = "";
log({},"Test with browser.link.open_newwindow = "+prefValue);
try {
prefs.setIntPref("browser.link.open_newwindow", prefValue);
doTest1(expectedEventLog,focusAfterCloseId);
} finally {
prefs.setIntPref("browser.link.open_newwindow", origPrefValue);
}
}
function doTest(expectedEventLog) {
var eventLogForNewTab = '\
: Test with browser.link.open_newwindow = 3\n\
: focus top-doc\n\
SELECT(Select1): focus \n\
SELECT(Select1): change \n\
: >>> OpenWindow\n\
: blur top-doc\n\
INPUT(popupText1): focus \n\
: <<< OpenWindow\n\
SELECT(Select1): blur \n\
INPUT(popupText1): blur \n\
: blur popup-doc\n\
: focus top-doc\n\
'
setPrefAndDoTest(eventLogForNewTab,'Body',3); // 3 = open new window as tab
var eventLogForNewWindow = '\
: Test with browser.link.open_newwindow = 2\n\
SELECT(Select1): focus \n\
SELECT(Select1): change \n\
: >>> OpenWindow\n\
: blur top-doc\n\
: focus popup-doc\n\
INPUT(popupText1): focus \n\
: <<< OpenWindow\n\
SELECT(Select1): blur \n\
'
setPrefAndDoTest(eventLogForNewWindow,'Body',2); // 2 = open new window as window
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</pre>
</body>
</html>