6 Test that verifies the behavior of text-align:-webkit-match-parent.
10 The test passes if all the lines containing the text
"Left Align" are aligned to the left and vice-versa for
"Right Align".
13 <h4>Cases where the outermost div is LTR.
</h4>
14 <div style=
"text-align:start">
15 <div style=
"text-align:-webkit-match-parent" dir=rtl class=l
><span>Left Aligned
</span></div>
18 <div style=
"text-align:start" dir=ltr
>
19 <div style=
"text-align:-webkit-match-parent" dir=rtl class=l
><span>Left Aligned
</span></div>
22 <div style=
"text-align:end" dir=ltr
>
23 <div style=
"text-align:-webkit-match-parent" dir=rtl class=r
><span>Right Aligned
</span></div>
26 <h4>Cases where the outermost div is RTL.
</h4>
28 <div style=
"text-align:start" dir=rtl
>
29 <div style=
"text-align:-webkit-match-parent" dir=ltr class=r
><span>Right Aligned
</span></div>
32 <div style=
"text-align:end" dir=rtl
>
33 <div style=
"text-align:-webkit-match-parent" dir=ltr class=l
><span>Left Aligned
</span></div>
36 <h4>Changing text-align programmatically
</h4>
38 <div id=programmatic_change_div
style=
"text-align:end" dir=ltr
>
39 <div style=
"text-align:-webkit-match-parent" dir=rtl class=l
><span>Left Aligned
</span></div>
43 var top_div
= document
.getElementById('programmatic_change_div');
44 top_div
.style
.setProperty('text-align', 'start', 'important');
47 <h4>check -webkit-match-parent in a nested div
</h4>
49 <div style=
"text-align:end" dir=ltr
>
51 <div style=
"text-align:-webkit-match-parent" dir=rtl class=r
><span>Right Aligned
</span></div>
55 <div style=
"text-align:start" dir=ltr
>
56 <div style=
"text-align:-webkit-match-parent" dir=rtl
>
57 <div style=
"text-align:-webkit-match-parent" dir=rtl class=l
><span>Left Aligned
</span></div>
65 if (window
.testRunner
)
66 testRunner
.dumpAsText();
68 // Checks that the given element is left aligned if expectedAlignment is 'left', or right aligned if
69 // expectedAlignment is 'right'.
70 // Our check for right alignment is just !isLeftAligned at the moment, but this is
71 // enough for our purposes.
72 function assertAlignment(element
, i
, expectedAlignment
)
74 var enclosingDiv
= element
;
75 var computedStyle
= window
.getComputedStyle(enclosingDiv
, null);
76 var innerSpan
= enclosingDiv
.children
[0];
77 var leftAlign
= expectedAlignment
== 'left';
78 var isLeftAligned
= (enclosingDiv
.offsetLeft
== innerSpan
.offsetLeft
);
80 if (window
.testRunner
) {
81 if (leftAlign
&& isLeftAligned
&& computedStyle
.textAlign
== 'left')
82 innerSpan
.innerHTML
= 'PASS';
83 else if (!leftAlign
&& !isLeftAligned
&& computedStyle
.textAlign
== 'right')
84 innerSpan
.innerHTML
= 'PASS';
86 innerSpan
.innerHTML
= 'FAIL';
91 var leftAlignedDivs
= document
.querySelectorAll(".l");
92 for (var i
= 0; i
< leftAlignedDivs
.length
; i
++)
93 assertAlignment(leftAlignedDivs
[i
], i
, 'left');
95 var rightAlignedDivs
= document
.querySelectorAll(".r");
96 for (var i
= 0; i
< rightAlignedDivs
.length
; i
++)
97 assertAlignment(rightAlignedDivs
[i
], i
, 'right');