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.accessibility; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.ArgumentMatchers.anyBoolean; 23 import static org.mockito.Mockito.never; 24 import static org.mockito.Mockito.spy; 25 import static org.mockito.Mockito.verify; 26 27 import android.content.Context; 28 import android.database.ContentObserver; 29 30 import androidx.test.core.app.ApplicationProvider; 31 32 import com.android.settings.R; 33 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 import org.robolectric.RobolectricTestRunner; 37 38 /** Tests for {@link MagnificationCapabilities} */ 39 @RunWith(RobolectricTestRunner.class) 40 public final class MagnificationCapabilitiesTest { 41 42 private final Context mContext = ApplicationProvider.getApplicationContext(); 43 44 @Test getCapabilities_windowMode_expectedCapabilities()45 public void getCapabilities_windowMode_expectedCapabilities() { 46 MagnificationCapabilities.setCapabilities(mContext, 47 MagnificationCapabilities.MagnificationMode.WINDOW); 48 49 final int windowCapabilities = MagnificationCapabilities.getCapabilities(mContext); 50 assertThat(windowCapabilities).isEqualTo( 51 MagnificationCapabilities.MagnificationMode.WINDOW); 52 } 53 54 @Test getSummary_fullScreenMode_expectedSummary()55 public void getSummary_fullScreenMode_expectedSummary() { 56 final int fullScreenCapabilities = MagnificationCapabilities.MagnificationMode.FULLSCREEN; 57 58 final String actualString = MagnificationCapabilities.getSummary(mContext, 59 fullScreenCapabilities); 60 61 final String expectedString = mContext.getString( 62 R.string.accessibility_magnification_area_settings_full_screen_summary); 63 assertThat(actualString).isEqualTo(expectedString); 64 } 65 66 @Test getCapabilities_unset_defaultValue()67 public void getCapabilities_unset_defaultValue() { 68 final int windowCapabilities = MagnificationCapabilities.getCapabilities(mContext); 69 assertThat(windowCapabilities).isEqualTo( 70 MagnificationCapabilities.MagnificationMode.FULLSCREEN); 71 } 72 73 @Test registerObserver_triggeredWhenCapabilitiesChanged()74 public void registerObserver_triggeredWhenCapabilitiesChanged() { 75 MagnificationCapabilities.setCapabilities(mContext, 76 MagnificationCapabilities.MagnificationMode.FULLSCREEN); 77 78 ContentObserver contentObserver = 79 spy(new ContentObserver(/* handler= */ null) {}); 80 81 MagnificationCapabilities.registerObserver(mContext, contentObserver); 82 MagnificationCapabilities.setCapabilities(mContext, 83 MagnificationCapabilities.MagnificationMode.WINDOW); 84 85 verify(contentObserver).onChange(/* selfChange= */ anyBoolean(), /* uri= */ any()); 86 } 87 88 @Test unregisterObserver_neverTriggeredWhenCapabilitiesChanged()89 public void unregisterObserver_neverTriggeredWhenCapabilitiesChanged() { 90 MagnificationCapabilities.setCapabilities(mContext, 91 MagnificationCapabilities.MagnificationMode.FULLSCREEN); 92 93 ContentObserver contentObserver = 94 spy(new ContentObserver(/* handler= */ null) {}); 95 96 MagnificationCapabilities.registerObserver(mContext, contentObserver); 97 MagnificationCapabilities.unregisterObserver(mContext, contentObserver); 98 MagnificationCapabilities.setCapabilities(mContext, 99 MagnificationCapabilities.MagnificationMode.WINDOW); 100 101 verify(contentObserver, never()).onChange(/* selfChange= */ anyBoolean(), /* uri= */ any()); 102 } 103 } 104