1 /* 2 * Copyright (C) 2023 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.tests.sdksandbox.host; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 22 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 23 24 import org.junit.After; 25 import org.junit.Before; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @RunWith(DeviceJUnit4ClassRunner.class) 30 public class ContentProviderRestrictionsHostTest extends BaseHostJUnit4Test { 31 private static final String TEST_APP_RESTRICTIONS_PACKAGE = "com.android.tests.sdksandbox"; 32 private static final String TEST_APP_CONTENT_PROVIDER_RESTRICTIONS_APK = 33 "ContentProviderRestrictionsTestApp.apk"; 34 35 /** 36 * Runs the given phase of a test by calling into the device. Throws an exception if the test 37 * phase fails. 38 * 39 * <p>For example, <code>runPhase("testExample");</code> 40 */ runPhase(String phase)41 private void runPhase(String phase) throws Exception { 42 assertThat( 43 runDeviceTests( 44 TEST_APP_RESTRICTIONS_PACKAGE, 45 "com.android.tests.sdksandbox.ContentProviderRestrictionsTestApp", 46 phase)) 47 .isTrue(); 48 } 49 50 @Before setUp()51 public void setUp() throws Exception { 52 installPackage(TEST_APP_CONTENT_PROVIDER_RESTRICTIONS_APK); 53 } 54 55 @After tearDown()56 public void tearDown() throws Exception { 57 uninstallPackage(TEST_APP_RESTRICTIONS_PACKAGE); 58 } 59 60 @Test testGetContentProvider_restrictionsApplied()61 public void testGetContentProvider_restrictionsApplied() throws Exception { 62 runPhase("testGetContentProvider_restrictionsApplied"); 63 } 64 65 @Test testRegisterContentObserver_restrictionsApplied()66 public void testRegisterContentObserver_restrictionsApplied() throws Exception { 67 runPhase("testRegisterContentObserver_restrictionsApplied"); 68 } 69 70 @Test testGetContentProvider_restrictionsNotApplied()71 public void testGetContentProvider_restrictionsNotApplied() throws Exception { 72 runPhase("testGetContentProvider_restrictionsNotApplied"); 73 } 74 75 @Test testRegisterContentObserver_restrictionsNotApplied()76 public void testRegisterContentObserver_restrictionsNotApplied() throws Exception { 77 runPhase("testRegisterContentObserver_restrictionsNotApplied"); 78 } 79 80 @Test testGetContentProvider_defaultValueRestrictionsNotApplied()81 public void testGetContentProvider_defaultValueRestrictionsNotApplied() throws Exception { 82 runPhase("testGetContentProvider_defaultValueRestrictionsNotApplied"); 83 } 84 85 @Test testRegisterContentObserver_defaultValueRestrictionsNotApplied()86 public void testRegisterContentObserver_defaultValueRestrictionsNotApplied() throws Exception { 87 runPhase("testRegisterContentObserver_defaultValueRestrictionsNotApplied"); 88 } 89 } 90