• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 android.view;
18 
19 import android.content.Context;
20 import android.test.AndroidTestCase;
21 import android.test.suitebuilder.annotation.SmallTest;
22 
23 public class ViewGroupAttributesTest extends AndroidTestCase {
24 
25     private MyViewGroup mViewGroup;
26 
27     private static final class MyViewGroup extends ViewGroup {
28 
MyViewGroup(Context context)29         public MyViewGroup(Context context) {
30             super(context);
31         }
32 
33         @Override
onLayout(boolean changed, int l, int t, int r, int b)34         protected void onLayout(boolean changed, int l, int t, int r, int b) {
35         }
36 
37         @Override
isChildrenDrawnWithCacheEnabled()38         public boolean isChildrenDrawnWithCacheEnabled() {
39             return super.isChildrenDrawnWithCacheEnabled();
40         }
41     }
42 
43     @Override
setUp()44     protected void setUp() throws Exception {
45         super.setUp();
46         mViewGroup = new MyViewGroup(getContext());
47     }
48 
49     @SmallTest
testDescendantFocusabilityEnum()50     public void testDescendantFocusabilityEnum() {
51         assertEquals("expected ViewGroup.FOCUS_BEFORE_DESCENDANTS to be default",
52                 ViewGroup.FOCUS_BEFORE_DESCENDANTS, mViewGroup.getDescendantFocusability());
53 
54         // remember some state before we muck with flags
55         final boolean isAnimationCachEnabled = mViewGroup.isAnimationCacheEnabled();
56         final boolean isAlwaysDrawnWithCacheEnabled = mViewGroup.isAlwaysDrawnWithCacheEnabled();
57         final boolean isChildrenDrawnWithCacheEnabled = mViewGroup.isChildrenDrawnWithCacheEnabled();
58 
59         mViewGroup.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
60         assertEquals(ViewGroup.FOCUS_AFTER_DESCENDANTS, mViewGroup.getDescendantFocusability());
61 
62         mViewGroup.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
63         assertEquals(ViewGroup.FOCUS_BLOCK_DESCENDANTS, mViewGroup.getDescendantFocusability());
64 
65         mViewGroup.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
66         assertEquals(ViewGroup.FOCUS_BEFORE_DESCENDANTS, mViewGroup.getDescendantFocusability());
67 
68         // verify we didn't change something unrelated
69         final String msg = "setDescendantFocusability messed with an unrelated flag";
70         assertEquals(msg, isAnimationCachEnabled, mViewGroup.isAnimationCacheEnabled());
71         assertEquals(msg, isAlwaysDrawnWithCacheEnabled, mViewGroup.isAlwaysDrawnWithCacheEnabled());
72         assertEquals(msg, isChildrenDrawnWithCacheEnabled, mViewGroup.isChildrenDrawnWithCacheEnabled());
73     }
74 
75     @SmallTest
testWrongIntSetForDescendantFocusabilityEnum()76     public void testWrongIntSetForDescendantFocusabilityEnum() {
77         try {
78             mViewGroup.setDescendantFocusability(0);
79             fail("expected setting wrong flag to throw an exception");
80         } catch (IllegalArgumentException expected) {
81         }
82     }
83 }
84