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

Side by Side Diff: tools/testing/dart/http_server.dart

Issue 11896031: Change the location of the output directory of generated tests to be inside output directory, but n… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library http_server; 5 library http_server;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 import 'test_suite.dart'; // For TestUtils. 9 import 'test_suite.dart'; // For TestUtils.
10 // TODO(efortuna): Rewrite to not use the args library and simply take an 10 // TODO(efortuna): Rewrite to not use the args library and simply take an
(...skipping 21 matching lines...) Expand all
32 print(parser.getUsage()); 32 print(parser.getUsage());
33 } else { 33 } else {
34 // Pretend we're running test.dart so that TestUtils doesn't get confused 34 // Pretend we're running test.dart so that TestUtils doesn't get confused
35 // about the "current directory." This is only used if we're trying to run 35 // about the "current directory." This is only used if we're trying to run
36 // this file independently for local testing. 36 // this file independently for local testing.
37 TestUtils.testScriptPath = new Path(new Options().script) 37 TestUtils.testScriptPath = new Path(new Options().script)
38 .directoryPath 38 .directoryPath
39 .join(new Path('../../test.dart')) 39 .join(new Path('../../test.dart'))
40 .canonicalize() 40 .canonicalize()
41 .toNativePath(); 41 .toNativePath();
42 TestingServerRunner.setPackageRootDir({'mode': args['mode'], 42 var conf = {'mode': args['mode'],
43 'arch': args['arch'], 'system': Platform.operatingSystem, 43 'arch': args['arch'], 'system': Platform.operatingSystem,
44 'build_directory': ''}); 44 'build_directory': ''};
45 45 TestingServerRunner.setPackageRootDir(conf);
46 TestingServerRunner.setBuildDir(conf);
46 TestingServerRunner.startHttpServer('127.0.0.1', 47 TestingServerRunner.startHttpServer('127.0.0.1',
47 port: int.parse(args['port'])); 48 port: int.parse(args['port']));
48 print('Server listening on port ' 49 print('Server listening on port '
49 '${TestingServerRunner.serverList[0].port}.'); 50 '${TestingServerRunner.serverList[0].port}.');
50 TestingServerRunner.startHttpServer('127.0.0.1', 51 TestingServerRunner.startHttpServer('127.0.0.1',
51 allowedPort: TestingServerRunner.serverList[0].port, port: 52 allowedPort: TestingServerRunner.serverList[0].port, port:
52 int.parse(args['crossOriginPort'])); 53 int.parse(args['crossOriginPort']));
53 print( 54 print(
54 'Server listening on port ${TestingServerRunner.serverList[1].port}.'); 55 'Server listening on port ${TestingServerRunner.serverList[1].port}.');
55 } 56 }
56 } 57 }
57 /** 58 /**
58 * Runs a set of servers that are initialized specifically for the needs of our 59 * Runs a set of servers that are initialized specifically for the needs of our
59 * test framework, such as dealing with package-root. 60 * test framework, such as dealing with package-root.
60 */ 61 */
61 class TestingServerRunner { 62 class TestingServerRunner {
62 static List serverList = []; 63 static List serverList = [];
63 static Path _packageRootDir = null; 64 static Path _packageRootDir = null;
65 static Path _buildDirectory = null;
64 66
65 // Added as a getter so that the function will be called again each time the 67 // Added as a getter so that the function will be called again each time the
66 // default request handler closure is executed. 68 // default request handler closure is executed.
67 static Path get packageRootDir => _packageRootDir; 69 static Path get packageRootDir => _packageRootDir;
70 static Path get buildDirectory => _buildDirectory;
68 71
69 static setPackageRootDir(Map configuration) { 72 static setPackageRootDir(Map configuration) {
70 _packageRootDir = TestUtils.currentWorkingDirectory.join( 73 _packageRootDir = TestUtils.currentWorkingDirectory.join(
71 new Path(TestUtils.buildDir(configuration))); 74 new Path(TestUtils.buildDir(configuration)));
75 print(_packageRootDir);
kustermann 2013/01/29 12:29:30 Why are these "print()"'s here? In case we wanna
ricow1 2013/01/30 14:38:42 left over debug info, removed
76 }
77
78 static setBuildDir(Map configuration) {
79 _buildDirectory = new Path(TestUtils.buildDir(configuration));
80 print(_buildDirectory);
72 } 81 }
73 82
74 static startHttpServer(String host, {int allowedPort:-1, int port: 0}) { 83 static startHttpServer(String host, {int allowedPort:-1, int port: 0}) {
75 var basePath = TestUtils.dartDir(); 84 var basePath = TestUtils.dartDir();
76 var httpServer = new HttpServer(); 85 var httpServer = new HttpServer();
77 var packagesDirName = 'packages'; 86 var packagesDirName = 'packages';
78 httpServer.onError = (e) { 87 httpServer.onError = (e) {
79 // TODO(ricow): Once we have a debug log we should write this out there. 88 // TODO(ricow): Once we have a debug log we should write this out there.
80 print('Test http server error: $e'); 89 print('Test http server error: $e');
81 }; 90 };
82 httpServer.defaultRequestHandler = (request, resp) { 91 httpServer.defaultRequestHandler = (request, resp) {
83 var requestPath = new Path(request.path.substring(1)).canonicalize(); 92 var requestPath = new Path(request.path.substring(1)).canonicalize();
93 if (requestPath.toString().startsWith("tests/html/xhr")) print(requestPath );
kustermann 2013/01/29 12:29:30 long line -- finally I can complain about this as
ricow1 2013/01/30 14:38:42 Removed
84 var path = basePath.join(requestPath); 94 var path = basePath.join(requestPath);
85 var file = new File(path.toNativePath()); 95 var file = new File(path.toNativePath());
86 96 // Since the build directory may not be located directly beneath the dart
97 // root directory (if we pass it in, e.g., for dartium testing) we serve
98 // files from the build directory explicitly. Please note that if
99 // buildDirectory has the same name as a directory inside the dart repo
100 // we will server files from the buildDirectory.
101 if (path.toString().startsWith(buildDirectory.toString())) {
102 file = new File(path.toNativePath());
103 }
87 if (requestPath.segments().contains(packagesDirName)) { 104 if (requestPath.segments().contains(packagesDirName)) {
88 // Essentially implement the packages path rewriting, so we don't have 105 // Essentially implement the packages path rewriting, so we don't have
89 // to pass environment variables to the browsers. 106 // to pass environment variables to the browsers.
90 var requestPathStr = requestPath.toNativePath().substring( 107 var requestPathStr = requestPath.toNativePath().substring(
91 requestPath.toNativePath().indexOf(packagesDirName)); 108 requestPath.toNativePath().indexOf(packagesDirName));
92 path = packageRootDir.append(requestPathStr); 109 path = packageRootDir.append(requestPathStr);
93 file = new File(path.toNativePath()); 110 file = new File(path.toNativePath());
94 } 111 }
95 file.exists().then((exists) { 112 file.exists().then((exists) {
96 if (exists) { 113 if (exists) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 }); 153 });
137 154
138 httpServer.listen(host, port); 155 httpServer.listen(host, port);
139 serverList.add(httpServer); 156 serverList.add(httpServer);
140 } 157 }
141 158
142 static terminateHttpServers() { 159 static terminateHttpServers() {
143 for (var server in serverList) server.close(); 160 for (var server in serverList) server.close();
144 } 161 }
145 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698