• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 com.android.settings;
18 
19 import static com.android.settings.ConfirmDeviceCredentialBaseFragment.LastTryDialog;
20 import static com.google.common.truth.Truth.assertThat;
21 
22 import android.R;
23 import android.app.Activity;
24 import android.app.Fragment;
25 import android.app.FragmentManager;
26 
27 import com.android.settings.testutils.shadow.SettingsShadowResources;
28 
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.Robolectric;
32 import org.robolectric.annotation.Config;
33 
34 @RunWith(SettingsRobolectricTestRunner.class)
35 @Config(
36         manifest = TestConfig.MANIFEST_PATH,
37         sdk = TestConfig.SDK_VERSION,
38         shadows = {
39                 SettingsShadowResources.class,
40                 SettingsShadowResources.SettingsShadowTheme.class,
41         })
42 public class ConfirmCredentialTest {
43     @Test
testLastTryDialogShownExactlyOnce()44     public void testLastTryDialogShownExactlyOnce() {
45         FragmentManager fm = Robolectric.buildActivity(Activity.class).get().getFragmentManager();
46 
47         // Launch only one instance at a time.
48         assertThat(LastTryDialog.show(fm, "title", R.string.yes, R.string.ok, false)).isTrue();
49         assertThat(LastTryDialog.show(fm, "title", R.string.yes, R.string.ok, false)).isFalse();
50 
51         // After cancelling, the dialog should be re-shown when asked for.
52         LastTryDialog.hide(fm);
53         assertThat(LastTryDialog.show(fm, "title", R.string.yes, R.string.ok, false)).isTrue();
54     }
55 }
56