1// Perf Tests run a maximum of 20 times,
2// make sure we have an equal amount of characters
3// for each run.
4var selectionSize = fallbackChars.length / 21;
5var target;
6
7function test() {
8    var charSelection = "";
9    for(var i=0; i < selectionSize; i++) {
10        var selectedCharIndex = Math.floor(Math.random() * fallbackChars.length);
11        if(!fallbackChars[selectedCharIndex])
12            continue;
13        charSelection += fallbackChars[selectedCharIndex];
14        fallbackChars.splice(selectedCharIndex, 1);
15    }
16    if (charSelection.length)
17        replaceTextAndWaitForLayout(charSelection);
18}
19
20function replaceTextAndWaitForLayout(charSelection) {
21    while (target.firstChild)
22        target.removeChild(target.firstChild);
23    target.appendChild(document.createTextNode(charSelection));
24    target.offsetHeight;
25}
26
27function cleanup() {
28    replaceTextAndWaitForLayout("");
29}
30
31function startTest() {
32    target = document.querySelector("#target");
33    PerfTestRunner.measureTime({ run: test, done: cleanup, description: "Per-character font fallback" });
34}
35