1 package com.android.settings.location; 2 3 import static com.google.common.truth.Truth.assertThat; 4 5 import android.content.Context; 6 7 import androidx.core.graphics.drawable.IconCompat; 8 import androidx.slice.Slice; 9 import androidx.slice.SliceMetadata; 10 import androidx.slice.SliceProvider; 11 import androidx.slice.core.SliceAction; 12 import androidx.slice.widget.SliceLiveData; 13 14 import com.android.settings.R; 15 16 import org.junit.Before; 17 import org.junit.Test; 18 import org.junit.runner.RunWith; 19 import org.robolectric.RobolectricTestRunner; 20 import org.robolectric.RuntimeEnvironment; 21 22 import java.util.List; 23 24 @RunWith(RobolectricTestRunner.class) 25 public class LocationSliceTest { 26 27 private Context mContext; 28 29 @Before setUp()30 public void setUp() { 31 mContext = RuntimeEnvironment.application; 32 33 // Set-up specs for SliceMetadata. 34 SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); 35 } 36 37 @Test getLocationSlice_correctSliceContent()38 public void getLocationSlice_correctSliceContent() { 39 final Slice LocationSlice = new LocationSlice(mContext).getSlice(); 40 41 final SliceMetadata metadata = SliceMetadata.from(mContext, LocationSlice); 42 assertThat(metadata.getTitle()).isEqualTo( 43 mContext.getString(R.string.location_settings_title)); 44 45 final List<SliceAction> toggles = metadata.getToggles(); 46 assertThat(toggles).isEmpty(); 47 48 final SliceAction primaryAction = metadata.getPrimaryAction(); 49 final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, 50 com.android.internal.R.drawable.ic_signal_location); 51 assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString()); 52 } 53 } 54