OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 import StringIO | |
5 import os | |
6 import unittest | |
7 | |
8 from telemetry import block_page_benchmark_results | |
9 from telemetry.page_set import PageSet | |
10 | |
11 BlockPageBenchmarkResults = \ | |
12 block_page_benchmark_results.BlockPageBenchmarkResults | |
13 | |
14 def _MakePageSet(): | |
15 return PageSet.FromDict({ | |
16 "description": "hello", | |
17 "archive_path": "foo.wpr", | |
18 "pages": [ | |
19 {"url": "http://www.foo.com/"}, | |
20 {"url": "http://www.bar.com/"} | |
21 ] | |
22 }, os.path.dirname(__file__)) | |
23 | |
24 class NonPrintingBlockPageBenchmarkResults(BlockPageBenchmarkResults): | |
25 def __init__(self, *args): | |
26 super(NonPrintingBlockPageBenchmarkResults, self).__init__(*args) | |
27 | |
28 def _PrintPerfResult(self, *args): | |
29 pass | |
30 | |
31 class BlockPageBenchmarkResultsTest(unittest.TestCase): | |
32 def setUp(self): | |
33 self._output = StringIO.StringIO() | |
34 self._page_set = _MakePageSet() | |
35 | |
36 @property | |
37 def lines(self): | |
38 lines = StringIO.StringIO(self._output.getvalue()).readlines() | |
39 return [line.strip() for line in lines] | |
40 | |
41 @property | |
42 def data(self): | |
43 return [line.split(': ', 1) for line in self.lines] | |
44 | |
45 def test_with_output_after_every_page(self): | |
46 results = NonPrintingBlockPageBenchmarkResults(self._output) | |
47 results.WillMeasurePage(self._page_set[0]) | |
48 results.Add('foo', 'seconds', 3) | |
49 results.DidMeasurePage() | |
50 | |
51 results.WillMeasurePage(self._page_set[1]) | |
52 results.Add('bar', 'seconds', 4) | |
53 results.DidMeasurePage() | |
54 | |
55 expected = [ | |
56 ['url', 'http://www.foo.com/'], | |
57 ['foo (seconds)', '3'], | |
58 [''], | |
59 ['url', 'http://www.bar.com/'], | |
60 ['bar (seconds)', '4'], | |
61 [''] | |
62 ] | |
63 self.assertEquals(self.data, expected) | |
OLD | NEW |