// CanvasRunner is a wrapper of PerformanceTests/resources/runner.js for canvas tests.
(function () {
    var MEASURE_DRAW_TIMES = 50;
    var MAX_MEASURE_DRAW_TIMES = 1000;
    var MAX_MEASURE_TIME_PER_FRAME = 1000; // 1 sec
    var currentTest = null;
    var isTestDone = false;

    var CanvasRunner = {};

    CanvasRunner.start = function (test) {
        PerfTestRunner.prepareToMeasureValuesAsync({unit: 'runs/s',
            description: test.description, done: testDone});
        if (!test.doRun) {
            CanvasRunner.logFatalError("\ndoRun must be set.\n");
            return;
        }
        currentTest = test;
        runTest();
    }

    function runTest() {
        try {
            if (currentTest.preRun)
                currentTest.preRun();

            var start = PerfTestRunner.now();
            var count = 0;
            while ((PerfTestRunner.now() - start <= MAX_MEASURE_TIME_PER_FRAME) && (count * MEASURE_DRAW_TIMES < MAX_MEASURE_DRAW_TIMES)) {
                for (var i = 0; i < MEASURE_DRAW_TIMES; i++) {
                    currentTest.doRun();
                }
                count++;
            }
            if (currentTest.ensureComplete)
                currentTest.ensureComplete();
            var elapsedTime = PerfTestRunner.now() - start;
            if (currentTest.postRun)
                currentTest.postRun();

            PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * count * 1000 / elapsedTime);
        } catch(err) {
            CanvasRunner.logFatalError("\ntest fails due to GPU issue. " + err + "\n");
            return;
        }

        if (!isTestDone)
            requestAnimationFrame(runTest);
    }

    function testDone() {
        isTestDone = true;
    }

    CanvasRunner.logFatalError = function (text) {
        PerfTestRunner.logFatalError(text);
    }

    window.CanvasRunner = CanvasRunner;
})();

@@ -250,36 +250,8 @@
 ull;
-%0A    var isTestDone = false;
 %0A%0A  
@@ -432,24 +432,8 @@
 tion
-, done: testDone
 %7D);%0A
@@ -638,26 +638,8 @@
 ) %7B%0A
-        try %7B%0A    
     
@@ -670,36 +670,32 @@
 un)%0A            
-  
-  
 currentTest.preR
@@ -693,36 +693,32 @@
 Test.preRun();%0A%0A
-    
         var star
@@ -739,28 +739,24 @@
 nner.now();%0A
-    
         var 
@@ -774,20 +774,16 @@
         
-    
 while ((
@@ -914,20 +914,16 @@
         
-    
 for (var
@@ -969,36 +969,32 @@
                 
- 
-   
 currentTest.doRu
@@ -1006,33 +1006,26 @@
             
-    %7D%0A   
+%7D%0A
             
@@ -1024,17 +1024,16 @@
         
- 
 count++;
@@ -1037,34 +1037,26 @@
 ++;%0A        
-    %7D%0A    
+%7D%0A
         if (
@@ -1087,36 +1087,32 @@
 te)%0A            
-    
 currentTest.ensu
@@ -1121,28 +1121,24 @@
 Complete();%0A
-    
         var 
@@ -1185,28 +1185,24 @@
 rt;%0A        
-  
-  
 if (currentT
@@ -1218,36 +1218,32 @@
 un)%0A            
-    
 currentTest.post
@@ -1254,28 +1254,24 @@
 );%0A%0A        
-   
- 
 PerfTestRunn
@@ -1345,277 +1345,47 @@
 e);%0A
-        %7D catch(err) %7B%0A            CanvasRunner.logFatalError(%22%5Cntest fails due to GPU issue. %22 + err + %22%5Cn%22);%0A            return;%0A        %7D%0A%0A        if (!isTestDone)%0A            requestAnimationFrame(runTest);%0A    %7D%0A%0A    function testDone() %7B%0A        isTestDone = true
+%0A        requestAnimationFrame(runTest)
 ;%0A  

Revert of Fix blink_perf.canvas test very flaky on Nexus One perf bot. (patchset #3 id:40001 of https://codereview.chromium.org/1123693003/)