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

Side by Side Diff: mojo/public/dart/third_party/shelf_static/test/default_document_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library shelf_static.default_document_test;
6
7 import 'dart:io';
8 //import 'package:http_parser/http_parser.dart';
9 //import 'package:path/path.dart' as p;
10 import 'package:scheduled_test/descriptor.dart' as d;
11 import 'package:scheduled_test/scheduled_test.dart';
12
13 import 'package:shelf_static/shelf_static.dart';
14 import 'test_util.dart';
15
16 void main() {
17 setUp(() {
18 var tempDir;
19 schedule(() {
20 return Directory.systemTemp.createTemp('shelf_static-test-').then((dir) {
21 tempDir = dir;
22 d.defaultRoot = tempDir.path;
23 });
24 });
25
26 d.file('index.html', '<html></html>').create();
27 d.file('root.txt', 'root txt').create();
28 d
29 .dir('files', [
30 d.file('index.html', '<html><body>files</body></html>'),
31 d.file('with space.txt', 'with space content')
32 ])
33 .create();
34
35 currentSchedule.onComplete.schedule(() {
36 d.defaultRoot = null;
37 return tempDir.delete(recursive: true);
38 });
39 });
40
41 group('default document value', () {
42 test('cannot contain slashes', () {
43 var invalidValues = [
44 'file/foo.txt',
45 '/bar.txt',
46 '//bar.txt',
47 '//news/bar.txt',
48 'foo/../bar.txt'
49 ];
50
51 for (var val in invalidValues) {
52 expect(() => createStaticHandler(d.defaultRoot, defaultDocument: val),
53 throwsArgumentError);
54 }
55 });
56 });
57
58 group('no default document specified', () {
59 test('access "/index.html"', () {
60 schedule(() {
61 var handler = createStaticHandler(d.defaultRoot);
62
63 return makeRequest(handler, '/index.html').then((response) {
64 expect(response.statusCode, HttpStatus.OK);
65 expect(response.contentLength, 13);
66 expect(response.readAsString(), completion('<html></html>'));
67 });
68 });
69 });
70
71 test('access "/"', () {
72 schedule(() {
73 var handler = createStaticHandler(d.defaultRoot);
74
75 return makeRequest(handler, '/').then((response) {
76 expect(response.statusCode, HttpStatus.NOT_FOUND);
77 });
78 });
79 });
80
81 test('access "/files"', () {
82 schedule(() {
83 var handler = createStaticHandler(d.defaultRoot);
84
85 return makeRequest(handler, '/files').then((response) {
86 expect(response.statusCode, HttpStatus.NOT_FOUND);
87 });
88 });
89 });
90
91 test('access "/files/" dir', () {
92 schedule(() {
93 var handler = createStaticHandler(d.defaultRoot);
94
95 return makeRequest(handler, '/files/').then((response) {
96 expect(response.statusCode, HttpStatus.NOT_FOUND);
97 });
98 });
99 });
100 });
101
102 group('default document specified', () {
103 test('access "/index.html"', () {
104 schedule(() {
105 var handler =
106 createStaticHandler(d.defaultRoot, defaultDocument: 'index.html');
107
108 return makeRequest(handler, '/index.html').then((response) {
109 expect(response.statusCode, HttpStatus.OK);
110 expect(response.contentLength, 13);
111 expect(response.readAsString(), completion('<html></html>'));
112 expect(response.mimeType, 'text/html');
113 });
114 });
115 });
116
117 test('access "/"', () {
118 schedule(() {
119 var handler =
120 createStaticHandler(d.defaultRoot, defaultDocument: 'index.html');
121
122 return makeRequest(handler, '/').then((response) {
123 expect(response.statusCode, HttpStatus.OK);
124 expect(response.contentLength, 13);
125 expect(response.readAsString(), completion('<html></html>'));
126 expect(response.mimeType, 'text/html');
127 });
128 });
129 });
130
131 test('access "/files"', () {
132 schedule(() {
133 var handler =
134 createStaticHandler(d.defaultRoot, defaultDocument: 'index.html');
135
136 return makeRequest(handler, '/files').then((response) {
137 expect(response.statusCode, HttpStatus.MOVED_PERMANENTLY);
138 expect(response.headers,
139 containsPair(HttpHeaders.LOCATION, 'http://localhost/files/'));
140 });
141 });
142 });
143
144 test('access "/files/" dir', () {
145 schedule(() {
146 var handler =
147 createStaticHandler(d.defaultRoot, defaultDocument: 'index.html');
148
149 return makeRequest(handler, '/files/').then((response) {
150 expect(response.statusCode, HttpStatus.OK);
151 expect(response.contentLength, 31);
152 expect(response.readAsString(),
153 completion('<html><body>files</body></html>'));
154 expect(response.mimeType, 'text/html');
155 });
156 });
157 });
158 });
159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698