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

Side by Side Diff: tests/compiler/dart2js/http_test.dart

Issue 557383002: dart2js: Support https. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/compiler/dart2js/http_launch_data/pkcert/key4.db ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 // Test: 5 // Test:
6 // *) Compiling a script fetched over HTTP. 6 // *) Compiling a script fetched over HTTP.
7 // *) Importing a library fetched over HTTP. 7 // *) Importing a library fetched over HTTP.
8 // *) Automatically resolving package_root when script is fetched over HTTP. 8 // *) Automatically resolving package_root when script is fetched over HTTP.
9 9
10 library http_launch_test; 10 library http_launch_test;
11 11
12 import 'dart:async'; 12 import 'dart:async';
13 import 'dart:io'; 13 import 'dart:io';
14 import 'package:async_helper/async_helper.dart'; 14 import 'package:async_helper/async_helper.dart';
15 import 'package:expect/expect.dart'; 15 import 'package:expect/expect.dart';
16 import 'package:path/path.dart' as path; 16 import 'package:path/path.dart' as path;
17 17
18 Uri pathOfData = Platform.script.resolve('http_launch_data/'); 18 Uri pathOfData = Platform.script.resolve('http_launch_data/');
19 Uri pathOfPkcert = pathOfData.resolve('pkcert');
19 int port; 20 int port;
20 Directory tempDir; 21 Directory tempDir;
21 String outFilePath; 22 String outFilePath;
23 String scheme;
22 24
23 _sendNotFound(HttpResponse response) { 25 _sendNotFound(HttpResponse response) {
24 response.statusCode = HttpStatus.NOT_FOUND; 26 response.statusCode = HttpStatus.NOT_FOUND;
25 response.close(); 27 response.close();
26 } 28 }
27 29
28 Future handleRequest(HttpRequest request) { 30 Future handleRequest(HttpRequest request) {
29 final String path = request.uri.path.substring(1); 31 final String path = request.uri.path.substring(1);
30 final Uri requestPath = pathOfData.resolve(path); 32 final Uri requestPath = pathOfData.resolve(path);
31 final File file = new File(requestPath.toFilePath()); 33 final File file = new File(requestPath.toFilePath());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 72 }
71 73
72 Future testNonHttp() { 74 Future testNonHttp() {
73 String inFilePath = pathOfData.resolve('http_launch_main.dart').toFilePath(); 75 String inFilePath = pathOfData.resolve('http_launch_main.dart').toFilePath();
74 List<String> args = [inFilePath, "--out=" + outFilePath]; 76 List<String> args = [inFilePath, "--out=" + outFilePath];
75 return launchDart2Js(args) 77 return launchDart2Js(args)
76 .then(check) 78 .then(check)
77 .then((_) { cleanup(); }); 79 .then((_) { cleanup(); });
78 } 80 }
79 81
80 Future testHttp() { 82 Future testHttpMain() {
81 String inFilePath = 'http://127.0.0.1:$port/http_launch_main.dart'; 83 String inFilePath = '$scheme://127.0.0.1:$port/http_launch_main.dart';
Bill Hesse 2014/09/11 08:08:40 The only uses of scheme and port are in the expres
floitsch 2014/09/11 13:37:40 Done.
82 List<String> args = [inFilePath, "--out=" + outFilePath]; 84 List<String> args = [inFilePath, "--out=" + outFilePath];
83 return launchDart2Js(args) 85 return launchDart2Js(args)
84 .then(check) 86 .then(check)
85 .then((_) { cleanup(); }); 87 .then((_) { cleanup(); });
86 } 88 }
87 89
88 Future testHttpLib() { 90 Future testHttpLib() {
89 File file = new File(path.join(tempDir.path, "in.dart")); 91 File file = new File(path.join(tempDir.path, "in.dart"));
90 file.writeAsStringSync(""" 92 file.writeAsStringSync("""
91 import 'http://127.0.0.1:$port/lib1.dart'; 93 import '$scheme://127.0.0.1:$port/lib1.dart';
92 main() { print(foo()); } 94 main() { print(foo()); }
93 """); 95 """);
94 String inFilePath = file.path; 96 String inFilePath = file.path;
95 List<String> args = [inFilePath, "--out=" + outFilePath]; 97 List<String> args = [inFilePath, "--out=" + outFilePath];
96 return launchDart2Js(args) 98 return launchDart2Js(args)
97 .then(check) 99 .then(check)
98 .whenComplete(file.deleteSync) 100 .whenComplete(file.deleteSync)
99 .then((_) { cleanup(); }); 101 .then((_) { cleanup(); });
100 } 102 }
101 103
102 Future testHttpPackage() { 104 Future testHttpPackage() {
103 String inFilePath = 105 String inFilePath =
104 pathOfData.resolve('http_launch_main_package.dart').toFilePath(); 106 pathOfData.resolve('http_launch_main_package.dart').toFilePath();
105 String packageRoot = 'http://127.0.0.1:$port/packages/'; 107 String packageRoot = '$scheme://127.0.0.1:$port/packages/';
106 List<String> args = [inFilePath, 108 List<String> args = [inFilePath,
107 "--out=" + outFilePath, 109 "--out=" + outFilePath,
108 "--package-root=" + packageRoot]; 110 "--package-root=" + packageRoot];
109 return launchDart2Js(args) 111 return launchDart2Js(args)
110 .then(check) 112 .then(check)
111 .then((_) { cleanup(); }); 113 .then((_) { cleanup(); });
112 } 114 }
113 115
114 Future testBadHttp() { 116 Future testBadHttp() {
115 File file = new File(path.join(tempDir.path, "in_bad.dart")); 117 File file = new File(path.join(tempDir.path, "in_bad.dart"));
116 file.writeAsStringSync(""" 118 file.writeAsStringSync("""
117 import 'http://127.0.0.1:$port/not_existing.dart'; 119 import '$scheme://127.0.0.1:$port/not_existing.dart';
118 main() { print(foo()); } 120 main() { print(foo()); }
119 """); 121 """);
120 String inFilePath = file.path; 122 String inFilePath = file.path;
121 List<String> args = [inFilePath, "--out=" + outFilePath]; 123 List<String> args = [inFilePath, "--out=" + outFilePath];
122 return launchDart2Js(args) 124 return launchDart2Js(args)
123 .then((pr) => checkNotFound(pr, "not_existing.dart")) 125 .then((pr) => checkNotFound(pr, "not_existing.dart"))
124 .whenComplete(file.deleteSync) 126 .whenComplete(file.deleteSync)
125 .then((_) { cleanup(); }); 127 .then((_) { cleanup(); });
126 } 128 }
127 129
128 Future testBadHttp2() { 130 Future testBadHttp2() {
129 String inFilePath = 'http://127.0.0.1:$port/not_found.dart'; 131 String inFilePath = '$scheme://127.0.0.1:$port/not_found.dart';
130 List<String> args = [inFilePath, "--out=" + outFilePath]; 132 List<String> args = [inFilePath, "--out=" + outFilePath];
131 return launchDart2Js(args) 133 return launchDart2Js(args)
132 .then((processResult) => checkNotFound(processResult, "not_found.dart")) 134 .then((processResult) => checkNotFound(processResult, "not_found.dart"))
133 .then((_) { cleanup(); }); 135 .then((_) { cleanup(); });
134 } 136 }
135 137
136 serverRunning(HttpServer server) { 138 serverRunning(HttpServer server) {
137 port = server.port; 139 port = server.port;
138 tempDir = Directory.systemTemp.createTempSync('directory_test'); 140 tempDir = Directory.systemTemp.createTempSync('directory_test');
139 outFilePath = path.join(tempDir.path, "out.js"); 141 outFilePath = path.join(tempDir.path, "out.js");
140 142
141 asyncStart(); 143 asyncStart();
142 server.listen(handleRequest); 144 server.listen(handleRequest);
143 new Future.value() 145 return new Future.value()
Bill Hesse 2014/09/11 08:08:40 You could make the tests return their input, and s
floitsch 2014/09/11 13:37:40 I don't like to return things that don't make sens
144 .then((_) => cleanup()) // Make sure we start fresh. 146 .then((_) => cleanup()) // Make sure we start fresh.
145 .then((_) => testNonHttp()) 147 .then((_) => testNonHttp())
146 .then((_) => testHttp()) 148 .then((_) => testHttpMain())
147 .then((_) => testHttpLib()) 149 .then((_) => testHttpLib())
148 .then((_) => testHttpPackage()) 150 .then((_) => testHttpPackage())
149 .then((_) => testBadHttp()) 151 .then((_) => testBadHttp())
150 .then((_) => testBadHttp2()) 152 .then((_) => testBadHttp2())
151 .whenComplete(() => tempDir.delete(recursive: true)) 153 .whenComplete(() => tempDir.delete(recursive: true))
152 .whenComplete(server.close) 154 .whenComplete(server.close)
153 .then((_) => asyncEnd()); 155 .then((_) => asyncEnd());
154 } 156 }
155 157
158 Future testHttp() {
159 scheme = "http";
160 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning);
161 }
162
163 void initializeSSL() {
164 String testPkcertDatabase = pathOfPkcert.toFilePath();
165 SecureSocket.initialize(database: testPkcertDatabase,
166 password: 'dartdart');
167 }
168
169 Future testHttps() {
170 initializeSSL();
171 scheme = "https";
172 return HttpServer.bindSecure(InternetAddress.LOOPBACK_IP_V4,
173 0,
174 certificateName: 'localhost_cert')
175 .then(serverRunning);
176 }
177
156 main() { 178 main() {
157 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning); 179 asyncStart();
180 testHttp()
181 .then((_) => testHttps)
182 .whenComplete(asyncEnd);
158 } 183 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/http_launch_data/pkcert/key4.db ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698