Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
permission_handler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
permission_handler
Commits
357df54f
Commit
357df54f
authored
Mar 15, 2021
by
Jan-Derk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed PermissionStatus enum, added tests
parent
36777b47
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
95 additions
and
35 deletions
+95
-35
permission_handler_platform_interface/lib/src/permission_status.dart
+8
-8
permission_handler_platform_interface/lib/src/permissions.dart
+0
-3
permission_handler_platform_interface/test/src/method_channel/method_channel_permission_handler_test.dart
+27
-9
permission_handler_platform_interface/test/src/method_channel/utils/coded_test.dart
+1
-1
permission_handler_platform_interface/test/src/permission_status_test.dart
+35
-6
permission_handler_platform_interface/test/src/permissions_test.dart
+0
-6
permission_handler_platform_interface/test/src/service_status_test.dart
+24
-2
No files found.
permission_handler_platform_interface/lib/src/permission_status.dart
View file @
357df54f
...
...
@@ -3,10 +3,10 @@ part of permission_handler_platform_interface;
/// Defines the state of a [Permission].
enum
PermissionStatus
{
/// The user granted access to the requested feature.
grant
ed
,
deni
ed
,
/// The user denied access to the requested feature.
deni
ed
,
grant
ed
,
/// The OS denied access to the requested feature. The user cannot change
/// this app's status, possibly due to active restrictions such as parental
...
...
@@ -28,9 +28,9 @@ enum PermissionStatus {
extension
PermissionStatusValue
on
PermissionStatus
{
int
get
value
{
switch
(
this
)
{
case
PermissionStatus
.
granted
:
return
0
;
case
PermissionStatus
.
denied
:
return
0
;
case
PermissionStatus
.
granted
:
return
1
;
case
PermissionStatus
.
restricted
:
return
2
;
...
...
@@ -45,8 +45,8 @@ extension PermissionStatusValue on PermissionStatus {
static
PermissionStatus
statusByValue
(
int
value
)
{
return
[
PermissionStatus
.
granted
,
PermissionStatus
.
denied
,
PermissionStatus
.
granted
,
PermissionStatus
.
restricted
,
PermissionStatus
.
limited
,
PermissionStatus
.
permanentlyDenied
,
...
...
@@ -55,12 +55,12 @@ extension PermissionStatusValue on PermissionStatus {
}
extension
PermissionStatusGetters
on
PermissionStatus
{
/// If the user granted access to the requested feature.
bool
get
isGranted
=>
this
==
PermissionStatus
.
granted
;
/// If the user denied access to the requested feature.
bool
get
isDenied
=>
this
==
PermissionStatus
.
denied
;
/// If the user granted access to the requested feature.
bool
get
isGranted
=>
this
==
PermissionStatus
.
granted
;
/// If the OS denied access to the requested feature. The user cannot change
/// this app's status, possibly due to active restrictions such as parental
/// controls being in place.
...
...
permission_handler_platform_interface/lib/src/permissions.dart
View file @
357df54f
...
...
@@ -15,9 +15,6 @@ class Permission {
const
Permission
.
_
(
this
.
value
);
factory
Permission
.
byValue
(
int
value
)
=>
values
[
value
];
@visibleForTesting
const
Permission
.
private
(
this
.
value
);
/// Integer representation of the [Permission].
final
int
value
;
...
...
permission_handler_platform_interface/test/src/method_channel/method_channel_permission_handler_test.dart
View file @
357df54f
...
...
@@ -15,13 +15,13 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkPermissionStatus'
,
result:
PermissionStatus
.
granted
.
index
,
result:
PermissionStatus
.
denied
.
value
,
);
final
permissionStatus
=
await
MethodChannelPermissionHandler
()
.
checkPermissionStatus
(
Permission
.
calendar
);
expect
(
permissionStatus
,
PermissionStatus
.
grant
ed
);
expect
(
permissionStatus
,
PermissionStatus
.
deni
ed
);
});
test
(
'Should receive denied if user denied access to the requested feature'
,
...
...
@@ -29,7 +29,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkPermissionStatus'
,
result:
PermissionStatus
.
denied
.
index
,
result:
PermissionStatus
.
denied
.
value
,
);
final
permissionStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -45,7 +45,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkPermissionStatus'
,
result:
PermissionStatus
.
restricted
.
index
,
result:
PermissionStatus
.
restricted
.
value
,
);
final
permissionStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -61,7 +61,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkPermissionStatus'
,
result:
PermissionStatus
.
limited
.
index
,
result:
PermissionStatus
.
limited
.
value
,
);
final
permissionStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -77,7 +77,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkPermissionStatus'
,
result:
PermissionStatus
.
permanentlyDenied
.
index
,
result:
PermissionStatus
.
permanentlyDenied
.
value
,
);
final
permissionStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -95,7 +95,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkServiceStatus'
,
result:
ServiceStatus
.
disabled
.
index
,
result:
ServiceStatus
.
disabled
.
value
,
);
final
serviceStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -109,7 +109,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkServiceStatus'
,
result:
ServiceStatus
.
enabled
.
index
,
result:
ServiceStatus
.
enabled
.
value
,
);
final
serviceStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -125,7 +125,7 @@ void main() {
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'checkServiceStatus'
,
result:
ServiceStatus
.
notApplicable
.
index
,
result:
ServiceStatus
.
notApplicable
.
value
,
);
final
serviceStatus
=
await
MethodChannelPermissionHandler
()
...
...
@@ -162,4 +162,22 @@ void main() {
expect
(
hasOpenedAppSettings
,
false
);
});
});
group
(
'shouldShowRequestPermissionRationale:'
,
()
{
test
(
// ignore: lines_longer_than_80_chars
'should return true when you should show a rationale for requesting permission.'
,
()
async
{
MethodChannelMock
(
channelName:
'flutter.baseflow.com/permissions/methods'
,
method:
'shouldShowRequestPermissionRationale'
,
result:
true
,
);
final
shouldShowRationale
=
await
MethodChannelPermissionHandler
()
.
shouldShowRequestPermissionRationale
(
mockPermissions
.
first
);
expect
(
shouldShowRationale
,
true
);
});
});
}
permission_handler_platform_interface/test/src/method_channel/utils/coded_test.dart
View file @
357df54f
...
...
@@ -5,7 +5,7 @@ import 'package:permission_handler_platform_interface/src/method_channel/utils/c
void
main
(
)
{
group
(
'Codec'
,
()
{
test
(
'decodePermissionStatus should return a PermissionStatus'
,
()
{
expect
(
Codec
.
decodePermissionStatus
(
0
),
PermissionStatus
.
grant
ed
);
expect
(
Codec
.
decodePermissionStatus
(
0
),
PermissionStatus
.
deni
ed
);
});
test
(
'decodeServiceStatus should a corresponding ServiceStatus'
,
()
{
...
...
permission_handler_platform_interface/test/src/permission_status_test.dart
View file @
357df54f
...
...
@@ -2,6 +2,7 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
;
void
main
(
)
{
group
(
'PermissionSatus'
,
()
{
test
(
'PermissionStatus should contain 5 options'
,
()
{
final
values
=
PermissionStatus
.
values
;
...
...
@@ -11,24 +12,52 @@ void main() {
test
(
'PermissionStatus enum should have items in correct index'
,
()
{
final
values
=
PermissionStatus
.
values
;
expect
(
values
[
0
],
PermissionStatus
.
grant
ed
);
expect
(
values
[
1
],
PermissionStatus
.
deni
ed
);
expect
(
values
[
0
],
PermissionStatus
.
deni
ed
);
expect
(
values
[
1
],
PermissionStatus
.
grant
ed
);
expect
(
values
[
2
],
PermissionStatus
.
restricted
);
expect
(
values
[
3
],
PermissionStatus
.
limited
);
expect
(
values
[
4
],
PermissionStatus
.
permanentlyDenied
);
});
});
group
(
'PermissionStatusValue'
,
()
{
test
(
'PermissonStatusValue returns right integer'
,
()
{
expect
(
PermissionStatus
.
denied
.
value
,
0
);
expect
(
PermissionStatus
.
granted
.
value
,
1
);
expect
(
PermissionStatus
.
restricted
.
value
,
2
);
expect
(
PermissionStatus
.
limited
.
value
,
3
);
expect
(
PermissionStatus
.
permanentlyDenied
.
value
,
4
);
});
test
(
// ignore: lines_longer_than_80_chars
'statusByValue should return right index int that corresponds with the right PermissionStatus'
,
()
{
expect
(
PermissionStatusValue
.
statusByValue
(
0
),
PermissionStatus
.
granted
);
expect
(
PermissionStatusValue
.
statusByValue
(
1
),
PermissionStatus
.
denied
);
expect
(
PermissionStatusValue
.
statusByValue
(
2
),
PermissionStatus
.
restricted
);
expect
(
PermissionStatusValue
.
statusByValue
(
0
),
PermissionStatus
.
denied
);
expect
(
PermissionStatusValue
.
statusByValue
(
1
),
PermissionStatus
.
granted
);
expect
(
PermissionStatusValue
.
statusByValue
(
2
),
PermissionStatus
.
restricted
);
expect
(
PermissionStatusValue
.
statusByValue
(
3
),
PermissionStatus
.
limited
);
expect
(
PermissionStatusValue
.
statusByValue
(
4
),
PermissionStatus
.
permanentlyDenied
);
});
});
//TODO: Kan je de Getters testen?
group
(
'PermissionStatusGetters'
,
()
{
test
(
'Getters should return true if statement is met'
,
()
{
expect
(
PermissionStatus
.
denied
.
isDenied
,
true
);
expect
(
PermissionStatus
.
granted
.
isGranted
,
true
);
expect
(
PermissionStatus
.
restricted
.
isRestricted
,
true
);
expect
(
PermissionStatus
.
limited
.
isLimited
,
true
);
expect
(
PermissionStatus
.
permanentlyDenied
.
isPermanentlyDenied
,
true
);
});
test
(
'Getters should return false if statement is not met'
,
()
{
expect
(
PermissionStatus
.
denied
.
isGranted
,
false
);
expect
(
PermissionStatus
.
granted
.
isDenied
,
false
);
expect
(
PermissionStatus
.
restricted
.
isDenied
,
false
);
expect
(
PermissionStatus
.
limited
.
isDenied
,
false
);
expect
(
PermissionStatus
.
permanentlyDenied
.
isDenied
,
false
);
});
});
}
permission_handler_platform_interface/test/src/permissions_test.dart
View file @
357df54f
...
...
@@ -16,10 +16,4 @@ void main() {
expect
(
values
[
i
],
Permission
.
byValue
(
i
));
}
});
test
(
'check if byValue returns corresponding PermissionGroup value'
,
()
{
var
permissionWithService
=
PermissionWithService
.
private
(
0
);
var
test
=
permissionWithService
.
toString
();
expect
(
test
,
'Permission.calendar'
);
});
}
permission_handler_platform_interface/test/src/service_status_test.dart
View file @
357df54f
...
...
@@ -2,19 +2,28 @@ import 'package:flutter_test/flutter_test.dart';
import
'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'
;
void
main
(
)
{
group
(
'ServiceStatus'
,
()
{
test
(
'ServiceStatus should contain 3 options'
,
()
{
final
values
=
ServiceStatus
.
values
;
expect
(
values
.
length
,
3
);
});
test
(
'Permission
Status enum should have items in correct index'
,
()
{
test
(
'Service
Status enum should have items in correct index'
,
()
{
final
values
=
ServiceStatus
.
values
;
expect
(
values
[
0
],
ServiceStatus
.
disabled
);
expect
(
values
[
1
],
ServiceStatus
.
enabled
);
expect
(
values
[
2
],
ServiceStatus
.
notApplicable
);
});
});
group
(
'ServiceStatusValue'
,
()
{
test
(
'ServiceStatusValue returns right integer'
,
()
{
expect
(
ServiceStatus
.
disabled
.
value
,
0
);
expect
(
ServiceStatus
.
enabled
.
value
,
1
);
expect
(
ServiceStatus
.
notApplicable
.
value
,
2
);
});
test
(
// ignore: lines_longer_than_80_chars
...
...
@@ -24,6 +33,19 @@ void main() {
expect
(
ServiceStatusValue
.
statusByValue
(
1
),
ServiceStatus
.
enabled
);
expect
(
ServiceStatusValue
.
statusByValue
(
2
),
ServiceStatus
.
notApplicable
);
});
});
//TODO: Kan je de Getters testen?
group
(
'ServiceStatusGetters'
,
()
{
test
(
'Getters should return true if statement is met'
,
()
{
expect
(
ServiceStatus
.
disabled
.
isDisabled
,
true
);
expect
(
ServiceStatus
.
enabled
.
isEnabled
,
true
);
expect
(
ServiceStatus
.
notApplicable
.
isNotApplicable
,
true
);
});
test
(
'Getters should return false if statement is not met'
,
()
{
expect
(
ServiceStatus
.
disabled
.
isEnabled
,
false
);
expect
(
ServiceStatus
.
enabled
.
isDisabled
,
false
);
expect
(
ServiceStatus
.
notApplicable
.
isDisabled
,
false
);
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment