| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// A tool to gather coverage data from an app generated with dart2js. This | 5 /// A tool to gather coverage data from an app generated with dart2js. This |
| 6 /// depends on code that has been landed in the bleeding_edge version of dart2js | 6 /// depends on code that has been landed in the bleeding_edge version of dart2js |
| 7 /// and that we expect to become publicly visible in version 0.13.0 of the Dart | 7 /// and that we expect to become publicly visible in version 0.13.0 of the Dart |
| 8 /// SDK). | 8 /// SDK). |
| 9 /// | 9 /// |
| 10 /// This tool starts a server that answers to mainly 2 requests: | 10 /// This tool starts a server that answers to mainly 2 requests: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 ? '<html><script src="$baseJsName"></script>' | 129 ? '<html><script src="$baseJsName"></script>' |
| 130 : await new File(htmlPath).readAsString(); | 130 : await new File(htmlPath).readAsString(); |
| 131 return new shelf.Response.ok(contents, headers: HTML_HEADERS); | 131 return new shelf.Response.ok(contents, headers: HTML_HEADERS); |
| 132 } | 132 } |
| 133 | 133 |
| 134 if (urlPath == _expectedPath(baseJsName)) { | 134 if (urlPath == _expectedPath(baseJsName)) { |
| 135 return new shelf.Response.ok(jsCode, headers: JS_HEADERS); | 135 return new shelf.Response.ok(jsCode, headers: JS_HEADERS); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Handle POST requests to record coverage data, and GET requests to display | 138 // Handle POST requests to record coverage data, and GET requests to display |
| 139 // the currently coverage resutls. | 139 // the currently coverage results. |
| 140 if (urlPath == _expectedPath('coverage')) { | 140 if (urlPath == _expectedPath('coverage')) { |
| 141 if (request.method == 'GET') { | 141 if (request.method == 'GET') { |
| 142 return new shelf.Response.ok(_serializedData, headers: TEXT_HEADERS); | 142 return new shelf.Response.ok(_serializedData, headers: TEXT_HEADERS); |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (request.method == 'POST') { | 145 if (request.method == 'POST') { |
| 146 _record(JSON.decode(await request.readAsString())); | 146 _record(JSON.decode(await request.readAsString())); |
| 147 return new shelf.Response.ok("Thanks!"); | 147 return new shelf.Response.ok("Thanks!"); |
| 148 } | 148 } |
| 149 } | 149 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 _adjustRequestUrl(String code, String prefix) { | 187 _adjustRequestUrl(String code, String prefix) { |
| 188 var newUrl = prefix == '' ? 'coverage' : '$prefix/coverage'; | 188 var newUrl = prefix == '' ? 'coverage' : '$prefix/coverage'; |
| 189 return code.replaceFirst('"/coverage_uri_to_amend_by_server"', | 189 return code.replaceFirst('"/coverage_uri_to_amend_by_server"', |
| 190 '"/$newUrl" /*url-prefix updated!*/'); | 190 '"/$newUrl" /*url-prefix updated!*/'); |
| 191 } | 191 } |
| 192 | 192 |
| 193 const HTML_HEADERS = const {'content-type': 'text/html'}; | 193 const HTML_HEADERS = const {'content-type': 'text/html'}; |
| 194 const JS_HEADERS = const {'content-type': 'text/javascript'}; | 194 const JS_HEADERS = const {'content-type': 'text/javascript'}; |
| 195 const TEXT_HEADERS = const {'content-type': 'text/plain'}; | 195 const TEXT_HEADERS = const {'content-type': 'text/plain'}; |
| OLD | NEW |