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

Side by Side Diff: tools/perf/measurements/tab_switching_unittest.py

Issue 2766533002: Using multi-tab story in TabSwitching Benchmark (Closed)
Patch Set: fix merge conflict Created 3 years, 8 months 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
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 from measurements import tab_switching
7 import mock
8 from page_sets.system_health import multi_tab_stories
9 from telemetry import benchmark
10 from telemetry import story as story_module
6 from telemetry.internal.results import page_test_results 11 from telemetry.internal.results import page_test_results
7 from telemetry.testing import page_test_test_case 12 from telemetry.testing import page_test_test_case
8 13 from telemetry.testing import options_for_unittests
9 from measurements import tab_switching 14 from telemetry.value import histogram
10
11 import mock
12 15
13 16
14 class BrowserForTest(object): 17 class BrowserForTest(object):
15 def __init__(self): 18 def __init__(self):
16 self.tabs = [] 19 self.tabs = []
17 self.platform = mock.MagicMock() 20 self.platform = mock.MagicMock()
18 self.platform.CanMonitorPower = mock.Mock(return_value=False) 21 self.platform.CanMonitorPower = mock.Mock(return_value=False)
19 22
20 def AddTab(self, tab): 23 def AddTab(self, tab):
21 tab.browser = self 24 tab.browser = self
22 self.tabs.append(tab) 25 self.tabs.append(tab)
23 26
24 27
25 class StorySetForTest(object): 28 class StorySetForTest(object):
26 def __init__(self): 29 def __init__(self):
27 self.stories = [] 30 self.stories = []
28 31
29 def AddStory(self, story): 32 def AddStory(self, story):
30 story.story_set = self 33 story.story_set = self
31 self.stories.append(story) 34 self.stories.append(story)
32 35
36 INTEGRATION_TEST_TAB_COUNT = 3
37
38 class EmptyMultiTabStory(multi_tab_stories.MultiTabStory):
39 NAME = 'multitab:test:empty'
40 URL_LIST = ['about:blank'] * INTEGRATION_TEST_TAB_COUNT
41 URL = URL_LIST[0]
33 42
34 class TabSwitchingUnittest(page_test_test_case.PageTestTestCase): 43 class TabSwitchingUnittest(page_test_test_case.PageTestTestCase):
35 @staticmethod 44 @staticmethod
36 def MakeStoryForTest(): 45 def MakeStoryForTest():
37 story = mock.MagicMock() 46 story = mock.MagicMock()
38 story.story_set = None 47 story.story_set = None
39 return story 48 return story
40 49
41 @staticmethod 50 @staticmethod
42 def MakeTabForTest(): 51 def MakeTabForTest():
(...skipping 13 matching lines...) Expand all
56 65
57 # Set up a browser with two tabs open 66 # Set up a browser with two tabs open
58 browser = BrowserForTest() 67 browser = BrowserForTest()
59 tab_0 = self.MakeTabForTest() 68 tab_0 = self.MakeTabForTest()
60 browser.AddTab(tab_0) 69 browser.AddTab(tab_0)
61 tab_1 = self.MakeTabForTest() 70 tab_1 = self.MakeTabForTest()
62 browser.AddTab(tab_1) 71 browser.AddTab(tab_1)
63 72
64 # Mock histogram result to test _IsDone really works. 73 # Mock histogram result to test _IsDone really works.
65 expected_histogram = [ 74 expected_histogram = [
66 # To get first_histogram for last tab (tab_1). 75 # DidNavigateToPage() calls GetHistogram() once
67 '{"count": 0, "buckets": []}', 76 '{"count": 0, "buckets": []}',
68 # First _IsDone check for tab_0. Retry. 77 # ValidateAndMeasurePage() calls GetHistogram() once
69 '{"count": 0, "buckets": []}',
70 # Second _IsDone check for tab_0. Retry.
71 '{"count": 0, "buckets": []}',
72 # Third _IsDone check for tab_0. Pass.
73 '{"count": 1, "buckets": [{"low": 1, "high": 2, "count": 1}]}',
74 # To get prev_histogram. End of tab_0 loop.
75 '{"count": 1, "buckets": [{"low": 1, "high": 2, "count": 1}]}',
76 # First _IsDone check for tab_1. Retry.
77 '{"count": 1, "buckets": [{"low": 1, "high": 2, "count": 1}]}',
78 # Second _IsDone check for tab_1. Pass.
79 '{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},'
80 '{"low": 2, "high": 3, "count": 1}]}',
81 # To get prev_histogram. End of tab_1 loop.
82 '{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},' 78 '{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},'
83 '{"low": 2, "high": 3, "count": 1}]}', 79 '{"low": 2, "high": 3, "count": 1}]}',
84 ] 80 ]
85 mock_get_histogram = mock.MagicMock(side_effect=expected_histogram) 81 mock_get_histogram = mock.MagicMock(side_effect=expected_histogram)
86 82
87 with contextlib.nested( 83 with contextlib.nested(
88 mock.patch('telemetry.value.histogram_util.GetHistogram', 84 mock.patch('telemetry.value.histogram_util.GetHistogram',
89 mock_get_histogram), 85 mock_get_histogram),
90 mock.patch('metrics.keychain_metric.KeychainMetric')): 86 mock.patch('metrics.keychain_metric.KeychainMetric')):
87 measure.DidNavigateToPage(story_set.stories[0], browser.tabs[-1])
91 measure.ValidateAndMeasurePage(story_set.stories[0], browser.tabs[-1], 88 measure.ValidateAndMeasurePage(story_set.stories[0], browser.tabs[-1],
92 page_test_results.PageTestResults()) 89 page_test_results.PageTestResults())
93 self.assertEqual(len(expected_histogram), 90 self.assertEqual(len(expected_histogram),
94 len(mock_get_histogram.mock_calls)) 91 len(mock_get_histogram.mock_calls))
92 # The last tab is passed to DidNavigateToPage() and
93 # ValidateAndMeasurePage()
95 expected_calls = [mock.call(mock.ANY, mock.ANY, t) for t in 94 expected_calls = [mock.call(mock.ANY, mock.ANY, t) for t in
96 [tab_1] + [tab_0] * 4 + [tab_1] * 3] 95 [browser.tabs[-1]] * 2]
97 self.assertEqual(expected_calls, mock_get_histogram.mock_calls) 96 self.assertEqual(expected_calls, mock_get_histogram.mock_calls)
97
98 @benchmark.Enabled('has tabs')
99 @benchmark.Disabled('mac-reference')
100 @benchmark.Disabled('android')
101 def testTabSwitching(self):
102 """IT of TabSwitching measurement and multi-tab story"""
103 ps = story_module.StorySet()
104 ps.AddStory(EmptyMultiTabStory(ps, False))
105 measurement = tab_switching.TabSwitching()
106 options = options_for_unittests.GetCopy()
107 results = self.RunMeasurement(measurement, ps, options=options)
108 self.assertEquals(len(results.failures), 0)
109
110 self.assertEquals(len(results.all_summary_values), 1)
111 summary = results.all_summary_values[0]
112 self.assertIsInstance(summary, histogram.HistogramValue)
113 self.assertEquals(summary.name, 'MPArch_RWH_TabSwitchPaintDuration')
114 histogram_count = sum([b.count for b in summary.buckets])
115 self.assertEquals(histogram_count, INTEGRATION_TEST_TAB_COUNT)
116 histogram_mean = summary.GetRepresentativeNumber()
117 self.assertGreater(histogram_mean, 0)
OLDNEW
« no previous file with comments | « tools/perf/measurements/tab_switching.py ('k') | tools/perf/page_sets/system_health/multi_tab_stories.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698