2 return document.getElementById(id);
5 function createFormControlDataSet() {
6 // A list of labelable elements resides in http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#category-label
7 var formControlClassNames = [
10 'HTMLFieldSetElement',
17 'HTMLOptGroupElement',
20 'HTMLProgressElement',
24 var formControlDataSet = {};
25 for (var i = 0; i < formControlClassNames.length; i++) {
26 var className = formControlClassNames[i];
27 var tagName = className.toLowerCase().substring(4, className.length - 7);
28 var element = document.createElement(tagName);
29 formControlDataSet[tagName] = {
32 isSupported: element.toString() == '[object ' + className + ']',
37 formControlDataSet.datalist.isLabelable = false;
38 formControlDataSet.fieldset.isLabelable = false;
39 formControlDataSet.label.isLabelable = false;
40 formControlDataSet.legend.isLabelable = false;
41 formControlDataSet.object.isLabelable = false;
42 formControlDataSet.optgroup.isLabelable = false;
43 formControlDataSet.option.isLabelable = false;
45 // Input type names reside in http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html
46 var inputTypeNames = [
71 for (var i = 0; i < inputTypeNames.length; i++) {
72 var typeName = inputTypeNames[i];
73 var name = typeName + 'Type';
74 var element = document.createElement('input');
75 element.type = typeName;
76 formControlDataSet[name] = {
79 isSupported: element.type == typeName,
84 formControlDataSet.hiddenType.isLabelable = false;
86 return formControlDataSet;
89 function getAbsoluteRect(element) {
90 var rect = element.getBoundingClientRect();
91 rect.top += document.scrollingElement.scrollTop;
92 rect.bottom += document.scrollingElement.scrollTop;
93 rect.left += document.scrollingElement.scrollLeft;
94 rect.right += document.scrollingElement.scrollLeft;
98 function searchCancelButtonPosition(element) {
100 pos.x = element.offsetLeft + element.offsetWidth - 9;
101 pos.y = element.offsetTop + element.offsetHeight / 2;
105 function mouseMoveToIndexInListbox(index, listboxId) {
106 var listbox = document.getElementById(listboxId);
107 var itemHeight = Math.floor(listbox.offsetHeight / listbox.size);
109 var y = border + index * itemHeight;
110 if (window.eventSender)
111 eventSender.mouseMoveTo(listbox.offsetLeft + border, listbox.offsetTop + y - window.pageYOffset);
114 function getUserAgentShadowTextContent(element) {
115 return internals.youngestShadowRoot(element).textContent;
118 function cumulativeOffset(element) {
121 var parentFrame = element.ownerDocument.defaultView.frameElement;
123 var parentFrameOffset = cumulativeOffset(parentFrame);
124 x = parentFrameOffset[0];
125 y = parentFrameOffset[1];
127 if (element.parentNode) {
129 x += element.offsetLeft || 0;
130 y += element.offsetTop || 0;
131 element = element.offsetParent;
137 function elementCenterPosition(element) {
138 var offset = cumulativeOffset(element);
139 var centerX = offset[0] + element.offsetWidth / 2;
140 var centerY = offset[1] + element.offsetHeight / 2;
141 return [centerX, centerY];
144 function hoverOverElement(element) {
145 var center = elementCenterPosition(element);
146 eventSender.mouseMoveTo(center[0], center[1]);
149 function clickElement(element) {
150 hoverOverElement(element);
151 eventSender.mouseDown();
152 eventSender.mouseUp();
155 function traverseNextNode(node, stayWithin) {
156 var nextNode = node.firstChild;
160 if (stayWithin && node === stayWithin)
163 nextNode = node.nextSibling;
168 while (nextNode && !nextNode.nextSibling && (!stayWithin || !nextNode.parentNode || nextNode.parentNode !== stayWithin))
169 nextNode = nextNode.parentNode;
173 return nextNode.nextSibling;
176 function getElementByPseudoId(root, pseudoId) {
177 if (!window.internals)
181 if (node.nodeType === Node.ELEMENT_NODE && internals.shadowPseudoId(node) === pseudoId)
183 node = traverseNextNode(node, root);
188 function doneLater() {
189 setTimeout(function() {
190 testRunner.notifyDone();
194 function waitUntilLoadedAndAutofocused(callback) {
196 var autofocused = false;
197 // Use doneLater() because some rendering tests need repaint after focus.
198 callback = callback || doneLater;
199 // Does both of waitUntilDone and jsTestIsAsync because we want to support
200 // tests with/without js-test.js.
201 testRunner.waitUntilDone();
202 window.jsTestIsAsync = true;
203 window.addEventListener('load', function() {
208 document.addEventListener('focusin', function() {
209 if (internals.hasAutofocusRequest(document))