1 /* 2 * Copyright (C) 2013 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.tradefed.targetprep; 18 19 import static org.junit.Assert.*; 20 21 import com.android.tradefed.build.AppBuildInfo; 22 import com.android.tradefed.config.OptionSetter; 23 import com.android.tradefed.device.ITestDevice; 24 import com.android.tradefed.device.WifiHelper; 25 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 26 import com.android.tradefed.testtype.IDeviceTest; 27 import com.android.tradefed.util.FileUtil; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 import java.io.File; 33 34 /** 35 * A functional test for {@link AppSetup}. 36 * 37 * <p>Relies on WifiUtil.apk in tradefed.jar. 38 * 39 * <p>'aapt' must be in PATH. 40 */ 41 @RunWith(DeviceJUnit4ClassRunner.class) 42 public class AppSetupFuncTest implements IDeviceTest { 43 44 private ITestDevice mDevice; 45 46 @Override setDevice(ITestDevice device)47 public void setDevice(ITestDevice device) { 48 mDevice = device; 49 } 50 51 @Override getDevice()52 public ITestDevice getDevice() { 53 return mDevice; 54 } 55 56 /** Test end to end normal case for {@link AppSetup}. */ 57 @Test testSetupTeardown()58 public void testSetupTeardown() throws Exception { 59 // use wifiutil as a test apk since it already exists 60 getDevice().uninstallPackage(WifiHelper.INSTRUMENTATION_PKG); 61 File wifiapk = WifiHelper.extractWifiUtilApk(); 62 try { 63 AppBuildInfo appBuild = new AppBuildInfo("0", "stub"); 64 appBuild.addAppPackageFile(wifiapk, "0"); 65 AppSetup appSetup = new AppSetup(); 66 // turn off reboot to reduce test execution time 67 OptionSetter optionSetter = new OptionSetter(appSetup); 68 optionSetter.setOptionValue("reboot", "false"); 69 appSetup.setUp(getDevice(), appBuild); 70 assertTrue(getDevice().getUninstallablePackageNames().contains( 71 WifiHelper.INSTRUMENTATION_PKG)); 72 appSetup.tearDown(getDevice(), appBuild, null); 73 assertFalse(getDevice().getUninstallablePackageNames().contains( 74 WifiHelper.INSTRUMENTATION_PKG)); 75 } finally { 76 FileUtil.deleteFile(wifiapk); 77 } 78 } 79 } 80