Skip to content

Commit c960583

Browse files
PhilLabbackportbot[bot]
authored andcommitted
Instrumentation tests now automatically grab the notifications permission
Before that, when starting individual tests from the command line or from inside the IDE, they could fail because a dialog asking for the permission to post notifications was blocking the view. While we are on it, added a small explanation to the other existing rule. Without that explanation it might be unclear why this is not also done via the same GrantPermissionRule used for the notifications. Signed-off-by: Philipp Hasper <vcs@hasper.info>
1 parent aaff1df commit c960583

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

app/src/androidTest/java/com/nextcloud/test/GrantStoragePermissionRule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import org.junit.rules.TestRule
1515
import org.junit.runner.Description
1616
import org.junit.runners.model.Statement
1717

18+
/**
19+
* Rule to automatically enable the test to write to the external storage.
20+
* Depending on the SDK version, different approaches might be necessary to achieve the full access.
21+
*/
1822
class GrantStoragePermissionRule private constructor() {
1923

2024
companion object {
@@ -30,6 +34,7 @@ class GrantStoragePermissionRule private constructor() {
3034
private class GrantManageExternalStoragePermissionRule : TestRule {
3135
override fun apply(base: Statement, description: Description): Statement = object : Statement() {
3236
override fun evaluate() {
37+
// Refer to https://developer.android.com/training/data-storage/manage-all-files#enable-manage-external-storage-for-testing
3338
InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(
3439
"appops set --uid ${InstrumentationRegistry.getInstrumentation().targetContext.packageName} " +
3540
"MANAGE_EXTERNAL_STORAGE allow"

app/src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package com.owncloud.android;
88

9+
import android.Manifest;
910
import android.accounts.Account;
1011
import android.accounts.AccountManager;
1112
import android.accounts.AuthenticatorException;
@@ -78,6 +79,7 @@
7879
import androidx.test.espresso.contrib.DrawerActions;
7980
import androidx.test.espresso.intent.rule.IntentsTestRule;
8081
import androidx.test.platform.app.InstrumentationRegistry;
82+
import androidx.test.rule.GrantPermissionRule;
8183
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
8284
import androidx.test.runner.lifecycle.Stage;
8385

@@ -93,7 +95,10 @@
9395
*/
9496
public abstract class AbstractIT {
9597
@Rule
96-
public final TestRule permissionRule = GrantStoragePermissionRule.grant();
98+
public final TestRule storagePermissionRule = GrantStoragePermissionRule.grant();
99+
100+
@Rule
101+
public GrantPermissionRule notificationsPermissionRule = GrantPermissionRule.grant(Manifest.permission.POST_NOTIFICATIONS);
97102

98103
protected static OwnCloudClient client;
99104
protected static NextcloudClient nextcloudClient;

0 commit comments

Comments
 (0)