Replace use of createHttpClient with mocks (#37)

package:http was recently removed from Flutter. This replaces the use of
createHttpClient, which was previously used to mock HTTP results. This
replaces that use with Mockito.

See: https://groups.google.com/d/msg/flutter-dev/AnqDqgQ6vus/spjSxiz6BgAJ
diff --git a/packages/flutter_markdown/CHANGELOG.md b/packages/flutter_markdown/CHANGELOG.md
index 1880a6f..4251736 100644
--- a/packages/flutter_markdown/CHANGELOG.md
+++ b/packages/flutter_markdown/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 0.1.5
+
+* Add `mockito` as a dev dependency. Eliminate use of `package:http`, which
+  is no longer part of Flutter.
+
 ## 0.1.4
 
 * Add `li` style to bullets 
diff --git a/packages/flutter_markdown/pubspec.yaml b/packages/flutter_markdown/pubspec.yaml
index ec5c8cd..2b7eb77 100644
--- a/packages/flutter_markdown/pubspec.yaml
+++ b/packages/flutter_markdown/pubspec.yaml
@@ -2,7 +2,7 @@
 author: Flutter Authors <flutter-dev@googlegroups.com>
 description: A markdown renderer for Flutter.
 homepage: https://github.com/flutter/flutter_markdown
-version: 0.1.4
+version: 0.1.5
 
 dependencies:
   flutter:
@@ -15,7 +15,7 @@
 dev_dependencies:
   flutter_test:
     sdk: flutter
-  http: ^0.11.3+16
+  mockito: ^3.0.0-alpha+2
 
 environment:
   sdk: '>=1.19.0 <2.0.0'
diff --git a/packages/flutter_markdown/test/flutter_markdown_test.dart b/packages/flutter_markdown/test/flutter_markdown_test.dart
index c8a2cbc..9a2a471 100644
--- a/packages/flutter_markdown/test/flutter_markdown_test.dart
+++ b/packages/flutter_markdown/test/flutter_markdown_test.dart
@@ -2,14 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+import 'dart:async';
+import 'dart:io' as io;
+
 import 'package:flutter_markdown/flutter_markdown.dart';
 import 'package:flutter_test/flutter_test.dart';
 import 'package:flutter/gestures.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter/services.dart' show createHttpClient;
-import 'package:http/http.dart' as http;
-import 'package:http/testing.dart' as http;
+import 'package:mockito/mockito.dart';
 
 void main() {
   TextTheme textTheme = new Typography(platform: TargetPlatform.android)
@@ -167,10 +168,12 @@
       expect(tapResults, orderedEquals(['firstHref', 'secondHref']));
     });
   });
-  
+
   group('Images', () {
-    setUpAll(() {
-      createHttpClient = createMockImageHttpClient;
+    setUp(() {
+      // Only needs to be done once since the HttpClient generated by this
+      // override is cached as a static singleton.
+      io.HttpOverrides.global = new TestHttpOverrides();
     });
 
     testWidgets('should not interrupt styling', (WidgetTester tester) async {
@@ -226,7 +229,7 @@
       expect(image.height, 50);
     });
 
-    testWidgets('should show properly next to text', (WidgetTester tester) async {      
+    testWidgets('should show properly next to text', (WidgetTester tester) async {
       await tester
           .pumpWidget(_boilerplate(const Markdown(data: 'Hello ![alt](img#50x50)')));
 
@@ -427,13 +430,41 @@
   );
 }
 
+class MockHttpClient extends Mock implements io.HttpClient {}
+class MockHttpClientRequest extends Mock implements io.HttpClientRequest {}
+class MockHttpClientResponse extends Mock implements io.HttpClientResponse {}
+class MockHttpHeaders extends Mock implements io.HttpHeaders {}
+
+class TestHttpOverrides extends io.HttpOverrides {
+   io.HttpClient createHttpClient(io.SecurityContext context) {
+     return createMockImageHttpClient(context);
+   }
+}
+
 // Returns a mock HTTP client that responds with an image to all requests.
-ValueGetter<http.Client> createMockImageHttpClient = () {
-  return new http.MockClient((http.BaseRequest request) {
-    return new Future<http.Response>.value(
-        new http.Response.bytes(_transparentImage, 200, request: request));
+MockHttpClient createMockImageHttpClient(io.SecurityContext _) {
+  final MockHttpClient client = new MockHttpClient();
+  final MockHttpClientRequest request = new MockHttpClientRequest();
+  final MockHttpClientResponse response = new MockHttpClientResponse();
+  final MockHttpHeaders headers = new MockHttpHeaders();
+
+  when(client.getUrl(typed(any))).thenAnswer((_) => new Future<io.HttpClientRequest>.value(request));
+  when(request.headers).thenReturn(headers);
+  when(request.close()).thenAnswer((_) => new Future<io.HttpClientResponse>.value(response));
+  when(response.contentLength).thenReturn(_transparentImage.length);
+  when(response.statusCode).thenReturn(io.HttpStatus.OK);
+  when(response.listen(typed(any))).thenAnswer((Invocation invocation) {
+    final void Function(List<int>) onData = invocation.positionalArguments[0];
+    final void Function() onDone = invocation.namedArguments[#onDone];
+    final void Function(Object, [StackTrace]) onError = invocation.namedArguments[#onError];
+    final bool cancelOnError = invocation.namedArguments[#cancelOnError];
+
+    return new Stream<List<int>>.fromIterable(<List<int>>[_transparentImage])
+        .listen(onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError);
   });
-};
+
+  return client;
+}
 
 const List<int> _transparentImage = const <int>[
   0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49,