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

Unified 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 side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698