1# Copyright 2013 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 unittest 6import sys 7 8from telemetry.core import util 9from telemetry.core.backends.chrome import inspector_timeline 10from telemetry.unittest import tab_test_case 11 12 13class InspectorTimelineTabTest(tab_test_case.TabTestCase): 14 """Test case that opens a browser and creates and then checks an event.""" 15 16 def _WaitForAnimationFrame(self): 17 """Wait until the variable window.done is set on the tab.""" 18 def _IsDone(): 19 return bool(self._tab.EvaluateJavaScript('window.done')) 20 util.WaitFor(_IsDone, 5) 21 22 def testGotTimeline(self): 23 if sys.platform in ('win32', 'cygwin'): 24 raise unittest.SkipTest('Test flaky on windows. http://crbug.com/321529') 25 26 # While the timeline is recording, call window.webkitRequestAnimationFrame. 27 # This will create a FireAnimationEvent, which can be checked below. See: 28 # https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame 29 with inspector_timeline.InspectorTimeline.Recorder(self._tab): 30 self._tab.ExecuteJavaScript( 31 """ 32 var done = false; 33 function sleep(ms) { 34 var endTime = (new Date().getTime()) + ms; 35 while ((new Date().getTime()) < endTime); 36 } 37 window.webkitRequestAnimationFrame(function() { 38 sleep(10); 39 window.done = true; 40 }); 41 """) 42 self._WaitForAnimationFrame() 43 44 # There should be at least a FireAnimationFrame record with some duration. 45 events = self._tab.timeline_model.GetAllEventsOfName('FireAnimationFrame') 46 self.assertTrue(len(events) > 0) 47 self.assertTrue(events[0].duration > 0) 48