[CSS Shapes] Add initial performance test for shape-outside: content-box
[WebKit-https.git] / PerformanceTests / Layout / Shapes / ShapeOutsideContentBox.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <link rel="stylesheet" href="resources/shapes.css" type="text/css"></link>
5         <script src="../../resources/runner.js"></script>
6         <script>
7             var templateParagraph = null;
8             var templateFloatingNode = null;
9             var DEFAULT_SHAPE_OBJECT_COUNT = 100;
10
11             function createParagraphNode() {
12                 if (!templateParagraph) {
13                     templateParagraph = document.createElement("p");
14                     templateParagraph.innerHTML = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at turpis placerat sapien congue viverra nec sed felis.\
15                         Aenean aliquam, justo eu condimentum pharetra, arcu eros blandit metus, nec lacinia nisi orci vitae nunc.\
16                         Proin orci libero, accumsan non dignissim at, sodales in sapien. Curabitur dui nibh, venenatis vel tempus vel, accumsan nec velit.\
17                         Nam sit amet tempor lacus. Sed mollis dolor nibh, non tempus leo. Donec magna odio, commodo id porta in, aliquam mollis eros.\
18                         Pellentesque vulputate gravida ligula in elementum. Fusce lacinia massa justo, at porttitor orci.\
19                         Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec odio quam, pulvinar ut porttitor ac, tempor vitae ligula.\
20                         Cras aliquet sapien id sapien mollis nec pulvinar mauris adipiscing. Praesent porttitor consequat augue, sit amet mollis justo condimentum eu.\
21                         Etiam ut erat pellentesque orci congue interdum. Nulla eu eros mi.\
22                         Curabitur rutrum, lorem ac malesuada pellentesque, sapien risus consequat massa, eget pellentesque nunc nulla vel sem.";
23                         templateParagraph.className = "contentParagraph";
24                 }
25
26                 var paragraph = templateParagraph.cloneNode(true);
27                 return paragraph;
28             }
29
30             function createFloatingNode(width, height, shape) {
31                 if (!templateFloatingNode) {
32                     templateFloatingNode = document.createElement("div");
33                     templateFloatingNode.className = "floatingObject";
34                 }
35
36                 var float = templateFloatingNode.cloneNode(false);
37                 float.style.width = width;
38                 float.style.height = height;
39                 float.style.webkitShapeOutside = shape;
40                 return float;
41             }
42
43             function addArticles(floatingObjects, paragraphCount) {
44                 for (var i = 0; i < paragraphCount; ++i) {
45                     floatingObjects.appendChild(createParagraphNode());
46                 }
47             }
48
49             function createFloatingObjects(width, height, shape, floatingObjectCount) {
50                 var testBox = document.createElement("div");
51                 for (var i = 0; i < floatingObjectCount; ++i) {
52                     testBox.appendChild(createFloatingNode(width, height, shape));
53                     testBox.appendChild(createParagraphNode())
54                 }
55                 testBox.className = "testBox";
56                 return testBox;
57             }
58
59             function applyFloating() {
60                 var floatingObjects = document.getElementsByClassName('floatingObject');
61                 for (i = 0; i < floatingObjects.length; ++i) {
62                     floatingObjects[i].style.cssFloat = 'left';
63                 }
64             }
65
66             function createShapeOutsideTest(width, height, shape, shapeObjectCount) {
67                 shapeObjectCount = shapeObjectCount || DEFAULT_SHAPE_OBJECT_COUNT;
68
69                 var floatingObjects = createFloatingObjects(width, height, shape, shapeObjectCount);
70                 document.body.appendChild(floatingObjects);
71                 return {
72                     description: "Testing shapes with " + shape +" using " + shapeObjectCount + " shapes.",
73                     run: function() {
74                         applyFloating();
75                         document.body.offsetTop;
76                     },
77                     setup: function() {
78                         PerfTestRunner.resetRandomSeed();
79                         document.body.offsetTop;
80                     },
81                     done: function() {
82                         document.body.removeChild(floatingObjects);
83                         templateParagraph = null;
84                     }
85                 };
86             }
87         </script>
88     </head>
89     <body>
90         <pre id="log"></pre>
91         <script>
92             var shape = "content-box";
93             PerfTestRunner.measureTime(createShapeOutsideTest("200px", "200px", shape, 1000));
94         </script>
95     </body>
96 </html>