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