1 /* 2 * Copyright (C) 2023 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.privacy; 18 19 20 import static com.google.common.truth.Truth.assertThat; 21 22 import static org.mockito.ArgumentMatchers.any; 23 import static org.mockito.Mockito.spy; 24 import static org.mockito.Mockito.when; 25 26 import android.content.Context; 27 import android.os.Looper; 28 29 import androidx.test.annotation.UiThreadTest; 30 import androidx.test.core.app.ApplicationProvider; 31 32 import com.android.settings.TestUtils; 33 import com.android.settings.safetycenter.SafetyCenterManagerWrapper; 34 import com.android.settings.search.BaseSearchIndexProvider; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.mockito.Mock; 39 import org.mockito.MockitoAnnotations; 40 41 import java.util.List; 42 43 public class PrivacyDashboardFragmentTest { 44 45 private Context mContext; 46 private PrivacyDashboardFragment mPrivacyDashboardFragment; 47 48 @Mock 49 private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper; 50 51 @Before 52 @UiThreadTest setUp()53 public void setUp() { 54 MockitoAnnotations.initMocks(this); 55 MockitoAnnotations.initMocks(this); 56 if (Looper.myLooper() == null) { 57 Looper.prepare(); 58 } 59 60 mContext = ApplicationProvider.getApplicationContext(); 61 SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper; 62 mPrivacyDashboardFragment = spy(new PrivacyDashboardFragment()); 63 when(mPrivacyDashboardFragment.getContext()).thenReturn(mContext); 64 } 65 66 @Test whenSafetyCenterIsEnabled_pageIndexExcluded()67 public void whenSafetyCenterIsEnabled_pageIndexExcluded() throws Exception { 68 when(mSafetyCenterManagerWrapper.isEnabled(any())).thenReturn(true); 69 BaseSearchIndexProvider indexProvider = PrivacyDashboardFragment.SEARCH_INDEX_DATA_PROVIDER; 70 71 List<String> allXmlKeys = TestUtils.getAllXmlKeys(mContext, indexProvider); 72 List<String> nonIndexableKeys = indexProvider.getNonIndexableKeys(mContext); 73 allXmlKeys.removeAll(nonIndexableKeys); 74 75 assertThat(allXmlKeys).isEmpty(); 76 } 77 } 78