gecko-dev/toolkit/components/satchel/test/test_bug_787624.html

185 lines
4.4 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Layout of Form History Autocomplete: Bug 787624</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style>
.container {
border: 1px solid #333;
width: 80px;
height: 26px;
position: absolute;
z-index: 2;
}
.subcontainer {
width: 100%;
overflow: hidden;
}
.subcontainer input {
width: 120px;
margin: 2px 6px;
padding-right: 4px;
border: none;
height: 22px;
z-index: 1;
outline: 1px dashed #555
}
</style>
</head>
<body>
Form History Layout test: form field autocomplete: Bug 787624
<p id="display"></p>
<!-- we presumably can't hide the content for this test. -->
<div id="content" style="direction: rtl;">
<!-- unused -->
<form id="unused" onsubmit="return false;">
<input type="text" name="field1" value="unused">
</form>
<!-- normal, basic form -->
<div class="container">
<div class="subcontainer">
<form id="form1" onsubmit="return false;">
<input type="text" name="field1">
<button type="submit">Submit</button>
</form>
</div>
</div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Form History autocomplete Layout: Bug 787624 **/
var autocompletePopup = getAutocompletePopup();
autocompletePopup.style.direction = "ltr";
var input = $_(1, "field1");
var rect = input.getBoundingClientRect();
// Get the form history service
function setupFormHistory() {
updateFormHistory([
{ op : "remove" },
{ op : "add", fieldname : "field1", value : "value1" },
{ op : "add", fieldname : "field1", value : "value2" },
], function() runTest(1));
}
function checkForm(expectedValue) {
var formID = input.parentNode.id;
if (input.value != expectedValue)
return false;
is(input.value, expectedValue, "Checking " + formID + " input");
return true;
}
function checkPopupOpen(isOpen, expectedIndex) {
var actuallyOpen = autocompletePopup.popupOpen;
var actualIndex = autocompletePopup.selectedIndex;
if (actuallyOpen != isOpen)
return false;
is(actuallyOpen, isOpen, "popup should be " + (isOpen ? "open" : "closed"));
if (isOpen) {
if (actualIndex != expectedIndex)
return false;
is(actualIndex, expectedIndex, "checking selected index");
}
return true;
}
function runTest(testNum) {
ok(true, "Starting test #" + testNum);
var retry = false;
var formOK, popupOK;
switch(testNum) {
//
// Check initial state
//
case 1:
input.value = "";
formOK = checkForm("");
if (!formOK) {
retry = true;
break;
}
is(autocompletePopup.popupOpen, false, "popup should be initially closed");
break;
// try a focus()
case 2:
input.focus();
break;
case 3:
popupOK = checkPopupOpen(false);
formOK = checkForm("");
if (!formOK || !popupOK)
retry = true;
break;
// try a click()
case 4:
input.click();
break;
case 5:
popupOK = checkPopupOpen(false);
formOK = checkForm("");
if (!formOK || !popupOK)
retry = true;
break;
case 6:
// We're privileged for this test, so open the popup.
popupOK = checkPopupOpen(false);
formOK = checkForm("");
if (!formOK || !popupOK)
retry = true;
doKey("down");
break;
case 7:
popupOK = checkPopupOpen(true, -1);
formOK = checkForm("");
if (!formOK || !popupOK)
retry = true;
break;
case 8:
var newRect = input.getBoundingClientRect();
is(newRect.left, rect.left,
"autocomplete popup does not disturb the input position");
is(newRect.top, rect.top,
"autocomplete popup does not disturb the input position");
SimpleTest.finish();
return;
default:
ok(false, "Unexpected invocation of test #" + testNum);
SimpleTest.finish();
return;
}
if (!retry)
testNum++;
setTimeout(runTest, 0, testNum);
}
function startTest() {
setupFormHistory();
}
window.onload = startTest;
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>