OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 import os | |
6 import re | |
7 import sys | |
8 | |
9 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
10 | |
11 import chrome_remote_control | |
12 | |
13 def Main(args): | |
14 options = chrome_remote_control.BrowserOptions() | |
15 parser = options.CreateParser('rendering_microbenchmark_test.py <sitelist>') | |
16 # TODO(nduca): Add test specific options here, if any. | |
17 options, args = parser.parse_args(args) | |
18 if len(args) != 1: | |
19 parser.print_usage() | |
20 return 255 | |
21 | |
22 urls = [] | |
23 with open(args[0], 'r') as f: | |
24 for url in f.readlines(): | |
25 url = url.strip() | |
26 if not re.match('(.+)://', url): | |
27 url = 'http://%s' % url | |
28 urls.append(url) | |
29 | |
30 options.extra_browser_args.append('--enable-gpu-benchmarking') | |
31 browser_to_create = chrome_remote_control.FindBrowser(options) | |
32 if not browser_to_create: | |
33 sys.stderr.write('No browser found! Supported types: %s' % | |
34 chrome_remote_control.GetAllAvailableBrowserTypes(options)) | |
35 return 255 | |
36 with browser_to_create.Create() as b: | |
37 with b.ConnectToNthTab(0) as tab: | |
38 # Check browser for benchmark API. Can only be done on non-chrome URLs. | |
39 tab.page.Navigate('http://www.google.com') | |
40 import time | |
41 time.sleep(2) | |
42 tab.WaitForDocumentReadyStateToBeComplete() | |
43 if tab.runtime.Evaluate('window.chrome.gpuBenchmarking === undefined'): | |
44 print 'Browser does not support gpu benchmarks API.' | |
45 return 255 | |
46 | |
47 if tab.runtime.Evaluate( | |
48 'window.chrome.gpuBenchmarking.runRenderingBenchmarks === undefined'): | |
49 print 'Browser does not support rendering benchmarks API.' | |
50 return 255 | |
51 | |
52 # Run the test. :) | |
53 first_line = [] | |
54 def DumpResults(url, results): | |
55 if len(first_line) == 0: | |
56 cols = ['url'] | |
57 for r in results: | |
58 cols.append(r['benchmark']) | |
59 print ','.join(cols) | |
60 first_line.append(0) | |
61 cols = [url] | |
62 for r in results: | |
63 cols.append(str(r['result'])) | |
64 print ','.join(cols) | |
65 | |
66 for u in urls: | |
67 tab.page.Navigate(u) | |
68 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() | |
69 results = tab.runtime.Evaluate( | |
70 'window.chrome.gpuBenchmarking.runRenderingBenchmarks();') | |
71 DumpResults(url, results) | |
72 | |
73 return 0 | |
74 | |
75 if __name__ == '__main__': | |
76 sys.exit(Main(sys.argv[1:])) | |
OLD | NEW |