OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / core / tests / coretests / src / android / widget / focus / HorizontalFocusSearchTest.java
1 /*
2  * Copyright (C) 2007 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.widget.focus;
18
19 import android.widget.focus.HorizontalFocusSearch;
20
21 import android.test.ActivityInstrumentationTestCase;
22 import android.test.suitebuilder.annotation.Suppress;
23 import android.widget.LinearLayout;
24 import android.widget.Button;
25 import android.view.View;
26
27 import static android.widget.focus.VerticalFocusSearchTest.FocusSearchAlg;
28 import static android.widget.focus.VerticalFocusSearchTest.NewFocusSearchAlg;
29
30 /**
31  * Tests that focus searching works on a horizontal linear layout of buttons of
32  * various widths and vertical placements.
33  */
34 // Suppress until bug http://b/issue?id=1416545 is fixed.
35 @Suppress
36 public class HorizontalFocusSearchTest extends ActivityInstrumentationTestCase<HorizontalFocusSearch> {
37
38     private FocusSearchAlg mFocusFinder;
39
40     private LinearLayout mLayout;
41     private Button mLeftTall;
42     private Button mMidShort1Top;
43     private Button mMidShort2Bottom;
44     private Button mRightTall;
45
46
47     public HorizontalFocusSearchTest() {
48         super("com.android.frameworks.coretests", HorizontalFocusSearch.class);
49     }
50
51     @Override
52     protected void setUp() throws Exception {
53         super.setUp();
54
55         mFocusFinder = new NewFocusSearchAlg();
56
57         mLayout = getActivity().getLayout();
58         mLeftTall = getActivity().getLeftTall();
59         mMidShort1Top = getActivity().getMidShort1Top();
60         mMidShort2Bottom = getActivity().getMidShort2Bottom();
61         mRightTall = getActivity().getRightTall();
62     }
63
64     public void testPreconditions() {
65         assertNotNull(mLayout);
66         assertNotNull(mLeftTall);
67         assertNotNull(mMidShort1Top);
68         assertNotNull(mMidShort2Bottom);
69         assertNotNull(mRightTall);
70     }
71
72     public void testSearchFromLeftButton() {
73         assertNull("going up from mLeftTall",
74                 mFocusFinder.findNextFocus(mLayout, mLeftTall, View.FOCUS_UP));
75         assertNull("going down from mLeftTall",
76                 mFocusFinder.findNextFocus(mLayout, mLeftTall, View.FOCUS_DOWN));
77         assertNull("going left from mLeftTall",
78                 mFocusFinder.findNextFocus(mLayout, mLeftTall, View.FOCUS_LEFT));
79
80         assertEquals("going right from mLeftTall",
81                 mMidShort1Top,
82                 mFocusFinder.findNextFocus(mLayout, mLeftTall, View.FOCUS_RIGHT));
83     }
84
85     public void TODO_testSearchFromMiddleLeftButton() {
86         assertNull("going up from mMidShort1Top",
87                 mFocusFinder.findNextFocus(mLayout, mMidShort1Top, View.FOCUS_UP));
88         assertEquals("going down from mMidShort1Top",
89                 mMidShort2Bottom,
90                 mFocusFinder.findNextFocus(mLayout, mMidShort1Top, View.FOCUS_DOWN));
91         assertEquals("going left from mMidShort1Top",
92                 mLeftTall,
93                 mFocusFinder.findNextFocus(mLayout, mMidShort1Top, View.FOCUS_LEFT));
94         assertEquals("going right from mMidShort1Top",
95                 mMidShort2Bottom,
96                 mFocusFinder.findNextFocus(mLayout, mMidShort1Top, View.FOCUS_RIGHT));
97     }
98
99     public void TODO_testSearchFromMiddleRightButton() {
100         assertEquals("going up from mMidShort2Bottom",
101                 mMidShort1Top,
102                 mFocusFinder.findNextFocus(mLayout, mMidShort2Bottom, View.FOCUS_UP));
103         assertNull("going down from mMidShort2Bottom",
104                 mFocusFinder.findNextFocus(mLayout, mMidShort2Bottom, View.FOCUS_DOWN));
105         assertEquals("going left from mMidShort2Bottom",
106                 mMidShort1Top,
107                 mFocusFinder.findNextFocus(mLayout, mMidShort2Bottom, View.FOCUS_LEFT));
108         assertEquals("goind right from mMidShort2Bottom",
109                 mRightTall,
110                 mFocusFinder.findNextFocus(mLayout, mMidShort2Bottom, View.FOCUS_RIGHT));
111     }
112
113     public void testSearchFromRightButton() {
114         assertNull("going up from mRightTall",
115                 mFocusFinder.findNextFocus(mLayout, mRightTall, View.FOCUS_UP));
116         assertNull("going down from mRightTall",
117                 mFocusFinder.findNextFocus(mLayout, mRightTall, View.FOCUS_DOWN));
118         assertEquals("going left from mRightTall",
119                 mMidShort2Bottom,
120                 mFocusFinder.findNextFocus(mLayout, mRightTall, View.FOCUS_LEFT));
121         assertNull("going right from mRightTall",
122                 mFocusFinder.findNextFocus(mLayout, mRightTall, View.FOCUS_RIGHT));
123     }
124 }