| OLD | NEW |
| 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 // VMOptions=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
| 5 | 5 |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:developer'; | 7 import 'dart:developer'; |
| 8 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
| 11 | 11 |
| 12 int majorVersion; |
| 13 int minorVersion; |
| 14 Uri serverUri; |
| 15 |
| 12 Future<Null> testeeBefore() async { | 16 Future<Null> testeeBefore() async { |
| 13 print('testee before'); | 17 print('testee before'); |
| 14 print(await Service.getInfo()); | 18 // First grab the URL where the observatory is listening on and the |
| 15 // Start the web server. | 19 // service protocol version numbers. We expect the URL to be null as |
| 16 ServiceProtocolInfo info = await Service.controlWebServer(enable: true); | 20 // the server has not been started yet. |
| 17 print(info); | 21 ServiceProtocolInfo info = await Service.getInfo(); |
| 22 majorVersion = info.majorVersion; |
| 23 minorVersion = info.minorVersion; |
| 24 serverUri = info.serverUri; |
| 25 expect(info.serverUri, isNull); |
| 26 { |
| 27 // Now, start the web server and store the URI which is expected to be |
| 28 // non NULL in the top level variable. |
| 29 ServiceProtocolInfo info = await Service.controlWebServer(enable: true); |
| 30 expect(info.majorVersion, equals(majorVersion)); |
| 31 expect(info.minorVersion, equals(minorVersion)); |
| 32 expect(info.serverUri, isNotNull); |
| 33 serverUri = info.serverUri; |
| 34 } |
| 35 { |
| 36 // Now try starting the web server again, this should just return the |
| 37 // existing state without any change (port number does not change). |
| 38 ServiceProtocolInfo info = await Service.controlWebServer(enable: true); |
| 39 expect(info.majorVersion, equals(majorVersion)); |
| 40 expect(info.minorVersion, equals(minorVersion)); |
| 41 expect(info.serverUri, equals(serverUri)); |
| 42 } |
| 43 { |
| 44 // Try turning off the web server, this should turn off the server and |
| 45 // the Uri returned should be null. |
| 46 ServiceProtocolInfo info = await Service.controlWebServer(enable: false); |
| 47 expect(info.majorVersion, equals(majorVersion)); |
| 48 expect(info.minorVersion, equals(minorVersion)); |
| 49 expect(info.serverUri, isNull); |
| 50 } |
| 51 { |
| 52 // Try turning off the web server again, this should be a nop |
| 53 // and the Uri returned should be null. |
| 54 ServiceProtocolInfo info = await Service.controlWebServer(enable: false); |
| 55 expect(info.majorVersion, equals(majorVersion)); |
| 56 expect(info.minorVersion, equals(minorVersion)); |
| 57 expect(info.serverUri, isNull); |
| 58 } |
| 59 { |
| 60 // Start the web server again for the test below. |
| 61 ServiceProtocolInfo info = await Service.controlWebServer(enable: true); |
| 62 majorVersion = info.majorVersion; |
| 63 minorVersion = info.minorVersion; |
| 64 serverUri = info.serverUri; |
| 65 expect(info.majorVersion, equals(majorVersion)); |
| 66 expect(info.minorVersion, equals(minorVersion)); |
| 67 expect(info.serverUri, equals(serverUri)); |
| 68 } |
| 18 } | 69 } |
| 19 | 70 |
| 20 var tests = [ | 71 var tests = [ |
| 21 (Isolate isolate) async { | 72 (Isolate isolate) async { |
| 22 await isolate.reload(); | 73 await isolate.reload(); |
| 23 // Just getting here means that the testee enabled the service protocol | 74 // Just getting here means that the testee enabled the service protocol |
| 24 // web server. | 75 // web server. |
| 25 expect(true, true); | 76 expect(true, true); |
| 26 } | 77 } |
| 27 ]; | 78 ]; |
| 28 | 79 |
| 29 main(args) => runIsolateTests(args, | 80 main(args) => runIsolateTests(args, |
| 30 tests, | 81 tests, |
| 31 testeeBefore: testeeBefore, | 82 testeeBefore: testeeBefore, |
| 32 // the testee is responsible for starting the | 83 // the testee is responsible for starting the |
| 33 // web server. | 84 // web server. |
| 34 testeeControlsServer: true); | 85 testeeControlsServer: true); |
| OLD | NEW |