diff --git a/.cirrus.yml b/.cirrus.yml index 668287bdf6ca..fe80a0109b9e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -27,6 +27,7 @@ task: matrix: PLUGIN_SHARDING: "--shardIndex 0 --shardCount 2" PLUGIN_SHARDING: "--shardIndex 1 --shardCount 2" + MAPS_API_KEY: ENCRYPTED[596a9f6bca436694625ac50851dc5da6b4d34cba8025f7db5bc9465142e8cd44e15f69e3507787753accebfc4910d550] create_device_script: echo no | avdmanager -v create avd -n test -k "system-images;android-21;default;armeabi-v7a" start_emulator_background_script: @@ -63,6 +64,7 @@ task: PLUGIN_SHARDING: "--shardIndex 1 --shardCount 4" PLUGIN_SHARDING: "--shardIndex 2 --shardCount 4" PLUGIN_SHARDING: "--shardIndex 3 --shardCount 4" + SIMCTL_CHILD_MAPS_API_KEY: ENCRYPTED[596a9f6bca436694625ac50851dc5da6b4d34cba8025f7db5bc9465142e8cd44e15f69e3507787753accebfc4910d550] setup_script: - brew update - brew install libimobiledevice diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index e7fba92887d2..99aa11a5dd5f 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -199,6 +199,12 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) { markersController.changeMarkers((List) markersToChange); Object markerIdsToRemove = call.argument("markerIdsToRemove"); markersController.removeMarkers((List) markerIdsToRemove); + result.success(null); + break; + } + case "map#isCompassEnabled": + { + result.success(googleMap.getUiSettings().isCompassEnabled()); break; } default: diff --git a/packages/google_maps_flutter/example/android/app/build.gradle b/packages/google_maps_flutter/example/android/app/build.gradle index 0e30acb1d954..16e93d936838 100644 --- a/packages/google_maps_flutter/example/android/app/build.gradle +++ b/packages/google_maps_flutter/example/android/app/build.gradle @@ -40,6 +40,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + defaultConfig { + manifestPlaceholders = [mapsApiKey: "$System.env.MAPS_API_KEY"] + } + buildTypes { release { // TODO: Add your own signing config for the release build. diff --git a/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml b/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml index 9e8b95998598..1e20d08125a0 100644 --- a/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml +++ b/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml @@ -11,9 +11,10 @@ + + android:value="${mapsApiKey}" /> isCompassEnabled() async { + return await _channel.invokeMethod('map#isCompassEnabled'); + } +} diff --git a/packages/google_maps_flutter/example/test_driver/google_maps.dart b/packages/google_maps_flutter/example/test_driver/google_maps.dart new file mode 100644 index 000000000000..864685ad2058 --- /dev/null +++ b/packages/google_maps_flutter/example/test_driver/google_maps.dart @@ -0,0 +1,60 @@ +// Copyright 2019, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/widgets.dart'; +import 'package:flutter_driver/driver_extension.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; + +import 'google_map_inspector.dart'; +import 'test_widgets.dart'; + +const CameraPosition _kInitialCameraPosition = + CameraPosition(target: LatLng(0, 0)); + +void main() { + final Completer allTestsCompleter = Completer(); + enableFlutterDriverExtension(handler: (_) => allTestsCompleter.future); + + tearDownAll(() => allTestsCompleter.complete(null)); + + test('testCompassToggle', () async { + final Completer inspectorCompleter = + Completer(); + + await pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: _kInitialCameraPosition, + compassEnabled: false, + onMapCreated: (GoogleMapController controller) { + final GoogleMapInspector inspector = + // ignore: invalid_use_of_visible_for_testing_member + GoogleMapInspector(controller.channel); + inspectorCompleter.complete(inspector); + }, + ), + )); + + final GoogleMapInspector inspector = await inspectorCompleter.future; + bool compassEnabled = await inspector.isCompassEnabled(); + expect(compassEnabled, false); + + await pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: _kInitialCameraPosition, + compassEnabled: true, + onMapCreated: (GoogleMapController controller) { + fail("OnMapCreated should get called only once."); + }, + ), + )); + + compassEnabled = await inspector.isCompassEnabled(); + expect(compassEnabled, true); + }); +} diff --git a/packages/google_maps_flutter/example/test_driver/google_maps_test.dart b/packages/google_maps_flutter/example/test_driver/google_maps_test.dart new file mode 100644 index 000000000000..b0d3305cd652 --- /dev/null +++ b/packages/google_maps_flutter/example/test_driver/google_maps_test.dart @@ -0,0 +1,13 @@ +// Copyright 2019, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter_driver/flutter_driver.dart'; + +Future main() async { + final FlutterDriver driver = await FlutterDriver.connect(); + await driver.requestData(null, timeout: const Duration(minutes: 1)); + driver.close(); +} diff --git a/packages/google_maps_flutter/example/test_driver/test_widgets.dart b/packages/google_maps_flutter/example/test_driver/test_widgets.dart new file mode 100644 index 000000000000..5656c9f5610c --- /dev/null +++ b/packages/google_maps_flutter/example/test_driver/test_widgets.dart @@ -0,0 +1,12 @@ +// Copyright 2019, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/widgets.dart'; + +Future pumpWidget(Widget widget) { + runApp(widget); + return WidgetsBinding.instance.endOfFrame; +} diff --git a/packages/google_maps_flutter/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/ios/Classes/GoogleMapController.m index 1783bded7f6d..da755393be70 100644 --- a/packages/google_maps_flutter/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/ios/Classes/GoogleMapController.m @@ -125,6 +125,9 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [_markersController removeMarkerIds:markerIdsToRemove]; } result(nil); + } else if ([call.method isEqualToString:@"map#isCompassEnabled"]) { + NSNumber* isCompassEnabled = @(_mapView.settings.compassButton); + result(isCompassEnabled); } else { result(FlutterMethodNotImplemented); } diff --git a/packages/google_maps_flutter/lib/src/controller.dart b/packages/google_maps_flutter/lib/src/controller.dart index 3d5640083698..bb8b4888eb54 100644 --- a/packages/google_maps_flutter/lib/src/controller.dart +++ b/packages/google_maps_flutter/lib/src/controller.dart @@ -7,12 +7,11 @@ part of google_maps_flutter; /// Controller for a single GoogleMap instance running on the host platform. class GoogleMapController { GoogleMapController._( - MethodChannel channel, + this.channel, CameraPosition initialCameraPosition, this._googleMapState, - ) : assert(channel != null), - _channel = channel { - _channel.setMethodCallHandler(_handleMethodCall); + ) : assert(channel != null) { + channel.setMethodCallHandler(_handleMethodCall); } static Future init( @@ -34,7 +33,8 @@ class GoogleMapController { ); } - final MethodChannel _channel; + @visibleForTesting + final MethodChannel channel; final _GoogleMapState _googleMapState; @@ -79,7 +79,7 @@ class GoogleMapController { // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. // https://github.com/flutter/flutter/issues/26431 // ignore: strong_mode_implicit_dynamic_method - await _channel.invokeMethod( + await channel.invokeMethod( 'map#update', { 'options': optionsUpdate, @@ -98,7 +98,7 @@ class GoogleMapController { // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. // https://github.com/flutter/flutter/issues/26431 // ignore: strong_mode_implicit_dynamic_method - await _channel.invokeMethod( + await channel.invokeMethod( 'markers#update', markerUpdates._toMap(), ); @@ -112,7 +112,7 @@ class GoogleMapController { // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. // https://github.com/flutter/flutter/issues/26431 // ignore: strong_mode_implicit_dynamic_method - await _channel.invokeMethod('camera#animate', { + await channel.invokeMethod('camera#animate', { 'cameraUpdate': cameraUpdate._toJson(), }); } @@ -125,7 +125,7 @@ class GoogleMapController { // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. // https://github.com/flutter/flutter/issues/26431 // ignore: strong_mode_implicit_dynamic_method - await _channel.invokeMethod('camera#move', { + await channel.invokeMethod('camera#move', { 'cameraUpdate': cameraUpdate._toJson(), }); } diff --git a/packages/google_maps_flutter/pubspec.yaml b/packages/google_maps_flutter/pubspec.yaml index 81169e44ff68..2db4b2e3aa79 100644 --- a/packages/google_maps_flutter/pubspec.yaml +++ b/packages/google_maps_flutter/pubspec.yaml @@ -12,6 +12,12 @@ dev_dependencies: flutter_test: sdk: flutter + # TODO(iskakaushik): The following dependencies can be removed once + # https://github.com/dart-lang/pub/issues/2101 is resolved. + flutter_driver: + sdk: flutter + test: ^1.6.0 + flutter: plugin: androidPackage: io.flutter.plugins.googlemaps