OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2015 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 unittest | |
6 | |
7 import telemetry.timeline.event as timeline_event | |
8 from telemetry.testing import test_page_test_results | |
9 from telemetry.web_perf.metrics import startup | |
10 | |
11 | |
12 class StartupTimelineMetricTest(unittest.TestCase): | |
13 | |
14 def setUp(self): | |
15 self.events = [] | |
16 | |
17 def AddEvent(self, event_name, start, duration=None): | |
18 event = timeline_event.TimelineEvent('my_category', event_name, | |
19 start, duration) | |
20 self.events.append(event) | |
21 | |
22 # pylint: disable=W0201 | |
23 def RunAggregator(self): | |
nednguyen
2015/11/18 18:23:13
nits: s/RunAggregator/ComputeStartupMetrics
gabadie
2015/11/18 19:16:32
Done.
| |
24 results = test_page_test_results.TestPageTestResults(self) | |
25 | |
26 # Create a mock model usable by StartupTimelineMetric.AddWholeTraceResults() | |
27 def GenerateEvents(event_predicate): | |
eakuefner
2015/11/18 18:39:53
Sorry, but I disagree with pasko here. Please chan
eakuefner
2015/11/18 18:41:11
Through I do agree that it should be IterateEvents
pasko
2015/11/18 18:56:46
up to you, of course
gabadie
2015/11/18 19:16:32
Done.
| |
28 for event in self.events: | |
29 if event_predicate(event): | |
30 yield event | |
31 class MockClass(object): | |
32 pass | |
33 model = MockClass() | |
34 model.browser_process = MockClass() | |
35 model.browser_process.parent = MockClass() | |
36 model.browser_process.parent.IterAllEvents = GenerateEvents | |
37 | |
38 startup.StartupTimelineMetric().AddWholeTraceResults(model, results) | |
39 return results | |
40 | |
41 def testUntrackedvents(self): | |
42 # Code coverage for untracked events, to make sure there is nothing wrong | |
43 # going on. | |
44 self.AddEvent('uknown_event_0', 0) | |
45 self.AddEvent('uknown_event_1', 1) | |
46 self.RunAggregator() | |
47 | |
48 def testInstantEventsBasedValue(self): | |
49 # Test case with instant events to measure the duration between the first | |
50 # occurrences of two distinct events. | |
51 START0 = 7 | |
52 START1 = 8 | |
53 DURATION0 = 17 | |
54 DURATION1 = 18 | |
55 | |
56 # Generate duplicated events to make sure we consider only the first one. | |
57 self.AddEvent(startup._MAIN_ENTRY_POINT, START0) | |
58 self.AddEvent(startup._MAIN_ENTRY_POINT, START1) | |
59 self.AddEvent('loadEventEnd', START0 + DURATION0) | |
60 self.AddEvent('loadEventEnd', START1 + DURATION1) | |
61 | |
62 results = self.RunAggregator() | |
63 results.AssertHasPageSpecificScalarValue('foreground_tab_load_complete', | |
64 'ms', DURATION0) | |
65 | |
66 def testBeginEndEventsBasedValue(self): | |
67 # Test case to get the duration of the first occurrence of a duration event. | |
68 DURATION = 13 | |
69 | |
70 # Generate duplicated events to make sure we consider only the first one. | |
71 self.AddEvent('Startup.BrowserMessageLoopStartTimeFromMainEntry', 5, | |
72 DURATION) | |
73 self.AddEvent('Startup.BrowserMessageLoopStartTimeFromMainEntry', 6, | |
74 DURATION + 2) | |
75 | |
76 results = self.RunAggregator() | |
77 results.AssertHasPageSpecificScalarValue('messageloop_start_time', 'ms', | |
78 DURATION) | |
nednguyen
2015/11/18 18:23:13
Can you also add test coverage for open_tabs_time,
gabadie
2015/11/18 19:16:32
Done.
| |
OLD | NEW |