• 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.applications;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.verify;
23 
24 import android.app.settings.SettingsEnums;
25 import android.os.Bundle;
26 
27 import com.android.internal.logging.nano.MetricsProto;
28 import com.android.settings.testutils.FakeFeatureFactory;
29 import com.android.settingslib.applications.ApplicationsState;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.MockitoAnnotations;
35 import org.robolectric.RobolectricTestRunner;
36 import org.robolectric.RuntimeEnvironment;
37 
38 @RunWith(RobolectricTestRunner.class)
39 public class UsageAccessDetailsTest {
40 
41     private FakeFeatureFactory mFeatureFactory;
42     private UsageAccessDetails mFragment;
43 
44     @Before
setUp()45     public void setUp() {
46         MockitoAnnotations.initMocks(this);
47         mFeatureFactory = FakeFeatureFactory.setupForTest();
48         mFragment = new UsageAccessDetails();
49         mFragment.onAttach(RuntimeEnvironment.application);
50     }
51 
52     @Test
logSpecialPermissionChange()53     public void logSpecialPermissionChange() {
54         mFragment.logSpecialPermissionChange(true, "app");
55         verify(mFeatureFactory.metricsFeatureProvider).action(
56                 SettingsEnums.PAGE_UNKNOWN,
57                 MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_ALLOW,
58                 mFragment.getMetricsCategory(),
59                 "app",
60                 0);
61 
62         mFragment.logSpecialPermissionChange(false, "app");
63         verify(mFeatureFactory.metricsFeatureProvider).action(
64                 SettingsEnums.PAGE_UNKNOWN,
65                 MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_USAGE_VIEW_DENY,
66                 mFragment.getMetricsCategory(),
67                 "app",
68                 0);
69     }
70 
71     @Test
refreshUi_hasNoAppEntry_shouldReturnFalse()72     public void refreshUi_hasNoAppEntry_shouldReturnFalse() {
73         mFragment.mState = mock(ApplicationsState.class);
74         mFragment.setArguments(new Bundle());
75 
76         assertThat(mFragment.refreshUi()).isFalse();
77         assertThat(mFragment.mAppEntry).isNull();
78         assertThat(mFragment.mPackageInfo).isNull();
79     }
80 }
81