toolkit/components/satchel/test/test_bug_787624.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/satchel/test/test_bug_787624.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,184 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for Layout of Form History Autocomplete: Bug 787624</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <script type="text/javascript" src="satchel_common.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +  <style>
    1.13 +    .container {
    1.14 +        border: 1px solid #333;
    1.15 +        width: 80px;
    1.16 +        height: 26px;
    1.17 +        position: absolute;
    1.18 +        z-index: 2;
    1.19 +    }
    1.20 +
    1.21 +    .subcontainer {
    1.22 +        width: 100%;
    1.23 +        overflow: hidden;
    1.24 +    }
    1.25 +
    1.26 +    .subcontainer input {
    1.27 +        width: 120px;
    1.28 +        margin: 2px 6px;
    1.29 +        padding-right: 4px;
    1.30 +        border: none;
    1.31 +        height: 22px;
    1.32 +        z-index: 1;
    1.33 +        outline: 1px dashed #555
    1.34 +    }
    1.35 +  </style>
    1.36 +</head>
    1.37 +<body>
    1.38 +Form History Layout test: form field autocomplete: Bug 787624
    1.39 +<p id="display"></p>
    1.40 +
    1.41 +<!-- we presumably can't hide the content for this test. -->
    1.42 +<div id="content" style="direction: rtl;">
    1.43 +  <!-- unused -->
    1.44 +  <form id="unused" onsubmit="return false;">
    1.45 +    <input  type="text" name="field1" value="unused">
    1.46 +  </form>
    1.47 +
    1.48 +  <!-- normal, basic form -->
    1.49 +  <div class="container">
    1.50 +    <div class="subcontainer">
    1.51 +      <form id="form1" onsubmit="return false;">
    1.52 +        <input  type="text" name="field1">
    1.53 +        <button type="submit">Submit</button>
    1.54 +      </form>
    1.55 +    </div>
    1.56 +  </div>
    1.57 +</div>
    1.58 +
    1.59 +<pre id="test">
    1.60 +<script class="testbody" type="text/javascript">
    1.61 +
    1.62 +/** Test for Form History autocomplete Layout: Bug 787624 **/
    1.63 +
    1.64 +var autocompletePopup = getAutocompletePopup();
    1.65 +autocompletePopup.style.direction = "ltr";
    1.66 +
    1.67 +var input = $_(1, "field1");
    1.68 +var rect = input.getBoundingClientRect();
    1.69 +
    1.70 +// Get the form history service
    1.71 +function setupFormHistory() {
    1.72 +  updateFormHistory([
    1.73 +    { op : "remove" },
    1.74 +    { op : "add", fieldname : "field1", value : "value1" },
    1.75 +    { op : "add", fieldname : "field1", value : "value2" },
    1.76 +  ], function() runTest(1));
    1.77 +}
    1.78 +
    1.79 +function checkForm(expectedValue) {
    1.80 +  var formID = input.parentNode.id;
    1.81 +  if (input.value != expectedValue)
    1.82 +    return false;
    1.83 +
    1.84 +  is(input.value, expectedValue, "Checking " + formID + " input");
    1.85 +  return true;
    1.86 +}
    1.87 +
    1.88 +function checkPopupOpen(isOpen, expectedIndex) {
    1.89 +  var actuallyOpen = autocompletePopup.popupOpen;
    1.90 +  var actualIndex = autocompletePopup.selectedIndex;
    1.91 +  if (actuallyOpen != isOpen)
    1.92 +    return false;
    1.93 +
    1.94 +  is(actuallyOpen, isOpen, "popup should be " + (isOpen ? "open" : "closed"));
    1.95 +  if (isOpen) {
    1.96 +    if (actualIndex != expectedIndex)
    1.97 +      return false;
    1.98 +    is(actualIndex, expectedIndex, "checking selected index");
    1.99 +  }
   1.100 +  return true;
   1.101 +}
   1.102 +
   1.103 +function runTest(testNum) {
   1.104 +  ok(true, "Starting test #" + testNum);
   1.105 +  var retry = false;
   1.106 +  var formOK, popupOK;
   1.107 +
   1.108 +  switch(testNum) {
   1.109 +    //
   1.110 +    // Check initial state
   1.111 +    //
   1.112 +    case 1:
   1.113 +      input.value = "";
   1.114 +      formOK = checkForm("");
   1.115 +      if (!formOK) {
   1.116 +        retry = true;
   1.117 +        break;
   1.118 +      }
   1.119 +      is(autocompletePopup.popupOpen, false, "popup should be initially closed");
   1.120 +      break;
   1.121 +
   1.122 +    // try a focus()
   1.123 +    case 2:
   1.124 +      input.focus();
   1.125 +      break;
   1.126 +    case 3:
   1.127 +      popupOK = checkPopupOpen(false);
   1.128 +      formOK = checkForm("");
   1.129 +      if (!formOK || !popupOK)
   1.130 +        retry = true;
   1.131 +      break;
   1.132 +    // try a click()
   1.133 +    case 4:
   1.134 +      input.click();
   1.135 +      break;
   1.136 +    case 5:
   1.137 +      popupOK = checkPopupOpen(false);
   1.138 +      formOK = checkForm("");
   1.139 +      if (!formOK || !popupOK)
   1.140 +        retry = true;
   1.141 +      break;
   1.142 +    case 6:
   1.143 +      // We're privileged for this test, so open the popup.
   1.144 +      popupOK = checkPopupOpen(false);
   1.145 +      formOK = checkForm("");
   1.146 +      if (!formOK || !popupOK)
   1.147 +        retry = true;
   1.148 +      doKey("down");
   1.149 +      break;
   1.150 +    case 7:
   1.151 +      popupOK = checkPopupOpen(true, -1);
   1.152 +      formOK = checkForm("");
   1.153 +      if (!formOK || !popupOK)
   1.154 +        retry = true;
   1.155 +      break;
   1.156 +    case 8:
   1.157 +      var newRect = input.getBoundingClientRect();
   1.158 +      is(newRect.left, rect.left,
   1.159 +        "autocomplete popup does not disturb the input position");
   1.160 +      is(newRect.top, rect.top,
   1.161 +        "autocomplete popup does not disturb the input position");
   1.162 +      SimpleTest.finish();
   1.163 +      return;
   1.164 +
   1.165 +    default:
   1.166 +      ok(false, "Unexpected invocation of test #" + testNum);
   1.167 +      SimpleTest.finish();
   1.168 +      return;
   1.169 +  }
   1.170 +
   1.171 +  if (!retry)
   1.172 +    testNum++;
   1.173 +
   1.174 +  setTimeout(runTest, 0, testNum);
   1.175 +}
   1.176 +
   1.177 +function startTest() {
   1.178 +  setupFormHistory();
   1.179 +}
   1.180 +
   1.181 +window.onload = startTest;
   1.182 +
   1.183 +SimpleTest.waitForExplicitFinish();
   1.184 +</script>
   1.185 +</pre>
   1.186 +</body>
   1.187 +</html>

mercurial