Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 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 | |
| 5 """Test Cluster Telemetry benchmarks and page sets.""" | |
|
eakuefner
2015/10/15 14:01:31
nit: no need for this comment
rmistry
2015/10/15 14:10:37
Done.
| |
| 6 | |
| 7 from optparse import OptionParser | |
| 8 import unittest | |
| 9 | |
| 10 from telemetry.page import shared_page_state | |
| 11 | |
| 12 from benchmarks import rasterize_and_record_micro | |
| 13 from benchmarks import repaint | |
| 14 from benchmarks import skpicture_printer | |
| 15 | |
| 16 | |
| 17 class MockErrorParser(object): | |
| 18 def __init__(self): | |
| 19 self.err_msg = None | |
| 20 | |
| 21 def error(self, err_msg): | |
| 22 self.err_msg = err_msg | |
| 23 | |
| 24 | |
| 25 class CTBenchmarks(unittest.TestCase): | |
| 26 | |
| 27 def setUp(self): | |
| 28 self.ct_benchmarks = [ | |
| 29 rasterize_and_record_micro.RasterizeAndRecordMicroCT(), | |
| 30 repaint.RepaintCT(), | |
| 31 skpicture_printer.SkpicturePrinterCT(), | |
| 32 ] | |
| 33 self.shared_page_state_class = shared_page_state.SharedMobilePageState | |
| 34 self.archive_data_file = '/b/test' | |
| 35 self.urls_list = 'http://test1.com,http://test2.com,http://test3.net' | |
| 36 self.mock_parser = MockErrorParser() | |
| 37 | |
| 38 def testCTBenchmarks(self): | |
| 39 for benchmark in self.ct_benchmarks: | |
| 40 parser = OptionParser() | |
| 41 parser.user_agent = 'mobile' | |
| 42 parser.archive_data_file = self.archive_data_file | |
| 43 parser.urls_list = self.urls_list | |
| 44 | |
| 45 benchmark.AddBenchmarkCommandLineArgs(parser) | |
| 46 benchmark.ProcessCommandLineArgs(None, parser) | |
| 47 ct_page_set = benchmark.CreateStorySet(parser) | |
| 48 | |
| 49 self.assertEquals( | |
| 50 len(self.urls_list.split(',')), len(ct_page_set.stories)) | |
| 51 self.assertEquals( | |
| 52 self.archive_data_file, ct_page_set.archive_data_file) | |
| 53 for i in range(len(self.urls_list.split(','))): | |
| 54 url = self.urls_list.split(',')[i] | |
| 55 story = ct_page_set.stories[i] | |
| 56 self.assertEquals(url, story.url) | |
| 57 self.assertEquals( | |
| 58 self.shared_page_state_class, story.shared_state_class) | |
| 59 self.assertEquals(self.archive_data_file, story.archive_data_file) | |
| 60 | |
| 61 def testCTBenchmarks_wrongAgent(self): | |
| 62 for benchmark in self.ct_benchmarks: | |
| 63 parser = OptionParser() | |
| 64 parser.user_agent = 'mobileeeeee' | |
| 65 parser.archive_data_file = self.archive_data_file | |
| 66 parser.urls_list = self.urls_list | |
| 67 | |
| 68 benchmark.AddBenchmarkCommandLineArgs(parser) | |
| 69 benchmark.ProcessCommandLineArgs(None, parser) | |
| 70 try: | |
| 71 benchmark.CreateStorySet(parser) | |
| 72 self.fail('Expected ValueError') | |
| 73 except ValueError, e: | |
| 74 self.assertEquals('user_agent mobileeeeee is unrecognized', e.message) | |
| 75 | |
| 76 def testCTBenchmarks_missingDataFile(self): | |
| 77 for benchmark in self.ct_benchmarks: | |
| 78 parser = OptionParser() | |
| 79 parser.user_agent = 'mobile' | |
| 80 parser.urls_list = self.urls_list | |
| 81 benchmark.AddBenchmarkCommandLineArgs(parser) | |
| 82 | |
| 83 # Should fail due to missing archive_data_file. | |
| 84 try: | |
| 85 benchmark.ProcessCommandLineArgs(None, parser) | |
| 86 self.fail('Expected AttributeError') | |
| 87 except AttributeError, e: | |
| 88 self.assertEquals( | |
| 89 'OptionParser instance has no attribute \'archive_data_file\'', | |
| 90 e.message) | |
| 91 | |
| 92 # Now add an empty archive_data_file. | |
| 93 parser.archive_data_file = '' | |
| 94 benchmark.ProcessCommandLineArgs(self.mock_parser, parser) | |
| 95 self.assertEquals( | |
| 96 'Please specify --archive_data_file.', self.mock_parser.err_msg) | |
| 97 | |
| 98 def testCTBenchmarks_missingUrlsList(self): | |
| 99 for benchmark in self.ct_benchmarks: | |
| 100 parser = OptionParser() | |
| 101 parser.user_agent = 'mobile' | |
| 102 parser.archive_data_file = self.archive_data_file | |
| 103 benchmark.AddBenchmarkCommandLineArgs(parser) | |
| 104 | |
| 105 # Should fail due to missing urls_list. | |
| 106 try: | |
| 107 benchmark.ProcessCommandLineArgs(None, parser) | |
| 108 self.fail('Expected AttributeError') | |
| 109 except AttributeError, e: | |
| 110 self.assertEquals( | |
| 111 'OptionParser instance has no attribute \'urls_list\'', | |
| 112 e.message) | |
| 113 | |
| 114 # Now add an empty urls_list. | |
| 115 parser.urls_list = '' | |
| 116 benchmark.ProcessCommandLineArgs(self.mock_parser, parser) | |
| 117 self.assertEquals('Please specify --urls_list.', self.mock_parser.err_msg) | |
| OLD | NEW |