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

Unified Diff: tests/standalone/src/io/HttpParserTest.dart

Issue 9956062: Refactor the close and error handling of HTTP connections (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 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 side-by-side diff with in-line comments
Download patch
Index: tests/standalone/src/io/HttpParserTest.dart
diff --git a/tests/standalone/src/io/HttpParserTest.dart b/tests/standalone/src/io/HttpParserTest.dart
index c8b1ca5a56ca8e7ff8de47428bbcc557330d9614..c20c59616c64e9c330f89825032a1a1018108046 100644
--- a/tests/standalone/src/io/HttpParserTest.dart
+++ b/tests/standalone/src/io/HttpParserTest.dart
@@ -54,7 +54,10 @@ class HttpParserTest {
Expect.isTrue(headersCompleteCalled);
bytesReceived += data.length;
};
- httpParser.dataEnd = () => dataEndCalled = true;
+ httpParser.dataEnd = (close) {
+ Expect.isFalse(close);
+ dataEndCalled = true;
+ };
headersCompleteCalled = false;
dataEndCalled = false;
@@ -128,10 +131,12 @@ class HttpParserTest {
Map expectedHeaders = null,
bool chunked = false,
bool close = false,
- String responseToMethod = null]) {
+ String responseToMethod = null,
+ bool connectionClose = false]) {
_HttpParser httpParser;
bool headersCompleteCalled;
bool dataEndCalled;
+ bool dataEndClose;
int statusCode;
String reasonPhrase;
Map headers;
@@ -170,10 +175,14 @@ class HttpParserTest {
Expect.isTrue(headersCompleteCalled);
bytesReceived += data.length;
};
- httpParser.dataEnd = () => dataEndCalled = true;
+ httpParser.dataEnd = (close) {
+ dataEndCalled = true;
+ dataEndClose = close;
+ };
headersCompleteCalled = false;
dataEndCalled = false;
+ dataEndClose = null;
statusCode = -1;
reasonPhrase = null;
headers = new Map();
@@ -194,6 +203,8 @@ class HttpParserTest {
Expect.isTrue(headersCompleteCalled);
Expect.equals(expectedBytesReceived, bytesReceived);
Expect.isTrue(dataEndCalled);
+ if (close) Expect.isTrue(dataEndClose);
+ Expect.equals(dataEndClose, connectionClose);
}
// Test parsing the request three times delivering the data in
@@ -323,6 +334,14 @@ Content-Length: 10\r
expectedContentLength: 10,
expectedBytesReceived: 10);
+ // Test connection close header.
+ request = """
+GET /test HTTP/1.1\r
+Connection: close\r
+\r
+""";
+ _testParseRequest(request, "GET", "/test");
+
// Test chunked encoding.
request = """
POST /test HTTP/1.1\r
@@ -495,6 +514,19 @@ Transfer-Encoding: chunked\r
expectedBytesReceived: 57,
chunked: true);
+ // Test connection close header.
+ response = """
+HTTP/1.1 200 OK\r
+Content-Length: 0\r
+Connection: close\r
+\r
+""";
+ _testParseResponse(response,
+ 200,
+ "OK",
+ expectedContentLength: 0,
+ connectionClose: true);
+
// Test HTTP response without any transfer length indications
// where closing the connections indicates end of body.
response = """
@@ -508,7 +540,8 @@ HTTP/1.1 200 OK\r
"OK",
expectedContentLength: -1,
expectedBytesReceived: 59,
- close: true);
+ close: true,
+ connectionClose: true);
}
static void testParseInvalidRequest() {

Powered by Google App Engine
This is Rietveld 408576698