Home | History | Annotate | Download | only in managedprofile
      1 /*
      2  * Copyright (C) 2017 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 package com.android.cts.managedprofile;
     17 
     18 import android.content.ComponentName;
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.support.test.InstrumentationRegistry;
     22 
     23 import com.android.compatibility.common.util.BlockingBroadcastReceiver;
     24 
     25 import org.junit.Before;
     26 import org.junit.Test;
     27 
     28 import static junit.framework.Assert.assertEquals;
     29 import static junit.framework.Assert.assertNotNull;
     30 
     31 /**
     32  * Basic sanity test to ensure some basic functionalities of work profile are working.
     33  */
     34 public class SanityTest {
     35     private static final ComponentName SIMPLE_APP_ACTIVITY =
     36             new ComponentName(
     37                     "com.android.cts.launcherapps.simpleapp",
     38                     "com.android.cts.launcherapps.simpleapp.SimpleActivity");
     39     /**
     40      * Broadcast sent from com.android.cts.launcherapps.simpleapp.SimpleActivity.
     41      */
     42     private static final String ACTIVITY_LAUNCHED_ACTION =
     43             "com.android.cts.launchertests.LauncherAppsTests.LAUNCHED_ACTION";
     44 
     45     private Context mContext;
     46 
     47     @Before
     48     public void setup() {
     49         mContext = InstrumentationRegistry.getTargetContext();
     50     }
     51 
     52     /**
     53      * Verify that we can launch an app that installed in work profile only.
     54      */
     55     @Test
     56     public void testLaunchAppInstalledInProfileOnly() throws Exception {
     57         BlockingBroadcastReceiver receiver =
     58                 new BlockingBroadcastReceiver(mContext, ACTIVITY_LAUNCHED_ACTION);
     59         try {
     60             receiver.register();
     61             Intent intent = new Intent();
     62             intent.setComponent(SIMPLE_APP_ACTIVITY);
     63             // Finish the activity after that.
     64             intent.putExtra("finish", true);
     65             mContext.startActivity(intent);
     66             Intent receivedBroadcast = receiver.awaitForBroadcast();
     67             assertNotNull(receivedBroadcast);
     68             assertEquals(ACTIVITY_LAUNCHED_ACTION, receivedBroadcast.getAction());
     69         } finally {
     70             receiver.unregisterQuietly();
     71         }
     72     }
     73 }
     74