5 select, span { font: menu; }
7 <script src="../../../resources/js-test.js"></script>
11 Test that text directionality is taken into account when
14 <select id="dropdown">
15 <option dir="rtl">اب اب</option>
17 <select id="list" size="5">
18 <option dir="rtl">اب اب</option>
21 function widthForEmptySelect(size)
23 var selectElement = document.createElement('select');
24 selectElement.size = size;
25 document.body.appendChild(selectElement);
26 var selectWidth = selectElement.getBoundingClientRect().width;
27 document.body.removeChild(selectElement);
31 function widthForText(str)
33 var textElement = document.createElement('span');
34 textElement.appendChild(document.createTextNode(str));
35 document.body.appendChild(textElement);
36 var textWidth = textElement.getBoundingClientRect().width;
37 document.body.removeChild(textElement);
41 var optionPaddingStart = 3;
42 var optionPaddingEnd = 2;
44 function testListbox(id)
46 var element = document.getElementById(id);
47 var emptyWidth = widthForEmptySelect(element.size);
48 var textWidth = widthForText(element.firstElementChild.textContent);
49 var dropdownWidth = element.getBoundingClientRect().width;
50 var expectedWidth = emptyWidth + textWidth + optionPaddingStart + optionPaddingEnd;
51 if (Math.abs(dropdownWidth - expectedWidth) <= 1)
52 testPassed('Width of ' + id + ' matches width of text plus width of empty ' + id + '.');
54 testFailed('Width ' + id + ' was ' + dropdownWidth + 'px wide, expected ' + expectedWidth + 'px (' + emptyWidth + 'px for empty ' + id + ' and ' + textWidth + 'px for text).');