1a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes/*
2a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * Copyright (C) 2015 The Android Open Source Project
3a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes *
4a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * Licensed under the Apache License, Version 2.0 (the "License");
5a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * you may not use this file except in compliance with the License.
6a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * You may obtain a copy of the License at
7a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes *
8a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes *      http://www.apache.org/licenses/LICENSE-2.0
9a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes *
10a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * Unless required by applicable law or agreed to in writing, software
11a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * distributed under the License is distributed on an "AS IS" BASIS,
12a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * See the License for the specific language governing permissions and
14a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes * limitations under the License.
15a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes */
16a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
17a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banespackage android.support.v7.app;
18a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
19a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banesimport org.junit.Test;
20a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
21a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banesimport android.app.Dialog;
22a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banesimport android.os.Bundle;
23a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banesimport android.support.v7.internal.app.WindowDecorActionBar;
24a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
25a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banespublic class DialogTestCase extends BaseInstrumentationTestCase<WindowDecorActionBarActivity> {
26a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
27a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    public DialogTestCase() {
28a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        super(WindowDecorActionBarActivity.class);
29a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    }
30a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
31a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    @Test
32a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    public void testDialogFragmentShows() {
33a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        getInstrumentation().waitForIdleSync();
34a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
35a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        TestDialogFragment fragment = new TestDialogFragment();
36a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        fragment.show(getActivity().getSupportFragmentManager(), null);
37a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
38a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        getInstrumentation().waitForIdleSync();
39a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
40a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        assertNotNull("Dialog was null", fragment.getDialog());
41a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        assertTrue("Dialog was not being shown", fragment.getDialog().isShowing());
42a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    }
43a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
44a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    public static class TestDialogFragment extends AppCompatDialogFragment {
45a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        @Override
46a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        public Dialog onCreateDialog(Bundle savedInstanceState) {
47a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes            return new AlertDialog.Builder(getActivity())
48a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes                    .setTitle("Test")
49a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes                    .setMessage("Message")
50a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes                    .setPositiveButton("Button", null)
51a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes                    .create();
52a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes        }
53a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes    }
54a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes}
55a4b5c35036e68c7551dd77641ceec17b92c6368dChris Banes
56