1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description("This test checks that textareas have the right metrics. These numbers match IE7 except for scrollHeight. For two reasons:<br>" +
11 "1. scrollHeight is different for elements without enough content to cause scroll because IE7 then reports the height of the text inside the " +
12 "element as the scrollHeight. IE8 reports has scrollHeight == offsetHeight. Gecko/WebKit have scrollHeight == clientHeight.<br>" +
13 "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 " +
14 "currently mimic this quirk. It's not clear whether we should given that we agree with IE7's clientWidth numbers in all these cases.");
16 function assertTextareaMetrics(doc
, properties
, expectedMetrics
) {
17 var textarea
= doc
.createElement('textarea');
18 // Give some consistent CSS for consistent rendering across platforms
19 // and to help in reasoning when trying to match IE metrics.
20 var style
= 'overflow-y:auto; font-family:Ahem; line-height:20px; height:50px; width:50px;';
22 for (property
in properties
) {
23 var value
= properties
[property
];
24 title
+= ' ' + property
+ ': "' + value
+ '",';
25 if (property
== 'style')
28 textarea
[property
] = value
;
30 textarea
.style
.cssText
= style
;
31 doc
.body
.appendChild(textarea
);
33 // Create a more human-readable ID.
34 var id
= title
.replace(/[\'\",;\:]/g, ' ').replace(/ +/g
, '-');
35 id
= id
== '' ? 'no-styles' : id
;
38 window
[doc
.compatMode
+ 'doc'] = doc
;
40 function assertMetricsForTextarea() {
44 debug('Properties =' + title
);
45 shouldBe(doc
.compatMode
+ "doc.getElementById('" + id
+ "').clientWidth", String(expectedMetrics
.clientWidth
));
46 shouldBe(doc
.compatMode
+ "doc.getElementById('" + id
+ "').clientHeight", String(expectedMetrics
.clientHeight
));
47 shouldBe(doc
.compatMode
+ "doc.getElementById('" + id
+ "').offsetWidth", String(expectedMetrics
.offsetWidth
));
48 shouldBe(doc
.compatMode
+ "doc.getElementById('" + id
+ "').offsetHeight", String(expectedMetrics
.offsetHeight
));
49 shouldBe(doc
.compatMode
+ "doc.getElementById('" + id
+ "').scrollWidth", String(expectedMetrics
.scrollWidth
));
50 shouldBe(doc
.compatMode
+ "doc.getElementById('" + id
+ "').scrollHeight", String(expectedMetrics
.scrollHeight
));
54 // Give a timeout so IE has time to figure out it's metrics.
55 setTimeout(assertMetricsForTextarea
, 100);
57 assertMetricsForTextarea();
61 var htmlThatCausesScroll
= 'AAAAAAAAA';
63 function testTextareasForDocument(doc
, compatMode
,
64 textareaSizes
, textareaWithScrollSizes
,
65 textareaWith8pxPaddingSizes
, textareaWith8pxPaddingAndScrollbarSizes
) {
66 if (doc
.compatMode
!= compatMode
)
67 testFailed('This doc should be in ' + compatMode
+ ' mode.');
70 var scrollbarStyle
= doc
.createElement('style');
71 scrollbarStyle
.innerText
= 'textarea::-webkit-scrollbar{ width:17px }';
72 doc
.getElementsByTagName('head')[0].appendChild(scrollbarStyle
);
74 // IE throws an exception here, but doesn't need the above clause anyways.
77 debug('Testing ' + compatMode
+ ' document.')
78 assertTextareaMetrics(doc
, {}, textareaSizes
);
79 assertTextareaMetrics(doc
, {disabled
: true}, textareaSizes
);
80 assertTextareaMetrics(doc
, {innerHTML
: smallHTML
}, textareaSizes
);
81 assertTextareaMetrics(doc
, {innerHTML
: htmlThatCausesScroll
}, textareaWithScrollSizes
);
82 assertTextareaMetrics(doc
, {innerHTML
: smallHTML
, disabled
: true}, textareaSizes
);
83 assertTextareaMetrics(doc
, {innerHTML
: htmlThatCausesScroll
, disabled
: true}, textareaWithScrollSizes
);
84 assertTextareaMetrics(doc
, {innerHTML
: smallHTML
, style
: 'padding:8px'}, textareaWith8pxPaddingSizes
);
85 assertTextareaMetrics(doc
, {innerHTML
: htmlThatCausesScroll
, style
: 'padding:8px'}, textareaWith8pxPaddingAndScrollbarSizes
);
86 assertTextareaMetrics(doc
, {innerHTML
: smallHTML
, rows
: 10}, textareaSizes
);
87 assertTextareaMetrics(doc
, {innerHTML
: htmlThatCausesScroll
, rows
: 10}, textareaWithScrollSizes
);
90 // For textareas with scrollbars have the expected clientWidth be the
91 // expected offsetWidth - scrollbarPlusBorderWidth.
92 // default border on textareas is 1px solid. So, the border width is 2.
93 // And the scrollbarWidth we set to be 17 to match windows so that
94 // these numbers will be platform independent and match IE.
95 var scrollbarPlusBorderWidth
= 19;
97 var textareaSizesQuirks
= {clientWidth
: 48,
104 var textareaWithScrollSizesQuirks
= {clientWidth
: 50 - scrollbarPlusBorderWidth
,
108 scrollWidth
: 50 - scrollbarPlusBorderWidth
,
111 var textareaWith8pxPaddingSizesQuirks
= {clientWidth
: 48,
118 var textareaWith8pxPaddingAndScrollbarSizesQuirks
= {clientWidth
: 50 - scrollbarPlusBorderWidth
,
122 scrollWidth
: 50 - scrollbarPlusBorderWidth
,
125 testTextareasForDocument(document
, 'BackCompat',
126 textareaSizesQuirks
, textareaWithScrollSizesQuirks
,
127 textareaWith8pxPaddingSizesQuirks
, textareaWith8pxPaddingAndScrollbarSizesQuirks
);
129 var standardsIframe
= document
.createElement('iframe');
130 standardsIframe
.style
.width
= '100%';
131 document
.body
.appendChild(standardsIframe
);
132 standardsIframe
.contentWindow
.document
.write('<!DocType html><html><head></head><body></body></html>');
133 standardsIframe
.contentWindow
.document
.close();
135 var textareaSizesStandards
= {clientWidth
: 54,
142 var textareaWithScrollSizesStandards
= {clientWidth
: 56 - scrollbarPlusBorderWidth
,
146 scrollWidth
: 56 - scrollbarPlusBorderWidth
,
149 var textareaWith8pxPaddingSizesStandards
= {clientWidth
: 66,
156 var textareaWith8pxPaddingAndScrollbarSizesStandards
= {clientWidth
: 68 - scrollbarPlusBorderWidth
,
160 scrollWidth
: 68 - scrollbarPlusBorderWidth
,
163 testTextareasForDocument(standardsIframe
.contentWindow
.document
, 'CSS1Compat',
164 textareaSizesStandards
, textareaWithScrollSizesStandards
,
165 textareaWith8pxPaddingSizesStandards
, textareaWith8pxPaddingAndScrollbarSizesStandards
);