-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_sign_in_web] Migrate to null-safety #3628
Changes from all commits
ad0518a
e8b1f0f
5416aa8
07b1957
f8b1218
b667a8b
c806547
cbdd090
42cd3f3
55bc71d
6135f9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.10.0 | ||
|
||
* Migrate to null-safety. | ||
|
||
## 0.9.2+1 | ||
|
||
* Update Flutter SDK constraint. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Testing | ||
|
||
This package utilizes the `integration_test` package to run its tests in a web browser. | ||
|
||
See [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests) for more info. | ||
|
||
## Running the tests | ||
|
||
Make sure you have updated to the latest Flutter master. | ||
|
||
1. Check what version of Chrome is running on the machine you're running tests on. | ||
|
||
2. Download and install driver for that version from here: | ||
* <https://chromedriver.chromium.org/downloads> | ||
|
||
3. Start the driver using `chromedriver --port=4444` | ||
|
||
4. Run tests: `flutter drive -d web-server --browser-name=chrome --driver=test_driver/integration_driver.dart --target=integration_test/TEST_NAME.dart`, or (in Linux): | ||
|
||
* Single: `./run_test.sh integration_test/TEST_NAME.dart` | ||
* All: `./run_test.sh` | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,19 @@ | |
|
||
import 'dart:html' as html; | ||
|
||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart'; | ||
import 'package:google_sign_in_web/google_sign_in_web.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'gapi_mocks/gapi_mocks.dart' as gapi_mocks; | ||
import 'src/test_utils.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
gapiUrl = toBase64Url(gapi_mocks.auth2InitSuccess(GoogleSignInUserData())); | ||
gapiUrl = toBase64Url(gapi_mocks.auth2InitSuccess( | ||
GoogleSignInUserData(email: '[email protected]', id: '1234'))); | ||
|
||
testWidgets('Plugin is initialized after GAPI fully loads and init is called', | ||
(WidgetTester tester) async { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:google_sign_in_web/src/generated/gapiauth2.dart' as gapi; | ||
import 'package:google_sign_in_web/src/utils.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know where this was coming from, it seemed to come from some implicit import! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was concerning me, so I dug a little bit. https://master-api.flutter.dev/flutter/flutter_test/flutter_test-library.html No need to import package:test anymore! (It's just a little bit "too new", hence the link to the "master" docs :P) |
||
|
||
class MockGoogleUser extends Mock implements gapi.GoogleUser {} | ||
|
||
class MockBasicProfile extends Mock implements gapi.BasicProfile {} | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
void main() { | ||
// The non-null use cases are covered by the auth2_test.dart file. | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('gapiUserToPluginUserData', () { | ||
var mockUser; | ||
late FakeGoogleUser fakeUser; | ||
|
||
setUp(() { | ||
mockUser = MockGoogleUser(); | ||
fakeUser = FakeGoogleUser(); | ||
}); | ||
|
||
testWidgets('null user -> null response', (WidgetTester tester) async { | ||
|
@@ -30,21 +24,45 @@ void main() { | |
|
||
testWidgets('not signed-in user -> null response', | ||
(WidgetTester tester) async { | ||
when(mockUser.isSignedIn()).thenReturn(false); | ||
expect(gapiUserToPluginUserData(mockUser), isNull); | ||
expect(gapiUserToPluginUserData(fakeUser), isNull); | ||
}); | ||
|
||
testWidgets('signed-in, but null profile user -> null response', | ||
(WidgetTester tester) async { | ||
when(mockUser.isSignedIn()).thenReturn(true); | ||
expect(gapiUserToPluginUserData(mockUser), isNull); | ||
fakeUser.setIsSignedIn(true); | ||
expect(gapiUserToPluginUserData(fakeUser), isNull); | ||
}); | ||
|
||
testWidgets('signed-in, null userId in profile user -> null response', | ||
(WidgetTester tester) async { | ||
when(mockUser.isSignedIn()).thenReturn(true); | ||
when(mockUser.getBasicProfile()).thenReturn(MockBasicProfile()); | ||
expect(gapiUserToPluginUserData(mockUser), isNull); | ||
fakeUser.setIsSignedIn(true); | ||
fakeUser.setBasicProfile(FakeBasicProfile()); | ||
expect(gapiUserToPluginUserData(fakeUser), isNull); | ||
}); | ||
}); | ||
} | ||
|
||
class FakeGoogleUser extends Fake implements gapi.GoogleUser { | ||
bool _isSignedIn = false; | ||
gapi.BasicProfile? _basicProfile; | ||
|
||
@override | ||
bool isSignedIn() => _isSignedIn; | ||
@override | ||
gapi.BasicProfile? getBasicProfile() => _basicProfile; | ||
|
||
void setIsSignedIn(bool isSignedIn) { | ||
_isSignedIn = isSignedIn; | ||
} | ||
|
||
void setBasicProfile(gapi.BasicProfile basicProfile) { | ||
_basicProfile = basicProfile; | ||
} | ||
} | ||
|
||
class FakeBasicProfile extends Fake implements gapi.BasicProfile { | ||
String? _id; | ||
|
||
@override | ||
String? getId() => _id; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
#!/usr/bin/bash | ||
|
||
if pgrep -lf chromedriver > /dev/null; then | ||
echo "chromedriver is running." | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "No target specified, running all tests..." | ||
find test_driver/ -iname *_integration.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --target='{}' | ||
find integration_test/ -iname *_test.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_driver.dart --target='{}' | ||
else | ||
echo "Running test target: $1..." | ||
set -x | ||
flutter drive -d web-server --web-port=7357 --browser-name=chrome --target=$1 | ||
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_driver.dart --target=$1 | ||
fi | ||
|
||
else | ||
echo "chromedriver is not running." | ||
fi | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.