Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: tools/telemetry/telemetry/web_perf/metrics/startup_unittest.py

Issue 1435243002: Re-implements start_with_url.* benchmarks as start_with_url2.* using TBM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b00
Patch Set: After offline discussion with nednguyen, replacing _AddEventsResults with a mock model to directly … Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698