58e456c4b92c80399f16dbabb0f291e656ea68ca
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / PerformanceTests / Layout / resources / floats.js
1 (function() {
2     function createElement(tag, parent, className, id) {
3         var el = document.createElement(tag);
4         el.className = className;
5         if (id)
6             el.id = id;
7         parent.appendChild(el);
8         return el;
9     }
10
11     function createSet(width, height, nested) {
12         var container = createElement("div", document.body, "container");
13         for (var y = 0; y < height; ++y) {
14             for (var x = 0; x < width; ++x)
15                 createElement("div", container, "float", "float" + x + "_" + y);
16
17             var nestedContainer = container;
18             for ( ; nested > 0; --nested)
19                 nestedContainer = createElement("div", nestedContainer, "nested", "nested" + x + "_" + nested);
20             
21             createElement("div", container, "float-end", "end" + x)
22         }
23         return container;
24     }
25
26     function toggle(str, str1, str2) {
27         return str == str1 ? str2 : str1;
28     }
29     
30     function resetTest() {
31         PerfTestRunner.resetRandomSeed();
32         var list = document.querySelectorAll(".float.big");
33         for (var i = 0; i < list.length; ++i)
34             list[i].className = "float";
35     }
36     
37     function createTestFunction(width, height, nested, runs, rows) {
38         var containers = [];
39         for (var i = 0; i < rows; ++i)
40             containers[i] = createSet(width, height, nested);
41         nested = nested || 0;
42         runs = runs || 10;
43         return function() {
44             for (var c = 0; c < rows; ++c) {
45                 container = containers[c];
46                 container.style.display = "block";
47                 for (var i = 0; i < runs; ++i) {
48                     var x = Math.floor(Math.random() * width);
49                     var y = Math.floor(Math.random() * height);
50                     var el = document.getElementById("float" + x + "_" + y);
51                     el.className = toggle(el.className, "float", "float big");
52                     // Force a layout.
53                     container.clientHeight;
54                 }
55                 resetTest();
56                 container.style.display = "none";
57             }
58         }
59     }
60     
61     window.createFloatsLayoutTestFunction = createTestFunction;
62 })();