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 BroadcastRestrictionsHostTest extends BaseHostJUnit4Test { 31 private static final String TEST_APP_RESTRICTIONS_PACKAGE = "com.android.tests.sdksandbox"; 32 private static final String TEST_APP_BROADCAST_RESTRICTIONS_APK = 33 "BroadcastRestrictionsTestApp.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.BroadcastRestrictionsTestApp", 46 phase)) 47 .isTrue(); 48 } 49 50 @Before setUp()51 public void setUp() throws Exception { 52 installPackage(TEST_APP_BROADCAST_RESTRICTIONS_APK); 53 } 54 55 @After tearDown()56 public void tearDown() throws Exception { 57 uninstallPackage(TEST_APP_RESTRICTIONS_PACKAGE); 58 } 59 60 @Test testRegisterBroadcastReceiver_defaultValueRestrictionsNotApplied()61 public void testRegisterBroadcastReceiver_defaultValueRestrictionsNotApplied() 62 throws Exception { 63 runPhase("testRegisterBroadcastReceiver_defaultValueRestrictionsNotApplied"); 64 } 65 66 @Test testRegisterBroadcastReceiver_restrictionsApplied()67 public void testRegisterBroadcastReceiver_restrictionsApplied() throws Exception { 68 runPhase("testRegisterBroadcastReceiver_restrictionsApplied"); 69 } 70 71 @Test testRegisterBroadcastReceiver_restrictionsNotApplied()72 public void testRegisterBroadcastReceiver_restrictionsNotApplied() throws Exception { 73 runPhase("testRegisterBroadcastReceiver_restrictionsNotApplied"); 74 } 75 76 @Test testRegisterBroadcastReceiver_defaultValueRestrictionsNotApplied_preU()77 public void testRegisterBroadcastReceiver_defaultValueRestrictionsNotApplied_preU() 78 throws Exception { 79 runPhase("testRegisterBroadcastReceiver_defaultValueRestrictionsNotApplied_preU"); 80 } 81 82 @Test testRegisterBroadcastReceiver_restrictionsApplied_preU()83 public void testRegisterBroadcastReceiver_restrictionsApplied_preU() throws Exception { 84 runPhase("testRegisterBroadcastReceiver_restrictionsApplied_preU"); 85 } 86 87 @Test testRegisterBroadcastReceiver_restrictionsNotApplied_preU()88 public void testRegisterBroadcastReceiver_restrictionsNotApplied_preU() throws Exception { 89 runPhase("testRegisterBroadcastReceiver_restrictionsNotApplied_preU"); 90 } 91 92 @Test testRegisterBroadcastReceiver_intentFilterWithoutAction()93 public void testRegisterBroadcastReceiver_intentFilterWithoutAction() throws Exception { 94 runPhase("testRegisterBroadcastReceiver_intentFilterWithoutAction"); 95 } 96 97 @Test testRegisterBroadcastReceiver_intentFilterWithoutAction_preU()98 public void testRegisterBroadcastReceiver_intentFilterWithoutAction_preU() throws Exception { 99 runPhase("testRegisterBroadcastReceiver_intentFilterWithoutAction_preU"); 100 } 101 } 102