Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 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 android.app.cts;
     17 
     18 import static org.mockito.Mockito.*;
     19 
     20 import android.app.stubs.MockActivity;
     21 import android.support.test.annotation.UiThreadTest;
     22 import android.support.test.rule.ActivityTestRule;
     23 import android.support.test.runner.AndroidJUnit4;
     24 import android.test.suitebuilder.annotation.SmallTest;
     25 import android.view.ActionMode;
     26 import android.view.Window;
     27 
     28 import org.junit.Before;
     29 import org.junit.Rule;
     30 import org.junit.Test;
     31 import org.junit.runner.RunWith;
     32 
     33 import static org.junit.Assert.*;
     34 
     35 @SmallTest
     36 @RunWith(AndroidJUnit4.class)
     37 public class ActivityActionModeTest {
     38 
     39     private ActionMode.Callback mCallback;
     40 
     41     @Rule
     42     public ActivityTestRule<MockActivity> mActivityRule =
     43             new ActivityTestRule<>(MockActivity.class);
     44 
     45     @Before
     46     public void setUp() {
     47         mCallback = mock(ActionMode.Callback.class);
     48         when(mCallback.onCreateActionMode(any(), any())).thenReturn(true);
     49         when(mCallback.onPrepareActionMode(any(), any())).thenReturn(true);
     50     }
     51 
     52     @Test
     53     @UiThreadTest
     54     public void testStartPrimaryActionMode() {
     55         if (!mActivityRule.getActivity().getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
     56             return;
     57         }
     58 
     59         final ActionMode mode = mActivityRule.getActivity().startActionMode(
     60                 mCallback, ActionMode.TYPE_PRIMARY);
     61 
     62         assertNotNull(mode);
     63         assertEquals(ActionMode.TYPE_PRIMARY, mode.getType());
     64     }
     65 
     66     @Test
     67     @UiThreadTest
     68     public void testStartFloatingActionMode() {
     69         if (!mActivityRule.getActivity().getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
     70             return;
     71         }
     72 
     73         final ActionMode mode = mActivityRule.getActivity().startActionMode(
     74                 mCallback, ActionMode.TYPE_FLOATING);
     75 
     76         assertNotNull(mode);
     77         assertEquals(ActionMode.TYPE_FLOATING, mode.getType());
     78     }
     79 
     80     @Test
     81     @UiThreadTest
     82     public void testStartTypelessActionMode() {
     83         if (!mActivityRule.getActivity().getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
     84             return;
     85         }
     86 
     87         final ActionMode mode = mActivityRule.getActivity().startActionMode(mCallback);
     88 
     89         assertNotNull(mode);
     90         assertEquals(ActionMode.TYPE_PRIMARY, mode.getType());
     91     }
     92 }
     93