1f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy/*
2f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * Copyright (C) 2007 The Android Open Source Project
3f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy *
4f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * you may not use this file except in compliance with the License.
6f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * You may obtain a copy of the License at
7f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy *
8f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy *
10f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * Unless required by applicable law or agreed to in writing, software
11f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * See the License for the specific language governing permissions and
14f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * limitations under the License.
15f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy */
16f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
171d3165f10b12165f02b7015ac1a817c5f60e6399Neal Nguyenpackage android.widget;
18f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
191d3165f10b12165f02b7015ac1a817c5f60e6399Neal Nguyenimport com.android.frameworks.coretests.R;
20f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
21f32b488bd205ae2b026f47ee898073fd4815da90Romain Guyimport android.test.ActivityInstrumentationTestCase2;
22f76c56bcaa9df1d1afa711177f813dc63f399795Brett Chabotimport android.test.TouchUtils;
23f32b488bd205ae2b026f47ee898073fd4815da90Romain Guyimport android.test.suitebuilder.annotation.LargeTest;
24f76c56bcaa9df1d1afa711177f813dc63f399795Brett Chabotimport android.test.suitebuilder.annotation.MediumTest;
25f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
26f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy/**
27f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy * Exercises {@link android.widget.RadioGroup}'s check feature.
28f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy */
29f32b488bd205ae2b026f47ee898073fd4815da90Romain Guypublic class RadioGroupPreCheckedTest extends ActivityInstrumentationTestCase2<RadioGroupActivity> {
30f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    public RadioGroupPreCheckedTest() {
31f76c56bcaa9df1d1afa711177f813dc63f399795Brett Chabot        super(RadioGroupActivity.class);
32f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    }
33f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
34f76c56bcaa9df1d1afa711177f813dc63f399795Brett Chabot    @MediumTest
35f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    public void testRadioButtonPreChecked() throws Exception {
36f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        final RadioGroupActivity activity = getActivity();
37f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
38f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        RadioButton radio = (RadioButton) activity.findViewById(R.id.value_one);
39f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        assertTrue("The first radio button should be checked", radio.isChecked());
40f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
41f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        RadioGroup group = (RadioGroup) activity.findViewById(R.id.group);
42f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        assertEquals("The first radio button should be checked", R.id.value_one,
43f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy                group.getCheckedRadioButtonId());
44f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    }
45f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
46f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    @LargeTest
47f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    public void testRadioButtonChangePreChecked() throws Exception {
48f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        final RadioGroupActivity activity = getActivity();
49f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
50f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        RadioButton radio = (RadioButton) activity.findViewById(R.id.value_two);
51f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        TouchUtils.clickView(this, radio);
52f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
53f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        RadioButton old = (RadioButton) activity.findViewById(R.id.value_one);
54f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
55f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        assertFalse("The first radio button should not be checked", old.isChecked());
56f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        assertTrue("The second radio button should be checked", radio.isChecked());
57f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy
58f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        RadioGroup group = (RadioGroup) activity.findViewById(R.id.group);
59f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy        assertEquals("The second radio button should be checked", R.id.value_two,
60f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy                group.getCheckedRadioButtonId());
61f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy    }
62f32b488bd205ae2b026f47ee898073fd4815da90Romain Guy}
63