Upstream version 9.38.198.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.core import util
8 from telemetry.page.actions import page_action
9
10
11 class RepaintContinuouslyAction(page_action.PageAction):
12   """Continuously repaints the visible content by requesting animation frames
13   until self.seconds have elapsed AND at least three RAFs have been fired. Times
14   out after max(60, self.seconds), if less than three RAFs were fired.
15   """
16
17   def __init__(self, seconds):
18     super(RepaintContinuouslyAction, self).__init__()
19     self._seconds = seconds
20
21   def RunAction(self, tab):
22     tab.ExecuteJavaScript(
23         'window.__rafCount = 0;'
24         'window.__rafFunction = function() {'
25           'window.__rafCount += 1;'
26           'window.webkitRequestAnimationFrame(window.__rafFunction);'
27         '};'
28         'window.webkitRequestAnimationFrame(window.__rafFunction);')
29
30     # Wait until at least self.seconds have elapsed AND min_rafs have been
31     # fired. Use a hard time-out after 60 seconds (or self.seconds).
32     time.sleep(self._seconds)
33     def HasMinRafs():
34       return tab.EvaluateJavaScript('window.__rafCount;') >= 3
35     util.WaitFor(HasMinRafs, max(60 - self._seconds, 0))