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