1 /* 2 * Copyright (C) 2015 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.internal.widget; 18 19 import android.content.Context; 20 import android.test.AndroidTestCase; 21 import android.view.ActionMode; 22 import android.view.View; 23 import android.view.ViewGroup; 24 25 /** 26 * Tests for {@link ActionBarContainer}. 27 */ 28 public class ActionBarContainerTest extends AndroidTestCase { 29 private ActionBarContainer mActionBarContainer; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 mActionBarContainer = new ActionBarContainer(mContext); 35 } 36 37 public void testPrimaryActionModesAreStopped() { 38 TestViewGroup viewGroup = new TestViewGroup(mContext); 39 viewGroup.addView(mActionBarContainer); 40 41 ActionMode mode = mActionBarContainer.startActionModeForChild( 42 null, null, ActionMode.TYPE_PRIMARY); 43 44 assertNull(mode); 45 // Should not bubble up. 46 assertFalse(viewGroup.isStartActionModeForChildTypedCalled); 47 assertFalse(viewGroup.isStartActionModeForChildTypelessCalled); 48 49 mode = mActionBarContainer.startActionModeForChild(null, null); 50 51 assertNull(mode); 52 // Should not bubble up. 53 assertFalse(viewGroup.isStartActionModeForChildTypedCalled); 54 assertFalse(viewGroup.isStartActionModeForChildTypelessCalled); 55 } 56 57 public void testFloatingActionModesAreBubbledUp() { 58 TestViewGroup viewGroup = new TestViewGroup(mContext); 59 viewGroup.addView(mActionBarContainer); 60 61 ActionMode mode = mActionBarContainer.startActionModeForChild( 62 null, null, ActionMode.TYPE_FLOATING); 63 64 // Should bubble up. 65 assertNotNull(mode); 66 assertTrue(viewGroup.isStartActionModeForChildTypedCalled); 67 } 68 69 private static class TestViewGroup extends ViewGroup { 70 boolean isStartActionModeForChildTypedCalled = false; 71 boolean isStartActionModeForChildTypelessCalled = false; 72 73 public TestViewGroup(Context context) { 74 super(context); 75 } 76 77 @Override 78 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { 79 isStartActionModeForChildTypelessCalled = true; 80 return super.startActionModeForChild(originalView, callback); 81 } 82 83 @Override 84 public ActionMode startActionModeForChild( 85 View originalView, ActionMode.Callback callback, int type) { 86 isStartActionModeForChildTypedCalled = true; 87 return super.startActionModeForChild(originalView, callback, type); 88 } 89 90 @Override 91 protected void onLayout(boolean changed, int l, int t, int r, int b) {} 92 } 93 } 94