2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ // the following ignore is needed for downgraded analyzer (casts to JSObject).
6
+ // ignore_for_file: unnecessary_cast
7
+
5
8
import 'dart:async' ;
9
+ import 'dart:js_interop' ;
6
10
7
11
import 'package:flutter_test/flutter_test.dart' ;
8
12
import 'package:google_identity_services_web/oauth2.dart' ;
9
13
import 'package:integration_test/integration_test.dart' ;
10
- import 'package:js/js.dart' ;
11
14
12
15
import 'utils.dart' as utils;
13
16
@@ -19,12 +22,96 @@ void main() async {
19
22
await utils.installGisMock ();
20
23
});
21
24
25
+ group ('Config objects pass values from Dart to JS - ' , () {
26
+ testWidgets ('TokenClientConfig' , (_) async {
27
+ final TokenClientConfig config = TokenClientConfig (
28
+ client_id: 'testing_1-2-3' ,
29
+ callback: (_) {},
30
+ scope: < String > ['one' , 'two' , 'three' ],
31
+ include_granted_scopes: true ,
32
+ prompt: 'some-prompt' ,
33
+ enable_granular_consent: true ,
34
+ login_hint: 'login-hint@example.com' ,
35
+ hd: 'hd_value' ,
36
+ state: 'some-state' ,
37
+ error_callback: (_) {},
38
+ );
39
+
40
+ final utils.ExpectConfigValueFn expectConfigValue =
41
+ utils.createExpectConfigValue (config as JSObject );
42
+
43
+ expectConfigValue ('client_id' , 'testing_1-2-3' );
44
+ expectConfigValue ('callback' , utils.isAJs ('function' ));
45
+ expectConfigValue ('scope' , 'one two three' );
46
+ expectConfigValue ('include_granted_scopes' , isTrue);
47
+ expectConfigValue ('prompt' , 'some-prompt' );
48
+ expectConfigValue ('enable_granular_consent' , isTrue);
49
+ expectConfigValue ('login_hint' , 'login-hint@example.com' );
50
+ expectConfigValue ('hd' , 'hd_value' );
51
+ expectConfigValue ('state' , 'some-state' );
52
+ expectConfigValue ('error_callback' , utils.isAJs ('function' ));
53
+ });
54
+
55
+ testWidgets ('OverridableTokenClientConfig' , (_) async {
56
+ final OverridableTokenClientConfig config = OverridableTokenClientConfig (
57
+ scope: < String > ['one' , 'two' , 'three' ],
58
+ include_granted_scopes: true ,
59
+ prompt: 'some-prompt' ,
60
+ enable_granular_consent: true ,
61
+ login_hint: 'login-hint@example.com' ,
62
+ state: 'some-state' ,
63
+ );
64
+
65
+ final utils.ExpectConfigValueFn expectConfigValue =
66
+ utils.createExpectConfigValue (config as JSObject );
67
+
68
+ expectConfigValue ('scope' , 'one two three' );
69
+ expectConfigValue ('include_granted_scopes' , isTrue);
70
+ expectConfigValue ('prompt' , 'some-prompt' );
71
+ expectConfigValue ('enable_granular_consent' , isTrue);
72
+ expectConfigValue ('login_hint' , 'login-hint@example.com' );
73
+ expectConfigValue ('state' , 'some-state' );
74
+ });
75
+
76
+ testWidgets ('CodeClientConfig' , (_) async {
77
+ final CodeClientConfig config = CodeClientConfig (
78
+ client_id: 'testing_1-2-3' ,
79
+ scope: < String > ['one' , 'two' , 'three' ],
80
+ include_granted_scopes: true ,
81
+ redirect_uri: Uri .parse ('https://www.example.com/login' ),
82
+ callback: (_) {},
83
+ state: 'some-state' ,
84
+ enable_granular_consent: true ,
85
+ login_hint: 'login-hint@example.com' ,
86
+ hd: 'hd_value' ,
87
+ ux_mode: UxMode .popup,
88
+ select_account: true ,
89
+ error_callback: (_) {},
90
+ );
91
+
92
+ final utils.ExpectConfigValueFn expectConfigValue =
93
+ utils.createExpectConfigValue (config as JSObject );
94
+
95
+ expectConfigValue ('scope' , 'one two three' );
96
+ expectConfigValue ('include_granted_scopes' , isTrue);
97
+ expectConfigValue ('redirect_uri' , 'https://www.example.com/login' );
98
+ expectConfigValue ('callback' , utils.isAJs ('function' ));
99
+ expectConfigValue ('state' , 'some-state' );
100
+ expectConfigValue ('enable_granular_consent' , isTrue);
101
+ expectConfigValue ('login_hint' , 'login-hint@example.com' );
102
+ expectConfigValue ('hd' , 'hd_value' );
103
+ expectConfigValue ('ux_mode' , 'popup' );
104
+ expectConfigValue ('select_account' , isTrue);
105
+ expectConfigValue ('error_callback' , utils.isAJs ('function' ));
106
+ });
107
+ });
108
+
22
109
group ('initTokenClient' , () {
23
110
testWidgets ('returns a tokenClient' , (_) async {
24
111
final TokenClient client = oauth2.initTokenClient (TokenClientConfig (
25
112
client_id: 'for-tests' ,
26
- callback: null ,
27
- scope: 'some_scope for_tests not_real' ,
113
+ callback: (_) {} ,
114
+ scope: < String > [ 'some_scope' , ' for_tests' , ' not_real'] ,
28
115
));
29
116
30
117
expect (client, isNotNull);
@@ -40,8 +127,8 @@ void main() async {
40
127
41
128
final TokenClient client = oauth2.initTokenClient (TokenClientConfig (
42
129
client_id: 'for-tests' ,
43
- callback: allowInterop ( controller.add) ,
44
- scope: scopes. join ( ' ' ) ,
130
+ callback: controller.add,
131
+ scope: scopes,
45
132
));
46
133
47
134
utils.setMockTokenResponse (client, 'some-non-null-auth-token-value' );
@@ -52,7 +139,7 @@ void main() async {
52
139
53
140
expect (response, isNotNull);
54
141
expect (response.error, isNull);
55
- expect (response.scope, scopes. join ( ' ' ) );
142
+ expect (response.scope, scopes);
56
143
});
57
144
58
145
testWidgets ('configuration can be overridden' , (_) async {
@@ -63,21 +150,21 @@ void main() async {
63
150
64
151
final TokenClient client = oauth2.initTokenClient (TokenClientConfig (
65
152
client_id: 'for-tests' ,
66
- callback: allowInterop ( controller.add) ,
67
- scope: 'blank' ,
153
+ callback: controller.add,
154
+ scope: < String > [ 'blank' ] ,
68
155
));
69
156
70
157
utils.setMockTokenResponse (client, 'some-non-null-auth-token-value' );
71
158
72
159
client.requestAccessToken (OverridableTokenClientConfig (
73
- scope: scopes. join ( ' ' ) ,
160
+ scope: scopes,
74
161
));
75
162
76
163
final TokenResponse response = await controller.stream.first;
77
164
78
165
expect (response, isNotNull);
79
166
expect (response.error, isNull);
80
- expect (response.scope, scopes. join ( ' ' ) );
167
+ expect (response.scope, scopes);
81
168
});
82
169
});
83
170
0 commit comments