Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: tools/testing/dart/browser_perf_testing/lib/browser_perf_testing.dart

Issue 199003005: Package-ify Dromaeo and browser controller functionality (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/html/dromaeo_smoke_test.dart ('k') | tools/testing/dart/perf_test_controller.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Dart script to launch performance tests without WebDriver/Selenium.
6 ///
7 /// WARNING: Although this is laid out like a package, it is not really a
8 /// package since it relies on test.dart files!
9 library browser_perf_testing;
10
11 import '../../browser_controller.dart';
12 import '../../utils.dart';
13 import '../../http_server.dart';
14 import 'dart:async';
15 import 'dart:io';
16 import 'dart:convert';
17 import 'package:path/path.dart' as path;
18 import 'package:args/args.dart' as args_parser;
19
20 final String ADDRESS = '127.0.0.1';
21
22 /// A map that is passed to the testing framework to specify what ports the
23 /// browser controller runs on.
24 final Map SERVER_CONFIG = {
25 'test_driver_port': 0,
26 'test_driver_error_port': 0
27 };
28
29 void main (List<String> args) {
30 var options = _parseArguments(args);
31
32 // Start a server to serve the entire repo: the http server is available on
33 // window.location.port.
34 var servers = new TestingServers(
35 new Path('/Users/efortuna/dart-git2/dart/xcodebuild/ReleaseIA32'),
36 false, options['browser'], path.dirname(path.dirname(path.dirname(
37 path.dirname(path.dirname(path.dirname(Platform.script.path)))))));
38 servers.startServers(ADDRESS).then((_) {
39 _runPerfTests(options, servers);
40 });
41 }
42
43 /// Helper function to parse the arguments for this file.
44 Map _parseArguments(List<String> args) {
45 var parser = new args_parser.ArgParser();
46 parser.addOption('browser', defaultsTo: 'chrome', help: 'Name of the browser'
47 ' to run this test with.');
48 parser.addOption('termination_test_file', defaultsTo:
49 '/root_dart/samples/third_party/dromaeo/dromaeo_end_condition.js',
50 help: 'Path to a javascript file that contains the function '
51 '"testIsComplete" tests whether the performance test has finished '
52 'running. This is in a form that can be served up by '
53 'http_server.dart, so it begins with /root_dart or some other server '
54 'understood prefix.');
55 parser.addOption('test_path', defaultsTo:
56 '/root_dart/samples/third_party/dromaeo/index-js.html?jsANDqueryORjs'
57 'ANDtraverseORjsANDattributes', help: 'Path to the performance test we '
58 'wish to run. This is in a form that can be served up by '
59 'http_server.dart, so it begins with /root_dart or some other server '
60 'understood prefix.');
61 parser.addOption('checked', defaultsTo: false,
62 help: 'Run this test in checked mode.');
63 parser.addFlag('help', abbr: 'h', negatable: false, callback: (help) {
64 if (help) {
65 print(parser.getUsage());
66 exit(0);
67 };
68 });
69 parser.addOption('timeout', defaultsTo: 300,
70 help: 'Maximum amount of time to let a test run, in seconds.');
71 return parser.parse(args);
72 }
73
74 void _runPerfTests(Map options, TestingServers servers) {
75 var browserName = options['browser'];
76
77 var testRunner = new BrowserTestRunner(SERVER_CONFIG, ADDRESS, browserName, 1,
78 checkedMode: options['checked'],
79 testingServer: new BrowserPerfTestingServer(browserName,
80 options['termination_test_file'], servers.port));
81
82 var url = 'http://$ADDRESS:${servers.port}${options["test_path"]}';
83
84 BrowserTest browserTest = new BrowserTest(url,
85 (BrowserTestOutput output) {
86 var eventQueue = JSON.decode(output.lastKnownMessage);
87 var lastEvent = eventQueue.last;
88 var lines = lastEvent['value'].split('\n');
89 for (var line in lines) {
90 print(line);
91 }
92 testRunner.terminate();
93 servers.stopServers();
94 }, options['timeout']);
95
96 testRunner.start().then((started) {
97 if (started) {
98 testRunner.queueTest(browserTest);
99 } else {
100 print("Issue starting browser test runner $started");
101 exit(1);
102 }
103 });
104 }
105
106 /// Server for controlling and running performance tests. Note the tests
107 /// themselves are served on the local file system (to eliminate any additional
108 /// potential sources of lag), but we need a server to communicate when the test
109 /// is done.
110 class BrowserPerfTestingServer extends BrowserTestingServer {
111 // Path to the script containing the ending condition of the performance test,
112 // in the form of /root_dart, /root_build, or some other, as per the form of
113 // url expected from http_server.dart.
114 String endConditionScript;
115 /// Port number to access the server serving the whole Dart repository.
116 int repoPort;
117
118 BrowserPerfTestingServer(String browserName, this.endConditionScript,
119 this.repoPort) : super(SERVER_CONFIG, ADDRESS,
120 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName));
121
122 /// We create a slightly modified version of the original browser_controller
123 /// driver page.
124 String getDriverPage(String browserId) {
125 var orig = super.getDriverPage(browserId);
126 //TODO(efortuna): Hacky!
127 var insertIndex = orig.indexOf('<script type');
128 var otherInsert = orig.indexOf('} else {',
129 orig.indexOf('if (isStatusUpdate)'));
130 var result = orig.substring(0, insertIndex) + """
131 <!-- To create a performance test, you must write a script that provides an
132 ending condition for the particular test, in the form /root_dart/foo (or
133 whatever base from http_server). // TODO not hard code.-->
134 <script src="http://$localIp:$repoPort$endConditionScript"></script>
135 """ + orig.substring(insertIndex, otherInsert) + """
136 if (testIsComplete(msg)) {
137 var obj = new Object();
138 obj['message'] = msg;
139 obj['is_first_message'] = false;
140 obj['is_status_update'] = false;
141 obj['is_done'] = true;
142 window.postMessage(JSON.stringify(obj), '*');
143 }""" + orig.substring(otherInsert);
144 return result;
145 }
146 }
OLDNEW
« no previous file with comments | « tests/html/dromaeo_smoke_test.dart ('k') | tools/testing/dart/perf_test_controller.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698