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

Side by Side Diff: tools/telemetry/telemetry/page/record_wpr_unittest.py

Issue 427093002: Add {Will,Did}StartBrowser to record_wpr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « tools/telemetry/telemetry/page/record_wpr.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 os 5 import os
6 import sys 6 import sys
7 7
8 from telemetry import benchmark 8 from telemetry import benchmark
9 from telemetry.core import util 9 from telemetry.core import util
10 from telemetry.core import wpr_modes 10 from telemetry.core import wpr_modes
11 from telemetry.page import page as page_module 11 from telemetry.page import page as page_module
12 from telemetry.page import page_set as page_set_module 12 from telemetry.page import page_set as page_set_module
13 from telemetry.page import page_test 13 from telemetry.page import page_test
14 from telemetry.page import record_wpr 14 from telemetry.page import record_wpr
15 from telemetry.unittest import tab_test_case 15 from telemetry.unittest import tab_test_case
16 16
17 17
18 class MockPage(page_module.Page): 18 class MockPage(page_module.Page):
19
19 def __init__(self, page_set, url): 20 def __init__(self, page_set, url):
20 super(MockPage, self).__init__(url=url, 21 super(MockPage, self).__init__(url=url,
21 page_set=page_set, 22 page_set=page_set,
22 base_dir=util.GetUnittestDataDir()) 23 base_dir=util.GetUnittestDataDir())
23 self.func_calls = [] 24 self.func_calls = []
24 25
25 def RunNavigateSteps(self, action_runner): 26 def RunNavigateSteps(self, action_runner):
26 self.func_calls.append('RunNavigateSteps') 27 self.func_calls.append('RunNavigateSteps')
27 super(MockPage, self).RunNavigateSteps(action_runner) 28 super(MockPage, self).RunNavigateSteps(action_runner)
28 29
29 def RunFoo(self, _): 30 def RunFoo(self, _):
30 self.func_calls.append('RunFoo') 31 self.func_calls.append('RunFoo')
31 32
32 def RunBar(self, _): 33 def RunBar(self, _):
33 self.func_calls.append('RunBar') 34 self.func_calls.append('RunBar')
34 35
35 def RunBaz(self, _): 36 def RunBaz(self, _):
36 self.func_calls.append('RunBaz') 37 self.func_calls.append('RunBaz')
37 38
38 39
39 class MockPageSet(page_set_module.PageSet): 40 class MockPageSet(page_set_module.PageSet):
41
40 def __init__(self, url=''): 42 def __init__(self, url=''):
41 super(MockPageSet, self).__init__(archive_data_file='data/test.json') 43 super(MockPageSet, self).__init__(archive_data_file='data/test.json')
42 self.AddPage(MockPage(self, url)) 44 self.AddPage(MockPage(self, url))
43 45
44 46
45 class MockPageTest(page_test.PageTest): 47 class MockPageTest(page_test.PageTest):
48
46 def __init__(self): 49 def __init__(self):
47 super(MockPageTest, self).__init__() 50 super(MockPageTest, self).__init__()
48 self._action_name_to_run = "RunBaz" 51 self._action_name_to_run = 'RunBaz'
49 self.func_calls = [] 52 self.func_calls = []
50 53
51 @classmethod 54 @classmethod
52 def AddCommandLineArgs(cls, parser): 55 def AddCommandLineArgs(cls, parser):
53 parser.add_option('--mock-page-test-option', action="store_true") 56 parser.add_option('--mock-page-test-option', action='store_true')
54 57
55 def WillNavigateToPage(self, page, tab): 58 def WillNavigateToPage(self, page, tab):
56 self.func_calls.append('WillNavigateToPage') 59 self.func_calls.append('WillNavigateToPage')
57 60
58 def DidNavigateToPage(self, page, tab): 61 def DidNavigateToPage(self, page, tab):
59 self.func_calls.append('DidNavigateToPage') 62 self.func_calls.append('DidNavigateToPage')
60 63
64 def WillStartBrowser(self, browser):
65 self.func_calls.append('WillStartBrowser')
66
67 def DidStartBrowser(self, browser):
68 self.func_calls.append('DidStartBrowser')
69
61 def WillRunActions(self, page, tab): 70 def WillRunActions(self, page, tab):
62 self.func_calls.append('WillRunActions') 71 self.func_calls.append('WillRunActions')
63 72
64 def DidRunActions(self, page, tab): 73 def DidRunActions(self, page, tab):
65 self.func_calls.append('DidRunActions') 74 self.func_calls.append('DidRunActions')
66 75
67 def ValidatePage(self, page, tab, results): 76 def ValidatePage(self, page, tab, results):
68 self.func_calls.append('ValidatePage') 77 self.func_calls.append('ValidatePage')
69 78
70 79
71 class MockBenchmark(benchmark.Benchmark): 80 class MockBenchmark(benchmark.Benchmark):
72 test = MockPageTest 81 test = MockPageTest
73 82
74 @classmethod 83 @classmethod
75 def AddTestCommandLineArgs(cls, group): 84 def AddTestCommandLineArgs(cls, group):
76 group.add_option('', '--mock-benchmark-url', action='store', type='string') 85 group.add_option('', '--mock-benchmark-url', action='store', type='string')
77 86
78 def CreatePageSet(self, options): 87 def CreatePageSet(self, options):
79 kwargs = {} 88 kwargs = {}
80 if (options.mock_benchmark_url): 89 if options.mock_benchmark_url:
81 kwargs['url'] = options.mock_benchmark_url 90 kwargs['url'] = options.mock_benchmark_url
82 return MockPageSet(**kwargs) 91 return MockPageSet(**kwargs)
83 92
84 93
85 class RecordWprUnitTests(tab_test_case.TabTestCase): 94 class RecordWprUnitTests(tab_test_case.TabTestCase):
86 95
87 _base_dir = util.GetUnittestDataDir() 96 _base_dir = util.GetUnittestDataDir()
88 _test_data_dir = os.path.join(util.GetUnittestDataDir(), 'page_measurements') 97 _test_data_dir = os.path.join(util.GetUnittestDataDir(), 'page_measurements')
89 98
90 @classmethod 99 @classmethod
91 def setUpClass(cls): 100 def setUpClass(cls):
92 sys.path.extend([cls._base_dir, cls._test_data_dir]) 101 sys.path.extend([cls._base_dir, cls._test_data_dir])
93 super(RecordWprUnitTests, cls).setUpClass() 102 super(RecordWprUnitTests, cls).setUpClass()
94 cls._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) 103 cls._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
95 blank_html_path = os.path.join(util.GetUnittestDataDir(), 'blank.html') 104 blank_html_path = os.path.join(util.GetUnittestDataDir(), 'blank.html')
96 cls._url = cls._browser.http_server.UrlOf(blank_html_path) 105 cls._url = cls._browser.http_server.UrlOf(blank_html_path)
97 106
98 # When the RecorderPageTest is created from a PageSet, we do not have a 107 # When the RecorderPageTest is created from a PageSet, we do not have a
99 # PageTest to use. In this case, we will record every available action. 108 # PageTest to use. In this case, we will record every available action.
100 def testRunPage_AllActions(self): 109 def testRunPage_AllActions(self):
101 record_page_test = record_wpr.RecorderPageTest(["RunFoo", "RunBar"]) 110 record_page_test = record_wpr.RecorderPageTest(['RunFoo', 'RunBar'])
102 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url) 111 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url)
103 record_page_test.RunPage(page, self._tab, results=None) 112 record_page_test.RunPage(page, self._tab, results=None)
104 self.assertTrue('RunFoo' in page.func_calls) 113 self.assertTrue('RunFoo' in page.func_calls)
105 self.assertTrue('RunBar' in page.func_calls) 114 self.assertTrue('RunBar' in page.func_calls)
106 self.assertFalse('RunBaz' in page.func_calls) 115 self.assertFalse('RunBaz' in page.func_calls)
107 116
108 def testRunPage_DontReloadSingleActions(self): 117 def testRunPage_DontReloadSingleActions(self):
109 record_page_test = record_wpr.RecorderPageTest(["RunFoo"]) 118 record_page_test = record_wpr.RecorderPageTest(['RunFoo'])
110 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url) 119 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url)
111 record_page_test.RunPage(page, self._tab, results=None) 120 record_page_test.RunPage(page, self._tab, results=None)
112 self.assertFalse('RunNavigateSteps' in page.func_calls) 121 self.assertFalse('RunNavigateSteps' in page.func_calls)
113 122
114 def testRunPage_ReloadPageBetweenActions(self): 123 def testRunPage_ReloadPageBetweenActions(self):
115 record_page_test = record_wpr.RecorderPageTest(["RunFoo", "RunBar"]) 124 record_page_test = record_wpr.RecorderPageTest(['RunFoo', 'RunBar'])
116 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url) 125 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url)
117 record_page_test.RunPage(page, self._tab, results=None) 126 record_page_test.RunPage(page, self._tab, results=None)
118 self.assertTrue('RunNavigateSteps' in page.func_calls) 127 self.assertTrue('RunNavigateSteps' in page.func_calls)
119 128
120 # When the RecorderPageTest is created from a Benchmark, the benchmark will 129 # When the RecorderPageTest is created from a Benchmark, the benchmark will
121 # have a PageTest, specified by its test attribute. 130 # have a PageTest, specified by its test attribute.
122 def testRunPage_OnlyRunBenchmarkAction(self): 131 def testRunPage_OnlyRunBenchmarkAction(self):
123 record_page_test = record_wpr.RecorderPageTest(["RunFoo"]) 132 record_page_test = record_wpr.RecorderPageTest(['RunFoo'])
124 record_page_test.page_test = MockBenchmark().test() 133 record_page_test.page_test = MockBenchmark().test()
125 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url) 134 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url)
126 record_page_test.RunPage(page, self._tab, results=None) 135 record_page_test.RunPage(page, self._tab, results=None)
127 self.assertFalse('RunFoo' in page.func_calls) 136 self.assertFalse('RunFoo' in page.func_calls)
128 self.assertTrue('RunBaz' in page.func_calls) 137 self.assertTrue('RunBaz' in page.func_calls)
129 138
130 def testRunPage_CallBenchmarksPageTestsFunctions(self): 139 def testRunPage_CallBenchmarksPageTestsFunctions(self):
131 record_page_test = record_wpr.RecorderPageTest([]) 140 record_page_test = record_wpr.RecorderPageTest([])
132 record_page_test.page_test = MockBenchmark().test() 141 record_page_test.page_test = MockBenchmark().test()
133 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url) 142 page = MockPage(page_set=MockPageSet(url=self._url), url=self._url)
134 record_page_test.RunPage(page, self._tab, results=None) 143 record_page_test.RunPage(page, self._tab, results=None)
135 self.assertEqual(3, len(record_page_test.page_test.func_calls)) 144 self.assertEqual(['WillRunActions', 'DidRunActions', 'ValidatePage'],
136 self.assertEqual('WillRunActions', record_page_test.page_test.func_calls[0]) 145 record_page_test.page_test.func_calls)
137 self.assertEqual('DidRunActions', record_page_test.page_test.func_calls[1])
138 self.assertEqual('ValidatePage', record_page_test.page_test.func_calls[2])
139 146
140 def testWprRecorderWithPageSet(self): 147 def testWprRecorderWithPageSet(self):
141 flags = [] 148 flags = []
142 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, 149 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir,
143 MockPageSet(url=self._url), flags) 150 MockPageSet(url=self._url), flags)
144 results = wpr_recorder.Record() 151 results = wpr_recorder.Record()
145 self.assertEquals(1, len(results.successes)) 152 self.assertEquals(1, len(results.successes))
146 mock_page = results.successes.pop() 153 mock_page = results.successes.pop()
147 self.assertTrue('RunFoo' in mock_page.func_calls) 154 self.assertTrue('RunFoo' in mock_page.func_calls)
148 self.assertFalse('RunBaz' in mock_page.func_calls) 155 self.assertFalse('RunBaz' in mock_page.func_calls)
149 156
150 def testWprRecorderWithBenchmark(self): 157 def testWprRecorderWithBenchmark(self):
151 flags = ['--mock-benchmark-url', self._url] 158 flags = ['--mock-benchmark-url', self._url]
152 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(), 159 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(),
153 flags) 160 flags)
154 results = wpr_recorder.Record() 161 results = wpr_recorder.Record()
155 self.assertEquals(1, len(results.successes)) 162 self.assertEquals(1, len(results.successes))
156 mock_page = results.successes.pop() 163 mock_page = results.successes.pop()
157 self.assertFalse('RunFoo' in mock_page.func_calls) 164 self.assertFalse('RunFoo' in mock_page.func_calls)
158 self.assertTrue('RunBaz' in mock_page.func_calls) 165 self.assertTrue('RunBaz' in mock_page.func_calls)
166 self.assertEqual(['WillStartBrowser', 'DidStartBrowser',
167 'WillNavigateToPage', 'DidNavigateToPage',
168 'WillRunActions', 'DidRunActions',
169 'ValidatePage'],
170 wpr_recorder.page_test.func_calls)
159 171
160 def testCommandLineFlags(self): 172 def testCommandLineFlags(self):
161 flags = [ 173 flags = [
162 '--page-repeat', '2', 174 '--page-repeat', '2',
163 '--mock-benchmark-url', self._url, 175 '--mock-benchmark-url', self._url,
164 '--mock-page-test-option', 176 '--mock-page-test-option',
165 ] 177 ]
166 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(), 178 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(),
167 flags) 179 flags)
168 # page_runner command-line args 180 # page_runner command-line args
(...skipping 13 matching lines...) Expand all
182 wpr_recorder.options.browser_options.wpr_mode) 194 wpr_recorder.options.browser_options.wpr_mode)
183 195
184 def testFindAllActionNames(self): 196 def testFindAllActionNames(self):
185 # The src/tools/telemetry/unittest_data/page_measurements/ has been 197 # The src/tools/telemetry/unittest_data/page_measurements/ has been
186 # populated with three simple Page Measurement classes, the first two of 198 # populated with three simple Page Measurement classes, the first two of
187 # which have action_name_to_run defined. 199 # which have action_name_to_run defined.
188 action_names_to_run = record_wpr.FindAllActionNames(self._test_data_dir) 200 action_names_to_run = record_wpr.FindAllActionNames(self._test_data_dir)
189 self.assertTrue('RunFoo' in action_names_to_run) 201 self.assertTrue('RunFoo' in action_names_to_run)
190 self.assertTrue('RunBar' in action_names_to_run) 202 self.assertTrue('RunBar' in action_names_to_run)
191 self.assertFalse('RunBaz' in action_names_to_run) 203 self.assertFalse('RunBaz' in action_names_to_run)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/page/record_wpr.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698