This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
413 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...missions/src/main/java/mozilla/components/feature/sitepermissions/SitePermissionsFacts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.feature.sitepermissions | ||
|
||
import mozilla.components.concept.engine.permission.Permission | ||
import mozilla.components.support.base.Component.FEATURE_SITEPERMISSIONS | ||
import mozilla.components.support.base.facts.Action | ||
import mozilla.components.support.base.facts.Fact | ||
import mozilla.components.support.base.facts.collect | ||
|
||
/** | ||
* Facts emitted for telemetry related to the site permissions prompt. | ||
*/ | ||
class SitePermissionsFacts { | ||
/** | ||
* Specific types of telemetry items. | ||
*/ | ||
object Items { | ||
const val PERMISSIONS = "permissions" | ||
} | ||
} | ||
|
||
internal fun emitPermissionDialogDisplayed(permission: Permission) = emitSitePermissionsFact( | ||
action = Action.DISPLAY, | ||
permissions = permission.id!! | ||
) | ||
|
||
internal fun emitPermissionsDialogDisplayed(permissions: List<Permission>) = emitSitePermissionsFact( | ||
action = Action.DISPLAY, | ||
permissions = permissions.joinToString { it.id!! } | ||
) | ||
|
||
internal fun emitPermissionDenied(permission: Permission) = emitSitePermissionsFact( | ||
action = Action.CANCEL, | ||
permissions = permission.id!! | ||
) | ||
|
||
internal fun emitPermissionsDenied(permissions: List<Permission>) = emitSitePermissionsFact( | ||
action = Action.CANCEL, | ||
permissions = permissions.joinToString { it.id!! } | ||
) | ||
|
||
internal fun emitPermissionAllowed(permission: Permission) = emitSitePermissionsFact( | ||
action = Action.CONFIRM, | ||
permissions = permission.id!! | ||
) | ||
|
||
internal fun emitPermissionsAllowed(permissions: List<Permission>) = emitSitePermissionsFact( | ||
action = Action.CONFIRM, | ||
permissions = permissions.joinToString { it.id!! } | ||
) | ||
|
||
private fun emitSitePermissionsFact( | ||
action: Action, | ||
permissions: String | ||
) { | ||
Fact( | ||
FEATURE_SITEPERMISSIONS, | ||
action, | ||
SitePermissionsFacts.Items.PERMISSIONS, | ||
permissions | ||
).collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ions/src/test/java/mozilla/components/feature/sitepermissions/SitePermissionsFactsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.feature.sitepermissions | ||
|
||
import mozilla.components.concept.engine.permission.Permission.AppCamera | ||
import mozilla.components.concept.engine.permission.Permission.AppLocationFine | ||
import mozilla.components.concept.engine.permission.Permission.ContentAudioCapture | ||
import mozilla.components.concept.engine.permission.Permission.ContentCrossOriginStorageAccess | ||
import mozilla.components.concept.engine.permission.Permission.ContentVideoCapture | ||
import mozilla.components.concept.engine.permission.Permission.Generic | ||
import mozilla.components.support.base.Component.FEATURE_SITEPERMISSIONS | ||
import mozilla.components.support.base.facts.Action | ||
import mozilla.components.support.base.facts.processor.CollectionProcessor | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class SitePermissionsFactsTest { | ||
|
||
@Test | ||
fun `GIVEN a fact for a prompt shown for one permission WHEN it is emitted THEN it is properly configured`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
emitPermissionDialogDisplayed(Generic()) | ||
|
||
assertEquals(1, facts.size) | ||
assertEquals(FEATURE_SITEPERMISSIONS, facts[0].component) | ||
assertEquals(Action.DISPLAY, facts[0].action) | ||
assertEquals(SitePermissionsFacts.Items.PERMISSIONS, facts[0].item) | ||
assertEquals(Generic().id, facts[0].value) | ||
} | ||
} | ||
|
||
@Test | ||
fun `GIVEN a fact for a prompt shown for multiple permissions WHEN it is emitted THEN it is properly configured`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
emitPermissionsDialogDisplayed(listOf(AppCamera(), ContentCrossOriginStorageAccess())) | ||
|
||
assertEquals(1, facts.size) | ||
assertEquals(FEATURE_SITEPERMISSIONS, facts[0].component) | ||
assertEquals(Action.DISPLAY, facts[0].action) | ||
assertEquals(SitePermissionsFacts.Items.PERMISSIONS, facts[0].item) | ||
assertEquals(listOf(AppCamera(), ContentCrossOriginStorageAccess()).joinToString { it.id!! }, facts[0].value) | ||
} | ||
} | ||
|
||
@Test | ||
fun `GIVEN a fact for a permission prompt being allowed WHEN it is emitted THEN it is properly configured`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
emitPermissionAllowed(ContentAudioCapture()) | ||
|
||
assertEquals(1, facts.size) | ||
assertEquals(FEATURE_SITEPERMISSIONS, facts[0].component) | ||
assertEquals(Action.CONFIRM, facts[0].action) | ||
assertEquals(SitePermissionsFacts.Items.PERMISSIONS, facts[0].item) | ||
assertEquals(ContentAudioCapture().id, facts[0].value) | ||
} | ||
} | ||
|
||
@Test | ||
fun `GIVEN a fact for a multiple permission prompt being allowed WHEN it is emitted THEN it is properly configured`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
emitPermissionsAllowed(listOf(ContentAudioCapture(), ContentVideoCapture())) | ||
|
||
assertEquals(1, facts.size) | ||
assertEquals(FEATURE_SITEPERMISSIONS, facts[0].component) | ||
assertEquals(Action.CONFIRM, facts[0].action) | ||
assertEquals(SitePermissionsFacts.Items.PERMISSIONS, facts[0].item) | ||
assertEquals(listOf(ContentAudioCapture(), ContentVideoCapture()).joinToString { it.id!! }, facts[0].value) | ||
} | ||
} | ||
|
||
@Test | ||
fun `GIVEN a fact for a permission prompt being blocked WHEN it is emitted THEN it is properly configured`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
emitPermissionDenied(AppLocationFine()) | ||
|
||
assertEquals(1, facts.size) | ||
assertEquals(FEATURE_SITEPERMISSIONS, facts[0].component) | ||
assertEquals(Action.CANCEL, facts[0].action) | ||
assertEquals(SitePermissionsFacts.Items.PERMISSIONS, facts[0].item) | ||
assertEquals(AppLocationFine().id, facts[0].value) | ||
} | ||
} | ||
|
||
@Test | ||
fun `GIVEN a fact for a multiple permission prompt being blocked WHEN it is emitted THEN it is properly configured`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
emitPermissionsDenied(listOf(ContentAudioCapture(), ContentVideoCapture())) | ||
|
||
assertEquals(1, facts.size) | ||
assertEquals(FEATURE_SITEPERMISSIONS, facts[0].component) | ||
assertEquals(Action.CANCEL, facts[0].action) | ||
assertEquals(SitePermissionsFacts.Items.PERMISSIONS, facts[0].item) | ||
assertEquals(listOf(ContentAudioCapture(), ContentVideoCapture()).joinToString { it.id!! }, facts[0].value) | ||
} | ||
} | ||
} |
Oops, something went wrong.
722e5d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh! Looks like an error! Details
Failed to fetch task artifact
public/github/customCheckRunText.md
for GitHub integration.Make sure the artifact exists on the worker or other location.
722e5d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh! Looks like an error! Details
Failed to fetch task artifact
public/github/customCheckRunText.md
for GitHub integration.Make sure the artifact exists on the worker or other location.