Home | History | Annotate | Download | only in resources
      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) {
     38         var container = createSet(width, height, nested);
     39         nested = nested || 0;
     40         runs = runs || 10;
     41         return function() {
     42             container.style.display = "block";
     43             for (var i = 0; i < runs; ++i) {
     44                 var x = Math.floor(Math.random() * width);
     45                 var y = Math.floor(Math.random() * height);
     46                 var el = document.getElementById("float" + x + "_" + y);
     47                 el.className = toggle(el.className, "float", "float big");
     48                 // Force a layout.
     49                 container.clientHeight;
     50             }
     51             resetTest();
     52             container.style.display = "none";
     53         }
     54     }
     55     
     56     window.createFloatsLayoutTestFunction = createTestFunction;
     57 })();
     58