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.page.actions import page_action 8 9class RepaintContinuouslyAction(page_action.PageAction): 10 """ Continuously repaints the visible content by requesting animation frames 11 until self.seconds have elapsed AND at least three RAFs have been fired. Times 12 out after max(60, self.seconds), if less than three RAFs were fired. 13 """ 14 def __init__(self, attributes=None): 15 super(RepaintContinuouslyAction, self).__init__(attributes) 16 17 def RunAction(self, tab): 18 assert(hasattr(self, 'seconds')) 19 start_time = time.time() 20 tab.ExecuteJavaScript( 21 'window.__rafCount = 0;' 22 'window.__rafFunction = function() {' 23 'window.__rafCount += 1;' 24 'window.webkitRequestAnimationFrame(window.__rafFunction);' 25 '};' 26 'window.webkitRequestAnimationFrame(window.__rafFunction);') 27 28 time_out = max(60, self.seconds) 29 min_rafs = 3 30 31 # Wait until al leat self.seconds have elapsed AND min_rafs have been fired. 32 # Use a hard time-out after 60 seconds (or self.seconds). 33 while True: 34 raf_count = tab.EvaluateJavaScript('window.__rafCount;') 35 elapsed_time = time.time() - start_time 36 if elapsed_time > time_out: 37 break 38 elif elapsed_time > self.seconds and raf_count > min_rafs: 39 break 40 time.sleep(1) 41