1 description("This test checks that textareas have the right metrics. These numbers match IE7 except for scrollHeight. For two reasons:<br>" +
2 "1. scrollHeight is different for elements without enough content to cause scroll because IE7 then reports the height of the text inside the " +
3 "element as the scrollHeight. IE8 reports has scrollHeight == offsetHeight. Gecko/WebKit have scrollHeight == clientHeight.<br>" +
4 "2. For the elements with scroll in standards-mode, IE wraps the text differently. It seems to leave 2px less space for the text. We don't " +
5 "currently mimic this quirk. It's not clear whether we should given that we agree with IE7's clientWidth numbers in all these cases.");
7 function assertTextareaMetrics(doc, properties, expectedMetrics) {
8 var textarea = doc.createElement('textarea');
9 // Give some consistent CSS for consistent rendering across platforms
10 // and to help in reasoning when trying to match IE metrics.
11 var style = 'overflow-y:auto; font-family:Ahem; line-height:20px; height:50px; width:50px;';
13 for (property in properties) {
14 var value = properties[property];
15 title += ' ' + property + ': "' + value + '",';
16 if (property == 'style')
19 textarea[property] = value;
21 textarea.style.cssText = style;
22 doc.body.appendChild(textarea);
24 // Create a more human-readable ID.
25 var id = title.replace(/[\'\",;\:]/g, ' ').replace(/ +/g, '-');
26 id = id == '' ? 'no-styles' : id;
29 window[doc.compatMode + 'doc'] = doc;
31 function assertMetricsForTextarea() {
35 debug('Properties =' + title);
36 shouldBe(doc.compatMode + "doc.getElementById('" + id + "').clientWidth", String(expectedMetrics.clientWidth));
37 shouldBe(doc.compatMode + "doc.getElementById('" + id + "').clientHeight", String(expectedMetrics.clientHeight));
38 shouldBe(doc.compatMode + "doc.getElementById('" + id + "').offsetWidth", String(expectedMetrics.offsetWidth));
39 shouldBe(doc.compatMode + "doc.getElementById('" + id + "').offsetHeight", String(expectedMetrics.offsetHeight));
40 shouldBe(doc.compatMode + "doc.getElementById('" + id + "').scrollWidth", String(expectedMetrics.scrollWidth));
41 shouldBe(doc.compatMode + "doc.getElementById('" + id + "').scrollHeight", String(expectedMetrics.scrollHeight));
45 // Give a timeout so IE has time to figure out it's metrics.
46 setTimeout(assertMetricsForTextarea, 100);
48 assertMetricsForTextarea();
52 var htmlThatCausesScroll = 'AAAAAAAAA';
54 function testTextareasForDocument(doc, compatMode,
55 textareaSizes, textareaWithScrollSizes,
56 textareaWith8pxPaddingSizes, textareaWith8pxPaddingAndScrollbarSizes) {
57 if (doc.compatMode != compatMode)
58 testFailed('This doc should be in ' + compatMode + ' mode.');
61 var scrollbarStyle = doc.createElement('style');
62 scrollbarStyle.innerText = 'textarea::-webkit-scrollbar{ width:17px }';
63 doc.getElementsByTagName('head')[0].appendChild(scrollbarStyle);
65 // IE throws an exception here, but doesn't need the above clause anyways.
68 debug('Testing ' + compatMode + ' document.')
69 assertTextareaMetrics(doc, {}, textareaSizes);
70 assertTextareaMetrics(doc, {disabled: true}, textareaSizes);
71 assertTextareaMetrics(doc, {innerHTML: smallHTML}, textareaSizes);
72 assertTextareaMetrics(doc, {innerHTML: htmlThatCausesScroll}, textareaWithScrollSizes);
73 assertTextareaMetrics(doc, {innerHTML: smallHTML, disabled: true}, textareaSizes);
74 assertTextareaMetrics(doc, {innerHTML: htmlThatCausesScroll, disabled: true}, textareaWithScrollSizes);
75 assertTextareaMetrics(doc, {innerHTML: smallHTML, style: 'padding:8px'}, textareaWith8pxPaddingSizes);
76 assertTextareaMetrics(doc, {innerHTML: htmlThatCausesScroll, style: 'padding:8px'}, textareaWith8pxPaddingAndScrollbarSizes);
77 assertTextareaMetrics(doc, {innerHTML: smallHTML, rows: 10}, textareaSizes);
78 assertTextareaMetrics(doc, {innerHTML: htmlThatCausesScroll, rows: 10}, textareaWithScrollSizes);
81 // For textareas with scrollbars have the expected clientWidth be the
82 // expected offsetWidth - scrollbarPlusBorderWidth.
83 // default border on textareas is 1px solid. So, the border width is 2.
84 // And the scrollbarWidth we set to be 17 to match windows so that
85 // these numbers will be platform independent and match IE.
86 var scrollbarPlusBorderWidth = 19;
88 var textareaSizesQuirks = {clientWidth: 48,
95 var textareaWithScrollSizesQuirks = {clientWidth: 50 - scrollbarPlusBorderWidth,
99 scrollWidth: 50 - scrollbarPlusBorderWidth,
102 var textareaWith8pxPaddingSizesQuirks = {clientWidth: 48,
109 var textareaWith8pxPaddingAndScrollbarSizesQuirks = {clientWidth: 50 - scrollbarPlusBorderWidth,
113 scrollWidth: 50 - scrollbarPlusBorderWidth,
116 testTextareasForDocument(document, 'BackCompat',
117 textareaSizesQuirks, textareaWithScrollSizesQuirks,
118 textareaWith8pxPaddingSizesQuirks, textareaWith8pxPaddingAndScrollbarSizesQuirks);
120 var standardsIframe = document.createElement('iframe');
121 standardsIframe.style.width = '100%';
122 document.body.appendChild(standardsIframe);
123 standardsIframe.contentWindow.document.write('<!DocType html><html><head></head><body></body></html>');
124 standardsIframe.contentWindow.document.close();
126 var textareaSizesStandards = {clientWidth: 54,
133 var textareaWithScrollSizesStandards = {clientWidth: 56 - scrollbarPlusBorderWidth,
137 scrollWidth: 56 - scrollbarPlusBorderWidth,
140 var textareaWith8pxPaddingSizesStandards = {clientWidth: 66,
147 var textareaWith8pxPaddingAndScrollbarSizesStandards = {clientWidth: 68 - scrollbarPlusBorderWidth,
151 scrollWidth: 68 - scrollbarPlusBorderWidth,
154 testTextareasForDocument(standardsIframe.contentWindow.document, 'CSS1Compat',
155 textareaSizesStandards, textareaWithScrollSizesStandards,
156 textareaWith8pxPaddingSizesStandards, textareaWith8pxPaddingAndScrollbarSizesStandards);