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

Side by Side Diff: test/request_test.dart

Issue 837193005: pkg/shelf: formatted code (Closed) Base URL: https://github.com/dart-lang/shelf.git@master
Patch Set: nits Created 5 years, 11 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
« no previous file with comments | « test/pipeline_test.dart ('k') | test/response_test.dart » ('j') | 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 library shelf.request_test; 5 library shelf.request_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:shelf/shelf.dart'; 9 import 'package:shelf/shelf.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 10 matching lines...) Expand all
21 var request = new Request('GET', LOCALHOST_URI); 21 var request = new Request('GET', LOCALHOST_URI);
22 expect(request.protocolVersion, '1.1'); 22 expect(request.protocolVersion, '1.1');
23 }); 23 });
24 24
25 test('provide non-default protocolVersion', () { 25 test('provide non-default protocolVersion', () {
26 var request = new Request('GET', LOCALHOST_URI, protocolVersion: '1.0'); 26 var request = new Request('GET', LOCALHOST_URI, protocolVersion: '1.0');
27 expect(request.protocolVersion, '1.0'); 27 expect(request.protocolVersion, '1.0');
28 }); 28 });
29 29
30 test('requestedUri must be absolute', () { 30 test('requestedUri must be absolute', () {
31 expect(() => new Request('GET', Uri.parse('/path')), 31 expect(() => new Request('GET', Uri.parse('/path')), throwsArgumentError);
32 throwsArgumentError);
33 }); 32 });
34 33
35 test('if uri is null, scriptName must be null', () { 34 test('if uri is null, scriptName must be null', () {
36 expect(() => new Request('GET', Uri.parse('/path'), 35 expect(() => new Request('GET', Uri.parse('/path'),
37 scriptName: '/script/name'), throwsArgumentError); 36 scriptName: '/script/name'), throwsArgumentError);
38 }); 37 });
39 38
40 test('if scriptName is null, uri must be null', () { 39 test('if scriptName is null, uri must be null', () {
41 var relativeUri = new Uri(path: '/cool/beans.html'); 40 var relativeUri = new Uri(path: '/cool/beans.html');
42 expect(() => new Request('GET', Uri.parse('/path'), 41 expect(() => new Request('GET', Uri.parse('/path'), url: relativeUri),
43 url: relativeUri), throwsArgumentError); 42 throwsArgumentError);
44 }); 43 });
45 44
46 test('uri must be relative', () { 45 test('uri must be relative', () {
47 var relativeUri = Uri.parse('http://localhost/test'); 46 var relativeUri = Uri.parse('http://localhost/test');
48 47
49 expect(() => new Request('GET', LOCALHOST_URI, 48 expect(() => new Request('GET', LOCALHOST_URI,
50 url: relativeUri, scriptName: '/news'), 49 url: relativeUri, scriptName: '/news'), throwsArgumentError);
51 throwsArgumentError);
52 50
53 // NOTE: explicitly testing fragments due to Issue 18053 51 // NOTE: explicitly testing fragments due to Issue 18053
54 relativeUri = Uri.parse('http://localhost/test#fragment'); 52 relativeUri = Uri.parse('http://localhost/test#fragment');
55 53
56 expect(() => new Request('GET', LOCALHOST_URI, 54 expect(() => new Request('GET', LOCALHOST_URI,
57 url: relativeUri, scriptName: '/news'), 55 url: relativeUri, scriptName: '/news'), throwsArgumentError);
58 throwsArgumentError);
59 }); 56 });
60 57
61 test('uri and scriptName', () { 58 test('uri and scriptName', () {
62 var pathInfo = '/pages/page.html?utm_source=ABC123'; 59 var pathInfo = '/pages/page.html?utm_source=ABC123';
63 var scriptName = '/assets/static'; 60 var scriptName = '/assets/static';
64 var fullUrl = 'http://localhost/other_path/other_resource.asp'; 61 var fullUrl = 'http://localhost/other_path/other_resource.asp';
65 var request = new Request('GET', Uri.parse(fullUrl), 62 var request = new Request('GET', Uri.parse(fullUrl),
66 url: Uri.parse(pathInfo), scriptName: scriptName); 63 url: Uri.parse(pathInfo), scriptName: scriptName);
67 64
68 expect(request.scriptName, scriptName); 65 expect(request.scriptName, scriptName);
(...skipping 12 matching lines...) Expand all
81 expect(request.url.path, '/'); 78 expect(request.url.path, '/');
82 expect(request.url.query, ''); 79 expect(request.url.query, '');
83 }); 80 });
84 81
85 test('invalid url', () { 82 test('invalid url', () {
86 var testUrl = 'page'; 83 var testUrl = 'page';
87 var scriptName = '/assets/static'; 84 var scriptName = '/assets/static';
88 var fullUrl = 'http://localhost$scriptName$testUrl'; 85 var fullUrl = 'http://localhost$scriptName$testUrl';
89 86
90 expect(() => new Request('GET', Uri.parse(fullUrl), 87 expect(() => new Request('GET', Uri.parse(fullUrl),
91 url: Uri.parse(testUrl), scriptName: scriptName), 88 url: Uri.parse(testUrl), scriptName: scriptName),
92 throwsArgumentError); 89 throwsArgumentError);
93 }); 90 });
94 91
95 test('scriptName with no leading slash', () { 92 test('scriptName with no leading slash', () {
96 var pathInfo = '/page'; 93 var pathInfo = '/page';
97 var scriptName = 'assets/static'; 94 var scriptName = 'assets/static';
98 var fullUrl = 'http://localhost/assets/static/pages'; 95 var fullUrl = 'http://localhost/assets/static/pages';
99 96
100 expect(() => new Request('GET',Uri.parse(fullUrl), 97 expect(() => new Request('GET', Uri.parse(fullUrl),
101 url: Uri.parse(pathInfo), scriptName: scriptName), 98 url: Uri.parse(pathInfo), scriptName: scriptName),
102 throwsArgumentError); 99 throwsArgumentError);
103 100
104 pathInfo = '/assets/static/page'; 101 pathInfo = '/assets/static/page';
105 scriptName = '/'; 102 scriptName = '/';
106 fullUrl = 'http://localhost/assets/static/pages'; 103 fullUrl = 'http://localhost/assets/static/pages';
107 104
108 expect(() => new Request('GET',Uri.parse(fullUrl), 105 expect(() => new Request('GET', Uri.parse(fullUrl),
109 url: Uri.parse(pathInfo), scriptName: scriptName), 106 url: Uri.parse(pathInfo), scriptName: scriptName),
110 throwsArgumentError); 107 throwsArgumentError);
111 }); 108 });
112 109
113 test('scriptName that is only a slash', () { 110 test('scriptName that is only a slash', () {
114 var pathInfo = '/assets/static/page'; 111 var pathInfo = '/assets/static/page';
115 var scriptName = '/'; 112 var scriptName = '/';
116 var fullUrl = 'http://localhost/assets/static/pages'; 113 var fullUrl = 'http://localhost/assets/static/pages';
117 114
118 expect(() => new Request('GET',Uri.parse(fullUrl), 115 expect(() => new Request('GET', Uri.parse(fullUrl),
119 url: Uri.parse(pathInfo), scriptName: scriptName), 116 url: Uri.parse(pathInfo), scriptName: scriptName),
120 throwsArgumentError); 117 throwsArgumentError);
121 }); 118 });
122 }); 119 });
123 120
124 group("ifModifiedSince", () { 121 group("ifModifiedSince", () {
125 test("is null without an If-Modified-Since header", () { 122 test("is null without an If-Modified-Since header", () {
126 var request = _request(); 123 var request = _request();
127 expect(request.ifModifiedSince, isNull); 124 expect(request.ifModifiedSince, isNull);
128 }); 125 });
129 126
130 test("comes from the Last-Modified header", () { 127 test("comes from the Last-Modified header", () {
131 var request = _request({ 128 var request =
132 'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT' 129 _request({'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT'});
133 });
134 expect(request.ifModifiedSince, 130 expect(request.ifModifiedSince,
135 equals(DateTime.parse("1994-11-06 08:49:37z"))); 131 equals(DateTime.parse("1994-11-06 08:49:37z")));
136 }); 132 });
137 }); 133 });
138 134
139 group('change', () { 135 group('change', () {
140 test('with no arguments returns instance with equal values', () { 136 test('with no arguments returns instance with equal values', () {
141 var controller = new StreamController(); 137 var controller = new StreamController();
142 138
143 var uri = Uri.parse('https://test.example.com/static/file.html'); 139 var uri = Uri.parse('https://test.example.com/static/file.html');
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 var request = new Request('GET', uri); 188 var request = new Request('GET', uri);
193 var copy = request.change(url: Uri.parse('/other_path/file.html')); 189 var copy = request.change(url: Uri.parse('/other_path/file.html'));
194 190
195 expect(copy.scriptName, ''); 191 expect(copy.scriptName, '');
196 expect(copy.url, Uri.parse('/other_path/file.html')); 192 expect(copy.url, Uri.parse('/other_path/file.html'));
197 }); 193 });
198 194
199 test('scriptName and url', () { 195 test('scriptName and url', () {
200 var uri = Uri.parse('https://test.example.com/static/file.html'); 196 var uri = Uri.parse('https://test.example.com/static/file.html');
201 var request = new Request('GET', uri); 197 var request = new Request('GET', uri);
202 var copy = request.change(scriptName: '/dynamic', 198 var copy = request.change(
203 url: Uri.parse('/other_path/file.html')); 199 scriptName: '/dynamic', url: Uri.parse('/other_path/file.html'));
204 200
205 expect(copy.scriptName, '/dynamic'); 201 expect(copy.scriptName, '/dynamic');
206 expect(copy.url, Uri.parse('/other_path/file.html')); 202 expect(copy.url, Uri.parse('/other_path/file.html'));
207 }); 203 });
208 }); 204 });
209 } 205 }
OLDNEW
« no previous file with comments | « test/pipeline_test.dart ('k') | test/response_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698