1 /* 2 * Copyright (C) 2020 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 import static com.google.common.truth.Truth.assertThat; 20 21 import android.app.Instrumentation; 22 23 import androidx.test.core.app.ApplicationProvider; 24 import androidx.test.ext.junit.runners.AndroidJUnit4; 25 import androidx.test.filters.SmallTest; 26 import androidx.test.platform.app.InstrumentationRegistry; 27 28 import com.android.settings.testutils.AdbUtils; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 @RunWith(AndroidJUnit4.class) 35 @SmallTest 36 public class EnabledContentCapturePreferenceControllerComponentTest { 37 private Instrumentation mInstrumentation; 38 private static final String TAG = 39 EnabledContentCapturePreferenceControllerComponentTest.class.getSimpleName(); 40 41 @Before setUp()42 public void setUp() { 43 if (null == mInstrumentation) { 44 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 45 } 46 } 47 48 @Test test_uncheck_content_capture()49 public void test_uncheck_content_capture() throws Exception { 50 content_capture_checkbox_test_helper(false); 51 } 52 53 @Test test_check_content_capture()54 public void test_check_content_capture() throws Exception { 55 content_capture_checkbox_test_helper(true); 56 } 57 content_capture_checkbox_test_helper(boolean check)58 private void content_capture_checkbox_test_helper(boolean check) throws Exception { 59 EnableContentCapturePreferenceController enableContentCapturePreferenceController = 60 new EnableContentCapturePreferenceController( 61 ApplicationProvider.getApplicationContext(), 62 "Test_key"); 63 enableContentCapturePreferenceController.setChecked(check); 64 65 //Check through adb command 66 assertThat(AdbUtils.checkStringInAdbCommandOutput(TAG, "dumpsys content_capture", 67 "Users disabled by Settings: ", check ? "{}" : "{0=true}", 1000)).isTrue(); 68 } 69 } 70