toolkit/components/satchel/test/test_bug_787624.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for Layout of Form History Autocomplete: Bug 787624</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 7 <script type="text/javascript" src="satchel_common.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 <style>
michael@0 10 .container {
michael@0 11 border: 1px solid #333;
michael@0 12 width: 80px;
michael@0 13 height: 26px;
michael@0 14 position: absolute;
michael@0 15 z-index: 2;
michael@0 16 }
michael@0 17
michael@0 18 .subcontainer {
michael@0 19 width: 100%;
michael@0 20 overflow: hidden;
michael@0 21 }
michael@0 22
michael@0 23 .subcontainer input {
michael@0 24 width: 120px;
michael@0 25 margin: 2px 6px;
michael@0 26 padding-right: 4px;
michael@0 27 border: none;
michael@0 28 height: 22px;
michael@0 29 z-index: 1;
michael@0 30 outline: 1px dashed #555
michael@0 31 }
michael@0 32 </style>
michael@0 33 </head>
michael@0 34 <body>
michael@0 35 Form History Layout test: form field autocomplete: Bug 787624
michael@0 36 <p id="display"></p>
michael@0 37
michael@0 38 <!-- we presumably can't hide the content for this test. -->
michael@0 39 <div id="content" style="direction: rtl;">
michael@0 40 <!-- unused -->
michael@0 41 <form id="unused" onsubmit="return false;">
michael@0 42 <input type="text" name="field1" value="unused">
michael@0 43 </form>
michael@0 44
michael@0 45 <!-- normal, basic form -->
michael@0 46 <div class="container">
michael@0 47 <div class="subcontainer">
michael@0 48 <form id="form1" onsubmit="return false;">
michael@0 49 <input type="text" name="field1">
michael@0 50 <button type="submit">Submit</button>
michael@0 51 </form>
michael@0 52 </div>
michael@0 53 </div>
michael@0 54 </div>
michael@0 55
michael@0 56 <pre id="test">
michael@0 57 <script class="testbody" type="text/javascript">
michael@0 58
michael@0 59 /** Test for Form History autocomplete Layout: Bug 787624 **/
michael@0 60
michael@0 61 var autocompletePopup = getAutocompletePopup();
michael@0 62 autocompletePopup.style.direction = "ltr";
michael@0 63
michael@0 64 var input = $_(1, "field1");
michael@0 65 var rect = input.getBoundingClientRect();
michael@0 66
michael@0 67 // Get the form history service
michael@0 68 function setupFormHistory() {
michael@0 69 updateFormHistory([
michael@0 70 { op : "remove" },
michael@0 71 { op : "add", fieldname : "field1", value : "value1" },
michael@0 72 { op : "add", fieldname : "field1", value : "value2" },
michael@0 73 ], function() runTest(1));
michael@0 74 }
michael@0 75
michael@0 76 function checkForm(expectedValue) {
michael@0 77 var formID = input.parentNode.id;
michael@0 78 if (input.value != expectedValue)
michael@0 79 return false;
michael@0 80
michael@0 81 is(input.value, expectedValue, "Checking " + formID + " input");
michael@0 82 return true;
michael@0 83 }
michael@0 84
michael@0 85 function checkPopupOpen(isOpen, expectedIndex) {
michael@0 86 var actuallyOpen = autocompletePopup.popupOpen;
michael@0 87 var actualIndex = autocompletePopup.selectedIndex;
michael@0 88 if (actuallyOpen != isOpen)
michael@0 89 return false;
michael@0 90
michael@0 91 is(actuallyOpen, isOpen, "popup should be " + (isOpen ? "open" : "closed"));
michael@0 92 if (isOpen) {
michael@0 93 if (actualIndex != expectedIndex)
michael@0 94 return false;
michael@0 95 is(actualIndex, expectedIndex, "checking selected index");
michael@0 96 }
michael@0 97 return true;
michael@0 98 }
michael@0 99
michael@0 100 function runTest(testNum) {
michael@0 101 ok(true, "Starting test #" + testNum);
michael@0 102 var retry = false;
michael@0 103 var formOK, popupOK;
michael@0 104
michael@0 105 switch(testNum) {
michael@0 106 //
michael@0 107 // Check initial state
michael@0 108 //
michael@0 109 case 1:
michael@0 110 input.value = "";
michael@0 111 formOK = checkForm("");
michael@0 112 if (!formOK) {
michael@0 113 retry = true;
michael@0 114 break;
michael@0 115 }
michael@0 116 is(autocompletePopup.popupOpen, false, "popup should be initially closed");
michael@0 117 break;
michael@0 118
michael@0 119 // try a focus()
michael@0 120 case 2:
michael@0 121 input.focus();
michael@0 122 break;
michael@0 123 case 3:
michael@0 124 popupOK = checkPopupOpen(false);
michael@0 125 formOK = checkForm("");
michael@0 126 if (!formOK || !popupOK)
michael@0 127 retry = true;
michael@0 128 break;
michael@0 129 // try a click()
michael@0 130 case 4:
michael@0 131 input.click();
michael@0 132 break;
michael@0 133 case 5:
michael@0 134 popupOK = checkPopupOpen(false);
michael@0 135 formOK = checkForm("");
michael@0 136 if (!formOK || !popupOK)
michael@0 137 retry = true;
michael@0 138 break;
michael@0 139 case 6:
michael@0 140 // We're privileged for this test, so open the popup.
michael@0 141 popupOK = checkPopupOpen(false);
michael@0 142 formOK = checkForm("");
michael@0 143 if (!formOK || !popupOK)
michael@0 144 retry = true;
michael@0 145 doKey("down");
michael@0 146 break;
michael@0 147 case 7:
michael@0 148 popupOK = checkPopupOpen(true, -1);
michael@0 149 formOK = checkForm("");
michael@0 150 if (!formOK || !popupOK)
michael@0 151 retry = true;
michael@0 152 break;
michael@0 153 case 8:
michael@0 154 var newRect = input.getBoundingClientRect();
michael@0 155 is(newRect.left, rect.left,
michael@0 156 "autocomplete popup does not disturb the input position");
michael@0 157 is(newRect.top, rect.top,
michael@0 158 "autocomplete popup does not disturb the input position");
michael@0 159 SimpleTest.finish();
michael@0 160 return;
michael@0 161
michael@0 162 default:
michael@0 163 ok(false, "Unexpected invocation of test #" + testNum);
michael@0 164 SimpleTest.finish();
michael@0 165 return;
michael@0 166 }
michael@0 167
michael@0 168 if (!retry)
michael@0 169 testNum++;
michael@0 170
michael@0 171 setTimeout(runTest, 0, testNum);
michael@0 172 }
michael@0 173
michael@0 174 function startTest() {
michael@0 175 setupFormHistory();
michael@0 176 }
michael@0 177
michael@0 178 window.onload = startTest;
michael@0 179
michael@0 180 SimpleTest.waitForExplicitFinish();
michael@0 181 </script>
michael@0 182 </pre>
michael@0 183 </body>
michael@0 184 </html>

mercurial