diff options
author | Sahana Rao <sahanas@google.com> | 2021-01-29 14:34:23 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-01-29 14:34:23 +0000 |
commit | cb3345dd5c5dd1b44363e4082fdabbb84c312268 (patch) | |
tree | ccc2e3537b09a8bb914db2f89f98d86a5745f40d | |
parent | 2694839e85a4b0d7a294af8508238dc91483354b (diff) | |
parent | a09a09c43c186353e42f7abdda8d0c69d06ddf4d (diff) | |
download | cts-cb3345dd5c5dd1b44363e4082fdabbb84c312268.tar.gz |
Merge "Add support for RunWith Parameterized in ScopedStorageDeviceTest" into mainline-prod
3 files changed, 91 insertions, 86 deletions
diff --git a/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageBaseDeviceTest.java b/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageBaseDeviceTest.java new file mode 100644 index 00000000000..b3adc449953 --- /dev/null +++ b/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageBaseDeviceTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.scopedstorage.cts.device; + +import static android.scopedstorage.cts.lib.TestUtils.getExternalFilesDir; +import static android.scopedstorage.cts.lib.TestUtils.pollForExternalStorageState; +import static android.scopedstorage.cts.lib.TestUtils.resetDefaultExternalStorageVolume; +import static android.scopedstorage.cts.lib.TestUtils.setExternalStorageVolume; +import static android.scopedstorage.cts.lib.TestUtils.setupDefaultDirectories; + +import static androidx.test.InstrumentationRegistry.getContext; + +import static com.google.common.truth.Truth.assertThat; + +import android.provider.MediaStore; +import android.scopedstorage.cts.lib.TestUtils; + +import androidx.test.runner.AndroidJUnit4; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +@RunWith(AndroidJUnit4.class) +class ScopedStorageBaseDeviceTest { + @BeforeClass + public static void setup() throws Exception { + createPublicVolume(); + setupStorage(); + } + + private static void createPublicVolume() throws Exception { + if (TestUtils.getCurrentPublicVolumeName() == null) { + TestUtils.createNewPublicVolume(); + } + } + + private static void setupStorage() throws Exception { + if (!getContext().getPackageManager().isInstantApp()) { + pollForExternalStorageState(); + getExternalFilesDir().mkdirs(); + } + } + + void setupExternalStorage(String volumeName) { + assertThat(volumeName).isNotNull(); + if (volumeName.equals(MediaStore.VOLUME_EXTERNAL)) { + resetDefaultExternalStorageVolume(); + TestUtils.assertDefaultVolumeIsPrimary(); + } else { + setExternalStorageVolume(volumeName); + TestUtils.assertDefaultVolumeIsPublic(); + } + setupDefaultDirectories(); + } + + static List<String> getTestParameters() { + return Arrays.asList( + MediaStore.VOLUME_EXTERNAL, + TestUtils.getCurrentPublicVolumeName() + ); + } +} diff --git a/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageDeviceTest.java b/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageDeviceTest.java index 0fc16416751..363fbd30902 100644 --- a/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageDeviceTest.java +++ b/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStorageDeviceTest.java @@ -74,7 +74,6 @@ import static android.scopedstorage.cts.lib.TestUtils.installAppWithStoragePermi import static android.scopedstorage.cts.lib.TestUtils.isAppInstalled; import static android.scopedstorage.cts.lib.TestUtils.listAs; import static android.scopedstorage.cts.lib.TestUtils.openWithMediaProvider; -import static android.scopedstorage.cts.lib.TestUtils.pollForExternalStorageState; import static android.scopedstorage.cts.lib.TestUtils.queryFile; import static android.scopedstorage.cts.lib.TestUtils.queryFileExcludingPending; import static android.scopedstorage.cts.lib.TestUtils.queryImageFile; @@ -82,7 +81,6 @@ import static android.scopedstorage.cts.lib.TestUtils.queryVideoFile; import static android.scopedstorage.cts.lib.TestUtils.readExifMetadataFromTestApp; import static android.scopedstorage.cts.lib.TestUtils.revokePermission; import static android.scopedstorage.cts.lib.TestUtils.setAttrAs; -import static android.scopedstorage.cts.lib.TestUtils.setupDefaultDirectories; import static android.scopedstorage.cts.lib.TestUtils.uninstallApp; import static android.scopedstorage.cts.lib.TestUtils.uninstallAppNoThrow; import static android.scopedstorage.cts.lib.TestUtils.updateDisplayNameWithMediaProvider; @@ -119,14 +117,12 @@ import android.os.FileUtils; import android.os.ParcelFileDescriptor; import android.os.Process; import android.provider.MediaStore; -import android.scopedstorage.cts.lib.TestUtils; import android.system.ErrnoException; import android.system.Os; import android.system.StructStat; import android.util.Log; import androidx.annotation.Nullable; -import androidx.test.runner.AndroidJUnit4; import com.android.cts.install.lib.TestApp; @@ -137,6 +133,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; import java.io.File; import java.io.FileDescriptor; @@ -153,8 +152,8 @@ import java.util.List; /** * Device-side test suite to verify scoped storage business logic. */ -@RunWith(AndroidJUnit4.class) -public class ScopedStorageDeviceTest { +@RunWith(Parameterized.class) +public class ScopedStorageDeviceTest extends ScopedStorageBaseDeviceTest { public static final String STR_DATA1 = "Just some random text"; public static final byte[] BYTES_DATA1 = STR_DATA1.getBytes(); @@ -209,20 +208,12 @@ public class ScopedStorageDeviceTest { private static final String OPSTR_MANAGE_EXTERNAL_STORAGE = permissionToOp(Manifest.permission.MANAGE_EXTERNAL_STORAGE); - @BeforeClass - public static void verifyTestsWillRunOnPrimaryVolume() throws Exception { - TestUtils.resetDefaultExternalStorageVolume(); - TestUtils.assertDefaultVolumeIsPrimary(); - } + @Parameter(0) + public String mVolumeName; - @BeforeClass - public static void createPublicVolume() throws Exception { - // Create a public volume. It's not used in this test right now, but it makes for a less - // flaky test to create here. ScopedStoragePublicVolumeDeviceTest will be folded into - // this test later, as a prametererized option, as tracked in b/159593019. - if (TestUtils.getCurrentPublicVolumeName() == null) { - TestUtils.createNewPublicVolume(); - } + @Parameters + public static Iterable<? extends Object> data() { + return ScopedStorageDeviceTest.getTestParameters(); } @BeforeClass @@ -245,14 +236,6 @@ public class ScopedStorageDeviceTest { Manifest.permission.WRITE_EXTERNAL_STORAGE)).isTrue(); } - @BeforeClass - public static void setupStorage() throws Exception { - if (!getContext().getPackageManager().isInstantApp()) { - pollForExternalStorageState(); - getExternalFilesDir().mkdirs(); - } - } - @After public void tearDown() throws Exception { executeShellCommand("rm -r /sdcard/Android/data/com.android.shell"); @@ -260,7 +243,8 @@ public class ScopedStorageDeviceTest { @Before public void setupExternalStorage() { - setupDefaultDirectories(); + super.setupExternalStorage(mVolumeName); + Log.i(TAG, "Using volume : " + mVolumeName); } /** diff --git a/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStoragePublicVolumeDeviceTest.java b/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStoragePublicVolumeDeviceTest.java deleted file mode 100644 index 20f4274e7c6..00000000000 --- a/hostsidetests/scopedstorage/device/src/android/scopedstorage/cts/device/ScopedStoragePublicVolumeDeviceTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.scopedstorage.cts.device; - -import static com.google.common.truth.Truth.assertThat; - -import android.scopedstorage.cts.lib.TestUtils; - -import androidx.test.runner.AndroidJUnit4; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; - -/** - * Test suite to run ScopedStorageDeviceTest on a public volume. - */ -@RunWith(AndroidJUnit4.class) -public class ScopedStoragePublicVolumeDeviceTest extends ScopedStorageDeviceTest { - - @BeforeClass - public static void createPublicVolume() throws Exception { - ScopedStorageDeviceTest.createPublicVolume(); - } - - @BeforeClass - public static void setupApps() throws Exception { - ScopedStorageDeviceTest.setupApps(); - } - - @AfterClass - public static void resetDefaultVolume() throws Exception { - TestUtils.resetDefaultExternalStorageVolume(); - } - - @BeforeClass - public static void setupStorage() throws Exception { - String volumeName = TestUtils.getPublicVolumeName(); - assertThat(volumeName).isNotNull(); - TestUtils.setExternalStorageVolume(volumeName); - TestUtils.assertDefaultVolumeIsPublic(); - ScopedStorageDeviceTest.setupStorage(); - } -} |