1 package com.android.systemui.controls.ui 2 3 import android.content.ComponentName 4 import androidx.test.ext.junit.runners.AndroidJUnit4 5 import androidx.test.filters.SmallTest 6 import com.android.systemui.SysuiTestCase 7 import com.android.systemui.controls.controller.StructureInfo 8 import com.android.systemui.util.mockito.mock 9 import com.google.common.truth.Truth.assertThat 10 import org.junit.Test 11 import org.junit.runner.RunWith 12 13 @SmallTest 14 @RunWith(AndroidJUnit4::class) 15 class SelectionItemTest : SysuiTestCase() { 16 17 @Test testMatchBadComponentName_falsenull18 fun testMatchBadComponentName_false() { 19 val selectionItem = 20 SelectionItem( 21 appName = "app", 22 structure = "structure", 23 icon = mock(), 24 componentName = ComponentName("pkg", "cls"), 25 uid = 0, 26 panelComponentName = null 27 ) 28 29 assertThat( 30 selectionItem.matches( 31 SelectedItem.StructureItem( 32 StructureInfo(ComponentName("", ""), "s", emptyList()) 33 ) 34 ) 35 ) 36 .isFalse() 37 assertThat(selectionItem.matches(SelectedItem.PanelItem("name", ComponentName("", "")))) 38 .isFalse() 39 } 40 41 @Test testMatchSameComponentName_panelSelected_truenull42 fun testMatchSameComponentName_panelSelected_true() { 43 val componentName = ComponentName("pkg", "cls") 44 45 val selectionItem = 46 SelectionItem( 47 appName = "app", 48 structure = "structure", 49 icon = mock(), 50 componentName = componentName, 51 uid = 0, 52 panelComponentName = null 53 ) 54 assertThat(selectionItem.matches(SelectedItem.PanelItem("name", componentName))).isTrue() 55 } 56 57 @Test testMatchSameComponentName_panelSelection_truenull58 fun testMatchSameComponentName_panelSelection_true() { 59 val componentName = ComponentName("pkg", "cls") 60 61 val selectionItem = 62 SelectionItem( 63 appName = "app", 64 structure = "structure", 65 icon = mock(), 66 componentName = componentName, 67 uid = 0, 68 panelComponentName = ComponentName("pkg", "panel") 69 ) 70 assertThat(selectionItem.matches(SelectedItem.PanelItem("name", componentName))).isTrue() 71 } 72 73 @Test testMatchSameComponentSameStructure_truenull74 fun testMatchSameComponentSameStructure_true() { 75 val componentName = ComponentName("pkg", "cls") 76 val structureName = "structure" 77 78 val structureItem = 79 SelectedItem.StructureItem(StructureInfo(componentName, structureName, emptyList())) 80 81 val selectionItem = 82 SelectionItem( 83 appName = "app", 84 structure = structureName, 85 icon = mock(), 86 componentName = componentName, 87 uid = 0, 88 panelComponentName = null 89 ) 90 assertThat(selectionItem.matches(structureItem)).isTrue() 91 } 92 93 @Test testMatchSameComponentDifferentStructure_falsenull94 fun testMatchSameComponentDifferentStructure_false() { 95 val componentName = ComponentName("pkg", "cls") 96 val structureName = "structure" 97 98 val structureItem = 99 SelectedItem.StructureItem(StructureInfo(componentName, structureName, emptyList())) 100 101 val selectionItem = 102 SelectionItem( 103 appName = "app", 104 structure = "other", 105 icon = mock(), 106 componentName = componentName, 107 uid = 0, 108 panelComponentName = null 109 ) 110 assertThat(selectionItem.matches(structureItem)).isFalse() 111 } 112 } 113