Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / Element / getBoundingClientRect.html
1 <script src="../../../resources/js-test.js"></script>
2 <style>
3     body {
4         font: 16px Ahem;
5     }
6
7     #base {
8         width: 300px;
9         height: 100px;
10     }
11
12     #border {
13         border: 10px solid #999;
14         width: 300px;
15         height: 100px;
16     }
17
18     #margin {
19         margin: 10px;
20         width: 300px;
21         height: 100px;
22     }
23
24     #transform {
25         transform: translateX(50px) rotate(45deg);
26         width: 100px;
27         height: 100px;
28     }
29
30     #columns {
31         -webkit-column-count: 3;
32         width: 300px;
33     }
34
35     #inline {
36         display: inline;
37     }
38
39     #outer {
40         width: 100px;
41         height: 100px;
42     }
43
44     #inner {
45         width: 200px;
46         height: 200px;
47     }
48
49     table {
50         width: 300px;
51     }
52
53     img {
54         width: 100px;
55         height: 100px;
56     }
57
58     .testBox {
59         background-color: green;
60     }
61
62     #testArea {
63         width: 300px;
64     }
65
66     .bbox {
67         position: absolute;
68         outline: 5px solid rgba(255, 0, 0, .75);
69     }
70
71     #console {
72         position: absolute;
73         left: 500px;
74     }
75 </style>
76
77 <div id="console"></div>
78 <div id="testArea">
79
80 <p>1. Base</p>                  <div id="base" class="testBox"></div>
81 <p>2. Border</p>                <div id="border" class="testBox"></div>
82 <p>3. Margin</p>                <div id="margin" class="testBox"></div>
83 <p>4. Transform</p>             <div id="transform" class="testBox"></div>
84 <p>5. Column</p>                <div id="columns" class="testBox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
85 <p>6. In a column</p>           <div id="columns">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.<span id="in-columns" class="testBox knownFailure">In columns</span> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
86 <p>7. Inline</p>                <div id="inline" class="testBox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
87 <p>8. Table</p>                 <table class="testBox"><tr><td>table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
88 <p>9. Table with Caption</p>    <table class="testBox"><caption>caption</caption><tr><td>table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
89 <p>10. Table Row</p>            <table><tr class="testBox"><td>table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
90 <p>11. Table Cell</p>           <table><tr><td class="testBox">table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
91 <p>12. Big block in little</p>  <div id="outer" class="testBox"><div id="inner"></div></div>
92 <p>13. Replaced in inline</p>   <span class="testBox">Lorem<img>ipsum</span>
93 <p>14. Block in inline</p>      <span class="testBox">Lorem<div id="inner"></div>ipsum</span>
94 <p>15. Float in inline</p>      <span class="testBox"><img style="float:right"></span>
95
96 </div>
97
98 <script>
99     if (window.testRunner)
100         testRunner.dumpAsText();
101     else
102         alert("WARNING:\nThis test may show bogus FAILures if not run in DumpRenderTree, due to platform-specific differences in font metrics.");
103
104     function testClientRect(toTest, expectedRect)
105     {
106         rect = toTest;
107         shouldBeEqualToString("rect.left.toFixed(3)", expectedRect.left.toFixed(3));
108         shouldBeEqualToString("rect.top.toFixed(3)", expectedRect.top.toFixed(3));
109         shouldBeEqualToString("rect.width.toFixed(3)", expectedRect.width.toFixed(3));
110         shouldBeEqualToString("rect.height.toFixed(3)", expectedRect.height.toFixed(3));
111         shouldBe("rect.right", "rect.left + rect.width");
112         shouldBe("rect.bottom", "rect.top + rect.height");
113         debug("");
114     }
115
116     function addBBoxOverClientRect(rect)
117     {
118         var bbox = document.createElement('div');
119         bbox.className = "bbox";
120         var style = "";
121         style += "left: " + rect.left + "px;";
122         style += "top: " + rect.top + "px;";
123         style += "width: " + (rect.right - rect.left) + "px;";
124         style += "height: " + (rect.bottom - rect.top) + "px;";
125         bbox.setAttribute("style", style);
126         document.documentElement.appendChild(bbox);
127     }
128
129     var fail = undefined;
130
131     var expectedResults = [
132         /*1*/  { left: 8, top: 40, width: 300, height: 100 },
133         /*2*/  { left: 8, top: 188, width: 320, height: 120 },
134         /*3*/  { left: 18, top: 356, width: 300, height: 100 },
135         /*4*/  { left: 37.289, top: 483.289, width: 141.421, height: 141.421 },
136         /*5*/  { left: 8, top: 652, width: 300, height: 374 },
137         /*6*/  { left: fail, top: fail, width: fail, height: fail },
138         /*7*/  { left: 8, top: 1490, width: 288, height: 464 },
139         /*8*/  { left: 8, top: 2002, width: 300, height: 74 },
140         /*9*/  { left: 8, top: 2140, width: 300, height: 90 },
141         /*10*/ { left: 8, top: 2280, width: 300, height: 34 },
142         /*11*/ { left: 10, top: 2402, width: 147, height: 34 },
143         /*12*/ { left: 8, top: 2538, width: 100, height: 100 },
144         /*13*/ { left: 8, top: 2789, width: 260, height: 16 },
145         /*14*/ { left: 8, top: 2869, width: 300, height: 232 },
146         /*15*/ { left: 8, top: 3165, width: 0, height: 0 }
147     ];
148
149     function test(number, element)
150     {
151         debug("Test " + number);
152
153         if (element.className.match("knownFailure")) {
154             debug("Known failure. Skipping.");
155             debug("");
156             return;
157         }
158
159         var boundingRect = element.getBoundingClientRect();
160         addBBoxOverClientRect(boundingRect);
161         testClientRect(boundingRect, expectedResults[number - 1]);
162     }
163
164     var tests = document.getElementsByClassName("testBox");
165     for (var i = 0; i < tests.length; ++i)
166         test(i + 1, tests[i]);
167
168     if (window.testRunner) {
169         var area = document.getElementById('testArea');
170         area.parentNode.removeChild(area);
171     }
172 </script>