1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.documentsui; 18 19 import static junit.framework.Assert.fail; 20 21 import static org.mockito.Mockito.mock; 22 23 import android.content.ContentProviderClient; 24 import android.content.pm.PackageManager; 25 26 import androidx.test.filters.MediumTest; 27 28 import com.android.documentsui.testing.TestEnv; 29 import com.android.documentsui.testing.TestProvidersAccess; 30 import com.android.modules.utils.build.SdkLevel; 31 32 import com.google.common.collect.Lists; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.junit.runners.Parameterized; 38 import org.junit.runners.Parameterized.Parameter; 39 import org.junit.runners.Parameterized.Parameters; 40 41 @RunWith(Parameterized.class) 42 @MediumTest 43 public class DocumentsAccessTest { 44 45 private final TestConfigStore mTestConfigStore = new TestConfigStore(); 46 private TestActivity mActivity; 47 private DocumentsAccess mDocumentsAccess; 48 private TestEnv mEnv; 49 private ContentProviderClient mMockContentProviderClient = mock(ContentProviderClient.class); 50 51 @Parameter(0) 52 public boolean isPrivateSpaceEnabled; 53 54 /** 55 * Parametrize values for {@code isPrivateSpaceEnabled} to run all the tests twice once with 56 * private space flag enabled and once with it disabled. 57 */ 58 @Parameters(name = "privateSpaceEnabled={0}") data()59 public static Iterable<?> data() { 60 return Lists.newArrayList(true, false); 61 } 62 63 @Before setUp()64 public void setUp() throws PackageManager.NameNotFoundException { 65 mEnv = TestEnv.create(); 66 mEnv.reset(); 67 mActivity = TestActivity.create(mEnv); 68 mDocumentsAccess = DocumentsAccess.create(mActivity, mEnv.state); 69 mEnv.state.configStore = mTestConfigStore; 70 isPrivateSpaceEnabled = SdkLevel.isAtLeastS() && isPrivateSpaceEnabled; 71 if (isPrivateSpaceEnabled) { 72 mTestConfigStore.enablePrivateSpaceInPhotoPicker(); 73 } 74 } 75 76 @Test testCreateDocument_noPermission()77 public void testCreateDocument_noPermission() throws Exception { 78 try { 79 mDocumentsAccess.getDocuments(TestProvidersAccess.OtherUser.USER_ID, "authority", 80 Lists.newArrayList("docId")); 81 fail("Expects CrossProfileNoPermissionException"); 82 } catch (CrossProfileNoPermissionException e) { 83 // expected. 84 } 85 } 86 } 87