Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / repaint_continuously.py
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
5 import time
6
7 from telemetry.page.actions import page_action
8
9 class 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, page, 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           'chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers();'
25           'window.webkitRequestAnimationFrame(window.__rafFunction);'
26         '};'
27         'window.webkitRequestAnimationFrame(window.__rafFunction);')
28
29     time_out = max(60, self.seconds)
30     min_rafs = 3
31
32     # Wait until al leat self.seconds have elapsed AND min_rafs have been fired.
33     # Use a hard time-out after 60 seconds (or self.seconds).
34     while True:
35       raf_count = tab.EvaluateJavaScript('window.__rafCount;')
36       elapsed_time = time.time() - start_time
37       if elapsed_time > time_out:
38         break
39       elif elapsed_time > self.seconds and raf_count > min_rafs:
40         break
41       time.sleep(1)