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

Side by Side Diff: tests/standalone/io/raw_secure_socket_pause_test.dart

Issue 12328037: Add missing files from previous commit (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "dart:async";
11 import "dart:io";
12 import "dart:isolate";
13
14
15 void main() {
16 List<int> message = "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n".charCodes;
17 int written = 0;
18 List<String> chunks = <String>[];
19 SecureSocket.initialize();
20 // TODO(whesse): Use a Dart HTTPS server for this test.
21 // The Dart HTTPS server works on bleeding-edge, but not on IOv2.
22 // When we use a Dart HTTPS server, allow --short_socket_write. The flag
23 // causes fragmentation of the client hello message, which doesn't seem to
24 // work with www.google.dk.
25 RawSecureSocket.connect("www.google.dk", 443).then((socket) {
26 StreamSubscription subscription;
27 bool paused = false;
28 bool readEventsTested = false;
29 bool readEventsPaused = false;
30
31 void runPauseTest() {
32 subscription.pause();
33 paused = true;
34 new Timer(500, (_) {
35 paused = false;
36 subscription.resume();
37 });
38 }
39
40 void runReadEventTest() {
41 if (readEventsTested) return;
42 readEventsTested = true;
43 socket.readEventsEnabled = false;
44 readEventsPaused = true;
45 new Timer(500, (_) {
46 readEventsPaused = false;
47 socket.readEventsEnabled = true;
48 });
49 }
50
51 subscription = socket.listen((RawSocketEvent event) {
52 Expect.isFalse(paused);
53 switch (event) {
54 case RawSocketEvent.READ:
55 Expect.isFalse(readEventsPaused);
56 runReadEventTest();
57 var data = socket.read();
58 var received = new String.fromCharCodes(data);
59 chunks.add(received);
60 break;
61 case RawSocketEvent.WRITE:
62 written +=
63 socket.write(message, written, message.length - written);
64 if (written < message.length) {
65 socket.writeEventsEnabled = true;
66 } else {
67 socket.shutdown(SocketDirection.SEND);
68 runPauseTest();
69 }
70 break;
71 case RawSocketEvent.READ_CLOSED:
72 String fullPage = chunks.join();
73 Expect.isTrue(fullPage.contains('</body></html>'));
74 break;
75 default: throw "Unexpected event $event";
76 }
77 }, onError: (AsyncError a) {
78 Expect.fail("onError handler of RawSecureSocket stream hit: $a");
79 });
80 });
81 }
OLDNEW
« no previous file with comments | « tests/standalone/io/raw_secure_server_socket_test.dart ('k') | tests/standalone/io/raw_secure_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698