OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import os | 4 import os |
5 import unittest | 5 import unittest |
6 | 6 |
7 from chrome_remote_control import browser_finder | 7 from chrome_remote_control import browser_finder |
8 from chrome_remote_control import browser_options | 8 from chrome_remote_control import browser_options |
9 from chrome_remote_control import multi_page_benchmark | 9 from chrome_remote_control import multi_page_benchmark |
10 from chrome_remote_control import page_runner | 10 from chrome_remote_control import page_runner |
11 from chrome_remote_control import page_set | 11 from chrome_remote_control import page_set |
12 | 12 |
13 class MultiPageBenchmarkUnitTestBase(unittest.TestCase): | 13 class MultiPageBenchmarkUnitTestBase(unittest.TestCase): |
14 """unittest.TestCase-derived class to help in the construction of unit tests | 14 """unittest.TestCase-derived class to help in the construction of unit tests |
15 for a benchmark.""" | 15 for a benchmark.""" |
16 | 16 |
17 unittest_data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), | 17 unittest_data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), |
18 '..', 'unittest_data')) | 18 '..', 'unittest_data')) |
19 | 19 |
20 def CreatePageSetFromFileInUnittestDataDir(self, test_filename): | 20 def CreatePageSetFromFileInUnittestDataDir(self, test_filename): |
21 path = os.path.join(self.unittest_data_dir, test_filename) | 21 path = os.path.join(self.unittest_data_dir, test_filename) |
22 self.assertTrue(os.path.exists(path)) | 22 self.assertTrue(os.path.exists(path)) |
23 page = page_set.Page('file://%s' % path) | |
24 | 23 |
25 ps = page_set.PageSet() | 24 page = page_set.Page('file://%s' % test_filename) |
| 25 |
| 26 ps = page_set.PageSet(description='', |
| 27 file_path=os.path.join(self.unittest_data_dir, |
| 28 'test_pageset.json')) |
26 ps.pages.append(page) | 29 ps.pages.append(page) |
27 return ps | 30 return ps |
28 | 31 |
29 def CustomizeOptionsForTest(self, options): | 32 def CustomizeOptionsForTest(self, options): |
30 """Override to customize default options.""" | 33 """Override to customize default options.""" |
31 pass | 34 pass |
32 | 35 |
33 def RunBenchmark(self, benchmark, ps): | 36 def RunBenchmark(self, benchmark, ps): |
34 """Runs a benchmark against a pageset, returning the rows its outputs.""" | 37 """Runs a benchmark against a pageset, returning the rows its outputs.""" |
35 assert browser_options.options_for_unittests | 38 assert browser_options.options_for_unittests |
36 options = ( | 39 options = ( |
37 browser_options.options_for_unittests.Copy()) | 40 browser_options.options_for_unittests.Copy()) |
38 temp_parser = options.CreateParser() | 41 temp_parser = options.CreateParser() |
39 benchmark.AddOptions(temp_parser) | 42 benchmark.AddOptions(temp_parser) |
40 defaults = temp_parser.get_default_values() | 43 defaults = temp_parser.get_default_values() |
41 for k, v in defaults.__dict__.items(): | 44 for k, v in defaults.__dict__.items(): |
42 if hasattr(options, k): | 45 if hasattr(options, k): |
43 continue | 46 continue |
44 setattr(options, k, v) | 47 setattr(options, k, v) |
45 | 48 |
46 benchmark.CustomizeBrowserOptions(options) | 49 benchmark.CustomizeBrowserOptions(options) |
47 self.CustomizeOptionsForTest(options) | 50 self.CustomizeOptionsForTest(options) |
48 possible_browser = browser_finder.FindBrowser(options) | 51 possible_browser = browser_finder.FindBrowser(options) |
49 | 52 |
50 results = multi_page_benchmark.BenchmarkResults() | 53 results = multi_page_benchmark.BenchmarkResults() |
51 with page_runner.PageRunner(ps) as runner: | 54 with page_runner.PageRunner(ps) as runner: |
52 runner.Run(options, possible_browser, benchmark, results) | 55 runner.Run(options, possible_browser, benchmark, results) |
53 return results | 56 return results |
OLD | NEW |