Index: tools/telemetry/telemetry/web_perf/metrics/startup_unittest.py |
diff --git a/tools/telemetry/telemetry/web_perf/metrics/startup_unittest.py b/tools/telemetry/telemetry/web_perf/metrics/startup_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e73e3ddb76d6f6a098259cb0be57e6610923dfd2 |
--- /dev/null |
+++ b/tools/telemetry/telemetry/web_perf/metrics/startup_unittest.py |
@@ -0,0 +1,78 @@ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import unittest |
+ |
+import telemetry.timeline.event as timeline_event |
+from telemetry.testing import test_page_test_results |
+from telemetry.web_perf.metrics import startup |
+ |
+ |
+class StartupTimelineMetricTest(unittest.TestCase): |
+ |
+ def setUp(self): |
+ self.events = [] |
+ |
+ def AddEvent(self, event_name, start, duration=None): |
+ event = timeline_event.TimelineEvent('my_category', event_name, |
+ start, duration) |
+ self.events.append(event) |
+ |
+ # pylint: disable=W0201 |
+ def RunAggregator(self): |
nednguyen
2015/11/18 18:23:13
nits: s/RunAggregator/ComputeStartupMetrics
gabadie
2015/11/18 19:16:32
Done.
|
+ results = test_page_test_results.TestPageTestResults(self) |
+ |
+ # Create a mock model usable by StartupTimelineMetric.AddWholeTraceResults() |
+ 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.
|
+ for event in self.events: |
+ if event_predicate(event): |
+ yield event |
+ class MockClass(object): |
+ pass |
+ model = MockClass() |
+ model.browser_process = MockClass() |
+ model.browser_process.parent = MockClass() |
+ model.browser_process.parent.IterAllEvents = GenerateEvents |
+ |
+ startup.StartupTimelineMetric().AddWholeTraceResults(model, results) |
+ return results |
+ |
+ def testUntrackedvents(self): |
+ # Code coverage for untracked events, to make sure there is nothing wrong |
+ # going on. |
+ self.AddEvent('uknown_event_0', 0) |
+ self.AddEvent('uknown_event_1', 1) |
+ self.RunAggregator() |
+ |
+ def testInstantEventsBasedValue(self): |
+ # Test case with instant events to measure the duration between the first |
+ # occurrences of two distinct events. |
+ START0 = 7 |
+ START1 = 8 |
+ DURATION0 = 17 |
+ DURATION1 = 18 |
+ |
+ # Generate duplicated events to make sure we consider only the first one. |
+ self.AddEvent(startup._MAIN_ENTRY_POINT, START0) |
+ self.AddEvent(startup._MAIN_ENTRY_POINT, START1) |
+ self.AddEvent('loadEventEnd', START0 + DURATION0) |
+ self.AddEvent('loadEventEnd', START1 + DURATION1) |
+ |
+ results = self.RunAggregator() |
+ results.AssertHasPageSpecificScalarValue('foreground_tab_load_complete', |
+ 'ms', DURATION0) |
+ |
+ def testBeginEndEventsBasedValue(self): |
+ # Test case to get the duration of the first occurrence of a duration event. |
+ DURATION = 13 |
+ |
+ # Generate duplicated events to make sure we consider only the first one. |
+ self.AddEvent('Startup.BrowserMessageLoopStartTimeFromMainEntry', 5, |
+ DURATION) |
+ self.AddEvent('Startup.BrowserMessageLoopStartTimeFromMainEntry', 6, |
+ DURATION + 2) |
+ |
+ results = self.RunAggregator() |
+ results.AssertHasPageSpecificScalarValue('messageloop_start_time', 'ms', |
+ 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.
|