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 from chrome_remote_control import multi_page_benchmark | 4 from chrome_remote_control import multi_page_benchmark |
5 from chrome_remote_control import multi_page_benchmark_unittest_base | 5 from chrome_remote_control import multi_page_benchmark_unittest_base |
6 | 6 |
7 class BenchThatFails(multi_page_benchmark.MultiPageBenchmark): | 7 class BenchThatFails(multi_page_benchmark.MultiPageBenchmark): |
8 def MeasurePage(self, page, tab): | 8 def MeasurePage(self, page, tab): |
9 raise multi_page_benchmark.MeasurementFailure('Intentional failure.') | 9 raise multi_page_benchmark.MeasurementFailure('Intentional failure.') |
10 | 10 |
11 class BenchThatHasDefaults(multi_page_benchmark.MultiPageBenchmark): | 11 class BenchThatHasDefaults(multi_page_benchmark.MultiPageBenchmark): |
12 def AddOptions(self, parser): | 12 def AddOptions(self, parser): |
13 parser.add_option('-x', dest='x', default=3) | 13 parser.add_option('-x', dest='x', default=3) |
14 | 14 |
15 def MeasurePage(self, page, tab): | 15 def MeasurePage(self, page, tab): |
16 assert self.options.x == 3 | 16 assert self.options.x == 3 |
17 return {'x': 7} | 17 return {'x': 7} |
18 | 18 |
| 19 class BenchForBlank(multi_page_benchmark.MultiPageBenchmark): |
| 20 def MeasurePage(self, page, tab): |
| 21 contents = tab.runtime.Evaluate('document.body.textContent') |
| 22 assert contents.strip() == 'Hello world' |
| 23 |
19 class MultiPageBenchmarkUnitTest( | 24 class MultiPageBenchmarkUnitTest( |
20 multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase): | 25 multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase): |
21 | 26 |
| 27 def testGotToBlank(self): |
| 28 ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html') |
| 29 benchmark = BenchForBlank() |
| 30 all_results = self.RunBenchmark(benchmark, ps) |
| 31 self.assertEquals(0, len(all_results.page_failures)) |
| 32 |
22 def testFailure(self): | 33 def testFailure(self): |
23 ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html') | 34 ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html') |
24 benchmark = BenchThatFails() | 35 benchmark = BenchThatFails() |
25 all_results = self.RunBenchmark(benchmark, ps) | 36 all_results = self.RunBenchmark(benchmark, ps) |
26 self.assertEquals(1, len(all_results.page_failures)) | 37 self.assertEquals(1, len(all_results.page_failures)) |
27 | 38 |
28 def testDefaults(self): | 39 def testDefaults(self): |
29 ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html') | 40 ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html') |
30 benchmark = BenchThatHasDefaults() | 41 benchmark = BenchThatHasDefaults() |
31 all_results = self.RunBenchmark(benchmark, ps) | 42 all_results = self.RunBenchmark(benchmark, ps) |
32 self.assertEquals(len(all_results.page_results), 1) | 43 self.assertEquals(len(all_results.page_results), 1) |
33 self.assertEquals(all_results.page_results[0]['results']["x"], 7) | 44 self.assertEquals(all_results.page_results[0]['results']["x"], 7) |
34 | 45 |
OLD | NEW |