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

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: Addressed comments. 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 int port;
20 Directory tempDir; 19 Directory tempDir;
21 String outFilePath; 20 String outFilePath;
22 21
23 _sendNotFound(HttpResponse response) { 22 _sendNotFound(HttpResponse response) {
24 response.statusCode = HttpStatus.NOT_FOUND; 23 response.statusCode = HttpStatus.NOT_FOUND;
25 response.close(); 24 response.close();
26 } 25 }
27 26
28 Future handleRequest(HttpRequest request) { 27 Future handleRequest(HttpRequest request) {
29 final String path = request.uri.path.substring(1); 28 final String path = request.uri.path.substring(1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 69 }
71 70
72 Future testNonHttp() { 71 Future testNonHttp() {
73 String inFilePath = pathOfData.resolve('http_launch_main.dart').toFilePath(); 72 String inFilePath = pathOfData.resolve('http_launch_main.dart').toFilePath();
74 List<String> args = [inFilePath, "--out=" + outFilePath]; 73 List<String> args = [inFilePath, "--out=" + outFilePath];
75 return launchDart2Js(args) 74 return launchDart2Js(args)
76 .then(check) 75 .then(check)
77 .then((_) { cleanup(); }); 76 .then((_) { cleanup(); });
78 } 77 }
79 78
80 Future testHttp() { 79 Future testHttpMain(String serverUrl) {
81 String inFilePath = 'http://127.0.0.1:$port/http_launch_main.dart'; 80 String inFilePath = '$serverUrl/http_launch_main.dart';
82 List<String> args = [inFilePath, "--out=" + outFilePath]; 81 List<String> args = [inFilePath, "--out=" + outFilePath];
83 return launchDart2Js(args) 82 return launchDart2Js(args)
84 .then(check) 83 .then(check)
85 .then((_) { cleanup(); }); 84 .then((_) { cleanup(); });
86 } 85 }
87 86
88 Future testHttpLib() { 87 Future testHttpLib(String serverUrl) {
89 File file = new File(path.join(tempDir.path, "in.dart")); 88 File file = new File(path.join(tempDir.path, "in.dart"));
90 file.writeAsStringSync(""" 89 file.writeAsStringSync("""
91 import 'http://127.0.0.1:$port/lib1.dart'; 90 import '$serverUrl/lib1.dart';
92 main() { print(foo()); } 91 main() { print(foo()); }
93 """); 92 """);
94 String inFilePath = file.path; 93 String inFilePath = file.path;
95 List<String> args = [inFilePath, "--out=" + outFilePath]; 94 List<String> args = [inFilePath, "--out=" + outFilePath];
96 return launchDart2Js(args) 95 return launchDart2Js(args)
97 .then(check) 96 .then(check)
98 .whenComplete(file.deleteSync) 97 .whenComplete(file.deleteSync)
99 .then((_) { cleanup(); }); 98 .then((_) { cleanup(); });
100 } 99 }
101 100
102 Future testHttpPackage() { 101 Future testHttpPackage(String serverUrl) {
103 String inFilePath = 102 String inFilePath =
104 pathOfData.resolve('http_launch_main_package.dart').toFilePath(); 103 pathOfData.resolve('http_launch_main_package.dart').toFilePath();
105 String packageRoot = 'http://127.0.0.1:$port/packages/'; 104 String packageRoot = '$serverUrl/packages/';
106 List<String> args = [inFilePath, 105 List<String> args = [inFilePath,
107 "--out=" + outFilePath, 106 "--out=" + outFilePath,
108 "--package-root=" + packageRoot]; 107 "--package-root=" + packageRoot];
109 return launchDart2Js(args) 108 return launchDart2Js(args)
110 .then(check) 109 .then(check)
111 .then((_) { cleanup(); }); 110 .then((_) { cleanup(); });
112 } 111 }
113 112
114 Future testBadHttp() { 113 Future testBadHttp(String serverUrl) {
115 File file = new File(path.join(tempDir.path, "in_bad.dart")); 114 File file = new File(path.join(tempDir.path, "in_bad.dart"));
116 file.writeAsStringSync(""" 115 file.writeAsStringSync("""
117 import 'http://127.0.0.1:$port/not_existing.dart'; 116 import '$serverUrl/not_existing.dart';
118 main() { print(foo()); } 117 main() { print(foo()); }
119 """); 118 """);
120 String inFilePath = file.path; 119 String inFilePath = file.path;
121 List<String> args = [inFilePath, "--out=" + outFilePath]; 120 List<String> args = [inFilePath, "--out=" + outFilePath];
122 return launchDart2Js(args) 121 return launchDart2Js(args)
123 .then((pr) => checkNotFound(pr, "not_existing.dart")) 122 .then((pr) => checkNotFound(pr, "not_existing.dart"))
124 .whenComplete(file.deleteSync) 123 .whenComplete(file.deleteSync)
125 .then((_) { cleanup(); }); 124 .then((_) { cleanup(); });
126 } 125 }
127 126
128 Future testBadHttp2() { 127 Future testBadHttp2(String serverUrl) {
129 String inFilePath = 'http://127.0.0.1:$port/not_found.dart'; 128 String inFilePath = '$serverUrl/not_found.dart';
130 List<String> args = [inFilePath, "--out=" + outFilePath]; 129 List<String> args = [inFilePath, "--out=" + outFilePath];
131 return launchDart2Js(args) 130 return launchDart2Js(args)
132 .then((processResult) => checkNotFound(processResult, "not_found.dart")) 131 .then((processResult) => checkNotFound(processResult, "not_found.dart"))
133 .then((_) { cleanup(); }); 132 .then((_) { cleanup(); });
134 } 133 }
135 134
136 serverRunning(HttpServer server) { 135 serverRunning(HttpServer server, String scheme) {
137 port = server.port;
138 tempDir = Directory.systemTemp.createTempSync('directory_test'); 136 tempDir = Directory.systemTemp.createTempSync('directory_test');
139 outFilePath = path.join(tempDir.path, "out.js"); 137 outFilePath = path.join(tempDir.path, "out.js");
138 int port = server.port;
139 String serverUrl = "$scheme://127.0.0.1:$port";
140 140
141 asyncStart(); 141 asyncStart();
142 server.listen(handleRequest); 142 server.listen(handleRequest);
143 new Future.value() 143 return new Future.value()
144 .then((_) => cleanup()) // Make sure we start fresh. 144 .then((_) => cleanup()) // Make sure we start fresh.
145 .then((_) => testNonHttp()) 145 .then((_) => testNonHttp())
146 .then((_) => testHttp()) 146 .then((_) => testHttpMain(serverUrl))
147 .then((_) => testHttpLib()) 147 .then((_) => testHttpLib(serverUrl))
148 .then((_) => testHttpPackage()) 148 .then((_) => testHttpPackage(serverUrl))
149 .then((_) => testBadHttp()) 149 .then((_) => testBadHttp(serverUrl))
150 .then((_) => testBadHttp2()) 150 .then((_) => testBadHttp2(serverUrl))
151 .whenComplete(() => tempDir.delete(recursive: true)) 151 .whenComplete(() => tempDir.delete(recursive: true))
152 .whenComplete(server.close) 152 .whenComplete(server.close)
153 .then((_) => asyncEnd()); 153 .then((_) => asyncEnd());
154 } 154 }
155 155
156 Future testHttp() {
157 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0)
158 .then((HttpServer server) => serverRunning(server, "http"));
159 }
160
161 void initializeSSL() {
162 Uri pathOfPkcert = pathOfData.resolve('pkcert');
163 String testPkcertDatabase = pathOfPkcert.toFilePath();
164 SecureSocket.initialize(database: testPkcertDatabase,
165 password: 'dartdart');
166 }
167
168 Future testHttps() {
169 initializeSSL();
170 return HttpServer.bindSecure(InternetAddress.LOOPBACK_IP_V4,
171 0,
172 certificateName: 'localhost_cert')
173 .then((HttpServer server) => serverRunning(server, "https"));
174 }
175
156 main() { 176 main() {
157 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning); 177 asyncStart();
178 testHttp()
179 .then((_) => testHttps)
180 .whenComplete(asyncEnd);
158 } 181 }
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