blob: 022e15f325a178e3c2d04d1c03b00172738aa8aa [file] [log] [blame]
jovanaka6647762018-06-26 14:09:30 -07001/*
2 * Copyright (C) 2018 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
17package com.android.car.settings.testutils;
18
19import android.widget.Button;
jovanak7cb44972018-08-21 16:48:28 -070020import android.widget.TextView;
jovanaka6647762018-06-26 14:09:30 -070021
22import androidx.fragment.app.DialogFragment;
23
jovanaka6647762018-06-26 14:09:30 -070024/**
25 * Helper methods for DialogFragment testing.
26 */
27public class DialogTestUtils {
Heemin Seog11d45c12018-11-20 13:47:34 -080028 private DialogTestUtils() {
29 }
jovanaka6647762018-06-26 14:09:30 -070030
31 /**
32 * Invokes onClick on the dialog's positive button.
33 */
34 public static void clickPositiveButton(DialogFragment dialogFragment) {
Heemin Seog11d45c12018-11-20 13:47:34 -080035 Button positiveButton = dialogFragment.getDialog().getWindow().findViewById(
36 com.android.internal.R.id.button1);
jovanaka6647762018-06-26 14:09:30 -070037 positiveButton.callOnClick();
38 }
39
40 /**
41 * Invokes onClick on the dialog's negative button.
42 */
jovanak7cb44972018-08-21 16:48:28 -070043 public static void clickNegativeButton(DialogFragment dialogFragment) {
Heemin Seog11d45c12018-11-20 13:47:34 -080044 Button negativeButton = dialogFragment.getDialog().getWindow().findViewById(
45 com.android.internal.R.id.button2);
jovanaka6647762018-06-26 14:09:30 -070046 negativeButton.callOnClick();
47 }
jovanak7cb44972018-08-21 16:48:28 -070048
49 /**
50 * Gets dialog's title.
51 */
52 public static String getTitle(DialogFragment dialogFragment) {
Heemin Seog11d45c12018-11-20 13:47:34 -080053 TextView titleView = dialogFragment.getDialog().getWindow().findViewById(
54 com.android.internal.R.id.alertTitle);
jovanak7cb44972018-08-21 16:48:28 -070055 return titleView.getText().toString();
56 }
JianYang Liu67deaf02020-01-31 10:56:54 -080057
58 public static String getMessage(DialogFragment dialogFragment) {
59 TextView messageView = dialogFragment.getDialog().getWindow().findViewById(
60 com.android.internal.R.id.message);
61 return messageView.getText().toString();
62 }
jovanaka6647762018-06-26 14:09:30 -070063}