| OLD | NEW |
| 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 import decorators | 9 from telemetry import decorators |
| 10 from telemetry.core import util | 10 from telemetry.core import util |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 super(MockPageSet, self).__init__(archive_data_file='data/test.json') | 42 super(MockPageSet, self).__init__(archive_data_file='data/test.json') |
| 43 self.AddPage(MockPage(self, url)) | 43 self.AddPage(MockPage(self, url)) |
| 44 | 44 |
| 45 | 45 |
| 46 class MockPageTest(page_test.PageTest): | 46 class MockPageTest(page_test.PageTest): |
| 47 def __init__(self): | 47 def __init__(self): |
| 48 super(MockPageTest, self).__init__() | 48 super(MockPageTest, self).__init__() |
| 49 self._action_name_to_run = "RunBaz" | 49 self._action_name_to_run = "RunBaz" |
| 50 self.func_calls = [] | 50 self.func_calls = [] |
| 51 | 51 |
| 52 @classmethod | |
| 53 def AddCommandLineArgs(cls, parser): | |
| 54 parser.add_option('--mock-page-test-option', action="store_true") | |
| 55 | |
| 56 def WillNavigateToPage(self, page, tab): | 52 def WillNavigateToPage(self, page, tab): |
| 57 self.func_calls.append('WillNavigateToPage') | 53 self.func_calls.append('WillNavigateToPage') |
| 58 | 54 |
| 59 def DidNavigateToPage(self, page, tab): | 55 def DidNavigateToPage(self, page, tab): |
| 60 self.func_calls.append('DidNavigateToPage') | 56 self.func_calls.append('DidNavigateToPage') |
| 61 | 57 |
| 62 def WillRunActions(self, page, tab): | 58 def WillRunActions(self, page, tab): |
| 63 self.func_calls.append('WillRunActions') | 59 self.func_calls.append('WillRunActions') |
| 64 | 60 |
| 65 def DidRunActions(self, page, tab): | 61 def DidRunActions(self, page, tab): |
| 66 self.func_calls.append('DidRunActions') | 62 self.func_calls.append('DidRunActions') |
| 67 | 63 |
| 68 def ValidatePage(self, page, tab, results): | 64 def ValidatePage(self, page, tab, results): |
| 69 self.func_calls.append('ValidatePage') | 65 self.func_calls.append('ValidatePage') |
| 70 | 66 |
| 71 def WillStartBrowser(self, platform): | 67 def WillStartBrowser(self, platform): |
| 72 self.func_calls.append('WillStartBrowser') | 68 self.func_calls.append('WillStartBrowser') |
| 73 | 69 |
| 74 def DidStartBrowser(self, browser): | 70 def DidStartBrowser(self, browser): |
| 75 self.func_calls.append('DidStartBrowser') | 71 self.func_calls.append('DidStartBrowser') |
| 76 | 72 |
| 77 class MockBenchmark(benchmark.Benchmark): | 73 class MockBenchmark(benchmark.Benchmark): |
| 78 test = MockPageTest | 74 test = MockPageTest |
| 79 mock_page_set = None | 75 mock_page_set = None |
| 80 | 76 |
| 81 @classmethod | 77 @classmethod |
| 82 def AddTestCommandLineArgs(cls, group): | 78 def AddBenchmarkCommandLineArgs(cls, group): |
| 83 group.add_option('', '--mock-benchmark-url', action='store', type='string') | 79 group.add_option('', '--mock-benchmark-url', action='store', type='string') |
| 84 | 80 |
| 85 def CreatePageSet(self, options): | 81 def CreatePageSet(self, options): |
| 86 kwargs = {} | 82 kwargs = {} |
| 87 if options.mock_benchmark_url: | 83 if options.mock_benchmark_url: |
| 88 kwargs['url'] = options.mock_benchmark_url | 84 kwargs['url'] = options.mock_benchmark_url |
| 89 self.mock_page_set = MockPageSet(**kwargs) | 85 self.mock_page_set = MockPageSet(**kwargs) |
| 90 return self.mock_page_set | 86 return self.mock_page_set |
| 91 | 87 |
| 92 | 88 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 'non-existent-dummy-dir', mock_benchmark, flags) | 171 'non-existent-dummy-dir', mock_benchmark, flags) |
| 176 results = wpr_recorder.CreateResults() | 172 results = wpr_recorder.CreateResults() |
| 177 wpr_recorder.Record(results) | 173 wpr_recorder.Record(results) |
| 178 self.assertEqual(set(mock_benchmark.mock_page_set.pages), | 174 self.assertEqual(set(mock_benchmark.mock_page_set.pages), |
| 179 results.pages_that_succeeded) | 175 results.pages_that_succeeded) |
| 180 | 176 |
| 181 def testCommandLineFlags(self): | 177 def testCommandLineFlags(self): |
| 182 flags = [ | 178 flags = [ |
| 183 '--page-repeat', '2', | 179 '--page-repeat', '2', |
| 184 '--mock-benchmark-url', self._url, | 180 '--mock-benchmark-url', self._url, |
| 185 '--mock-page-test-option', | |
| 186 ] | 181 ] |
| 187 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(), | 182 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(), |
| 188 flags) | 183 flags) |
| 189 # page_runner command-line args | 184 # page_runner command-line args |
| 190 self.assertEquals(2, wpr_recorder.options.page_repeat) | 185 self.assertEquals(2, wpr_recorder.options.page_repeat) |
| 191 # benchmark command-line args | 186 # benchmark command-line args |
| 192 self.assertEquals(self._url, wpr_recorder.options.mock_benchmark_url) | 187 self.assertEquals(self._url, wpr_recorder.options.mock_benchmark_url) |
| 193 # benchmark's page_test command-line args | |
| 194 self.assertTrue(wpr_recorder.options.mock_page_test_option) | |
| 195 # invalid command-line args | 188 # invalid command-line args |
| 196 self.assertFalse(hasattr(wpr_recorder.options, 'not_a_real_option')) | 189 self.assertFalse(hasattr(wpr_recorder.options, 'not_a_real_option')) |
| 197 | 190 |
| 198 def testRecordingEnabled(self): | 191 def testRecordingEnabled(self): |
| 199 flags = ['--mock-benchmark-url', self._url] | 192 flags = ['--mock-benchmark-url', self._url] |
| 200 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(), | 193 wpr_recorder = record_wpr.WprRecorder(self._test_data_dir, MockBenchmark(), |
| 201 flags) | 194 flags) |
| 202 self.assertEqual(wpr_modes.WPR_RECORD, | 195 self.assertEqual(wpr_modes.WPR_RECORD, |
| 203 wpr_recorder.options.browser_options.wpr_mode) | 196 wpr_recorder.options.browser_options.wpr_mode) |
| 204 | 197 |
| 205 def testFindAllActionNames(self): | 198 def testFindAllActionNames(self): |
| 206 # The src/tools/telemetry/unittest_data/page_tests/ has been | 199 # The src/tools/telemetry/unittest_data/page_tests/ has been |
| 207 # populated with three simple Page Measurement classes, the first two of | 200 # populated with three simple Page Measurement classes, the first two of |
| 208 # which have action_name_to_run defined. | 201 # which have action_name_to_run defined. |
| 209 action_names_to_run = record_wpr.FindAllActionNames(self._test_data_dir) | 202 action_names_to_run = record_wpr.FindAllActionNames(self._test_data_dir) |
| 210 self.assertTrue('RunFoo' in action_names_to_run) | 203 self.assertTrue('RunFoo' in action_names_to_run) |
| 211 self.assertTrue('RunBar' in action_names_to_run) | 204 self.assertTrue('RunBar' in action_names_to_run) |
| 212 self.assertFalse('RunBaz' in action_names_to_run) | 205 self.assertFalse('RunBaz' in action_names_to_run) |
| 213 | 206 |
| 214 # When the RecorderPageTest WillStartBrowser/DidStartBrowser function is | 207 # When the RecorderPageTest WillStartBrowser/DidStartBrowser function is |
| 215 # called, it forwards the call to the PageTest | 208 # called, it forwards the call to the PageTest |
| 216 def testRecorderPageTest_BrowserMethods(self): | 209 def testRecorderPageTest_BrowserMethods(self): |
| 217 record_page_test = record_wpr.RecorderPageTest([]) | 210 record_page_test = record_wpr.RecorderPageTest([]) |
| 218 record_page_test.page_test = MockBenchmark().test() | 211 record_page_test.page_test = MockBenchmark().test() |
| 219 record_page_test.WillStartBrowser(self._tab.browser.platform) | 212 record_page_test.WillStartBrowser(self._tab.browser.platform) |
| 220 record_page_test.DidStartBrowser(self._tab.browser) | 213 record_page_test.DidStartBrowser(self._tab.browser) |
| 221 self.assertTrue('WillStartBrowser' in record_page_test.page_test.func_calls) | 214 self.assertTrue('WillStartBrowser' in record_page_test.page_test.func_calls) |
| 222 self.assertTrue('DidStartBrowser' in record_page_test.page_test.func_calls) | 215 self.assertTrue('DidStartBrowser' in record_page_test.page_test.func_calls) |
| OLD | NEW |