1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import time 6 7from telemetry.internal.actions import page_action 8 9import py_utils 10 11 12class RepaintContinuouslyAction(page_action.PageAction): 13 """Continuously repaints the visible content by requesting animation frames 14 until self.seconds have elapsed AND at least three RAFs have been fired. Times 15 out after max(60, self.seconds), if less than three RAFs were fired. 16 """ 17 18 def __init__(self, seconds): 19 super(RepaintContinuouslyAction, self).__init__() 20 self._seconds = seconds 21 22 def RunAction(self, tab): 23 tab.ExecuteJavaScript( 24 'window.__rafCount = 0;' 25 'window.__rafFunction = function() {' 26 'window.__rafCount += 1;' 27 'window.webkitRequestAnimationFrame(window.__rafFunction);' 28 '};' 29 'window.webkitRequestAnimationFrame(window.__rafFunction);') 30 31 # Wait until at least self.seconds have elapsed AND min_rafs have been 32 # fired. Use a hard time-out after 60 seconds (or self.seconds). 33 time.sleep(self._seconds) 34 def HasMinRafs(): 35 return tab.EvaluateJavaScript('window.__rafCount;') >= 3 36 py_utils.WaitFor(HasMinRafs, max(60 - self._seconds, 0)) 37