Enable tests which do not require any modification

Fix: 329052420
Flag: NA
Test: Presubmits + :NexusLauncher:testGoogleWithQuickstepDebugUnitTest
Change-Id: I27e847c923076e4e978fd7359c9c62745d4f5f0a
This commit is contained in:
Uwais Ashraf committed 2024-03-13 12:27:46 +00:00
1 parent 54ae7b9dc3
commit 4ee1701fd1
13 files changed

No files matched your search

@@ -0,0 +1,158 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.celllayout;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT;
import static com.google.common.truth.Truth.assertThat;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import com.android.launcher3.celllayout.CellPosMapper.CellPos;
import com.android.launcher3.celllayout.CellPosMapper.TwoPanelCellPosMapper;
import com.android.launcher3.model.data.ItemInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests for {@link CellPosMapper}
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
public class CellPosMapperTest {
@Test
public void testMapModelToPresenter_default() {
CellPosMapper mapper = CellPosMapper.DEFAULT;
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 0, CONTAINER_DESKTOP))).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 1, CONTAINER_DESKTOP))).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 1, CONTAINER_DESKTOP))).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 0, CONTAINER_DESKTOP))).isEqualTo(new CellPos(5, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 0, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 1, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 1, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 0, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(5, 0, 0));
}
@Test
public void testMapPresenterToModel_default() {
CellPosMapper mapper = CellPosMapper.DEFAULT;
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
}
@Test
public void testMapModelToPresenter_twoPanel() {
CellPosMapper mapper = new TwoPanelCellPosMapper(8);
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 0, CONTAINER_DESKTOP))).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 1, CONTAINER_DESKTOP))).isEqualTo(new CellPos(8, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 1, CONTAINER_DESKTOP))).isEqualTo(new CellPos(13, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 0, CONTAINER_DESKTOP))).isEqualTo(new CellPos(5, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 0, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapModelToPresenter(
createInfo(0, 0, 1, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 1, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapModelToPresenter(
createInfo(5, 0, 0, CONTAINER_HOTSEAT))).isEqualTo(new CellPos(5, 0, 0));
}
@Test
public void testMapPresenterToModel_twoPanel() {
CellPosMapper mapper = new TwoPanelCellPosMapper(3);
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(2, 0, 1));
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(5, 0, 5));
}
@Test
public void testMapPresenterToModel_VerticalHotseat() {
CellPosMapper mapper = new CellPosMapper(true, 6);
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(0, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 1, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 1));
assertThat(mapper.mapPresenterToModel(
5, 0, 0, CONTAINER_DESKTOP)).isEqualTo(new CellPos(5, 0, 0));
assertThat(mapper.mapPresenterToModel(
0, 0, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 5));
assertThat(mapper.mapPresenterToModel(
0, 0, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 0, 5));
assertThat(mapper.mapPresenterToModel(
0, 5, 1, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 5, 0));
assertThat(mapper.mapPresenterToModel(
0, 5, 0, CONTAINER_HOTSEAT)).isEqualTo(new CellPos(0, 5, 0));
}
private ItemInfo createInfo(int cellX, int cellY, int screen, int container) {
ItemInfo info = new ItemInfo();
info.cellX = cellX;
info.cellY = cellY;
info.screenId = screen;
info.container = container;
return info;
}
}
@@ -0,0 +1,96 @@
package com.android.launcher3.logging;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Calendar;
/**
* Tests for {@link FileLog}
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
public class FileLogTest {
private File mTempDir;
@Before
public void setUp() {
int count = 0;
do {
mTempDir = new File(getApplicationContext().getCacheDir(),
"log-test-" + (count++));
} while (!mTempDir.mkdir());
FileLog.setDir(mTempDir);
}
@After
public void tearDown() {
// Clear existing logs
for (int i = 0; i < FileLog.LOG_DAYS; i++) {
new File(mTempDir, "log-" + i).delete();
}
mTempDir.delete();
}
@Test
public void testPrintLog() throws Exception {
if (!FileLog.ENABLED) {
return;
}
FileLog.print("Testing", "hoolalala");
StringWriter writer = new StringWriter();
assertTrue(FileLog.flushAll(new PrintWriter(writer)));
assertTrue(writer.toString().contains("hoolalala"));
FileLog.print("Testing", "abracadabra", new Exception("cat! cat!"));
writer = new StringWriter();
assertTrue(FileLog.flushAll(new PrintWriter(writer)));
assertTrue(writer.toString().contains("abracadabra"));
// Exception is also printed
assertTrue(writer.toString().contains("cat! cat!"));
// Old logs still present after flush
assertTrue(writer.toString().contains("hoolalala"));
}
@Test
public void testOldFileTruncated() throws Exception {
if (!FileLog.ENABLED) {
return;
}
FileLog.print("Testing", "hoolalala");
StringWriter writer = new StringWriter();
assertTrue(FileLog.flushAll(new PrintWriter(writer)));
assertTrue(writer.toString().contains("hoolalala"));
Calendar threeDaysAgo = Calendar.getInstance();
threeDaysAgo.add(Calendar.HOUR, -72);
for (int i = 0; i < FileLog.LOG_DAYS; i++) {
new File(mTempDir, "log-" + i).setLastModified(threeDaysAgo.getTimeInMillis());
}
FileLog.print("Testing", "abracadabra", new Exception("cat! cat!"));
writer = new StringWriter();
assertTrue(FileLog.flushAll(new PrintWriter(writer)));
assertTrue(writer.toString().contains("abracadabra"));
// Exception is also printed
assertTrue(writer.toString().contains("cat! cat!"));
// Old logs have been truncated
assertFalse(writer.toString().contains("hoolalala"));
}
}
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.model.data
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.launcher3.pm.PackageInstallInfo
import com.android.launcher3.util.LauncherModelHelper
import com.google.common.truth.Truth
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class ItemInfoWithIconTest {
private var context = LauncherModelHelper.SandboxModelContext()
private lateinit var itemInfoWithIcon: ItemInfoWithIcon
@Before
fun setup() {
itemInfoWithIcon =
object : ItemInfoWithIcon() {
override fun clone(): ItemInfoWithIcon? {
return null
}
}
}
@After
fun tearDown() {
context.destroy()
}
@Test
fun itemInfoWithIconDefaultParamsTest() {
Truth.assertThat(itemInfoWithIcon.isDisabled).isFalse()
Truth.assertThat(itemInfoWithIcon.isPendingDownload).isFalse()
Truth.assertThat(itemInfoWithIcon.isArchived).isFalse()
}
@Test
fun isDisabledOrPendingTest() {
itemInfoWithIcon.setProgressLevel(0, PackageInstallInfo.STATUS_INSTALLING)
Truth.assertThat(itemInfoWithIcon.isDisabled).isFalse()
Truth.assertThat(itemInfoWithIcon.isPendingDownload).isTrue()
itemInfoWithIcon.setProgressLevel(1, PackageInstallInfo.STATUS_INSTALLING)
Truth.assertThat(itemInfoWithIcon.isDisabled).isFalse()
Truth.assertThat(itemInfoWithIcon.isPendingDownload).isFalse()
}
}
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.popup;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS;
import static com.android.launcher3.popup.PopupPopulator.NUM_DYNAMIC;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.pm.ShortcutInfo;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Tests the sorting and filtering of shortcuts in {@link PopupPopulator}.
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
public class PopupPopulatorTest {
@Test
public void testSortAndFilterShortcuts() {
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 0), 3, 0);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(0, 3), 0, 3);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 0), MAX_SHORTCUTS, 0);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(0, 5), 0, MAX_SHORTCUTS);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 3),
MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 5),
MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 1), MAX_SHORTCUTS - 1, 1);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(1, 5), 1, MAX_SHORTCUTS - 1);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(5, 3),
MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 5),
MAX_SHORTCUTS - NUM_DYNAMIC, NUM_DYNAMIC);
}
private String generateId(boolean isStatic, int rank) {
return (isStatic ? "static" : "dynamic") + rank;
}
private void filterShortcutsAndAssertNumStaticAndDynamic(
List<ShortcutInfo> shortcuts, int expectedStatic, int expectedDynamic) {
Collections.shuffle(shortcuts);
List<ShortcutInfo> filteredShortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts);
assertIsSorted(filteredShortcuts);
int numStatic = 0;
int numDynamic = 0;
for (ShortcutInfo shortcut : filteredShortcuts) {
if (shortcut.isDeclaredInManifest()) {
numStatic++;
}
if (shortcut.isDynamic()) {
numDynamic++;
}
}
assertEquals(expectedStatic, numStatic);
assertEquals(expectedDynamic, numDynamic);
}
private void assertIsSorted(List<ShortcutInfo> shortcuts) {
int lastStaticRank = -1;
int lastDynamicRank = -1;
boolean hasSeenDynamic = false;
for (ShortcutInfo shortcut : shortcuts) {
int rank = shortcut.getRank();
if (shortcut.isDeclaredInManifest()) {
assertFalse("Static shortcuts should come before all dynamic shortcuts.",
hasSeenDynamic);
assertTrue(rank > lastStaticRank);
lastStaticRank = rank;
}
if (shortcut.isDynamic()) {
hasSeenDynamic = true;
assertTrue(rank > lastDynamicRank);
lastDynamicRank = rank;
}
}
}
private List<ShortcutInfo> createShortcutsList(int numStatic, int numDynamic) {
List<ShortcutInfo> shortcuts = new ArrayList<>();
for (int i = 0; i < numStatic; i++) {
shortcuts.add(createInfo(true, i));
}
for (int i = 0; i < numDynamic; i++) {
shortcuts.add(createInfo(false, i));
}
return shortcuts;
}
private ShortcutInfo createInfo(boolean isStatic, int rank) {
ShortcutInfo info = spy(new ShortcutInfo.Builder(
getApplicationContext(), generateId(isStatic, rank))
.setRank(rank)
.build());
doReturn(isStatic).when(info).isDeclaredInManifest();
doReturn(!isStatic).when(info).isDynamic();
return info;
}
}
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.util.window
import android.graphics.Rect
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.launcher3.util.window.WindowManagerProxy.areBottomDisplayCutoutsSmallAndAtCorners
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
/** Unit test for [WindowManagerProxy] */
@SmallTest
@RunWith(AndroidJUnit4::class)
class WindowManagerProxyTest {
private val windowWidthPx = 2000
private val bottomLeftCutout = Rect(0, 2364, 136, 2500)
private val bottomRightCutout = Rect(1864, 2364, 2000, 2500)
private val bottomLeftCutoutWithOffset = Rect(10, 2364, 136, 2500)
private val bottomRightCutoutWithOffset = Rect(1864, 2364, 1990, 2500)
private val maxWidthAndHeightOfSmallCutoutPx = 136
@Test
fun cutout_at_bottom_right_corner() {
assertTrue(
areBottomDisplayCutoutsSmallAndAtCorners(
bottomRightCutout,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_at_bottom_left_corner_with_offset() {
assertTrue(
areBottomDisplayCutoutsSmallAndAtCorners(
bottomLeftCutoutWithOffset,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_at_bottom_right_corner_with_offset() {
assertTrue(
areBottomDisplayCutoutsSmallAndAtCorners(
bottomRightCutoutWithOffset,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_at_bottom_left_corner() {
assertTrue(
areBottomDisplayCutoutsSmallAndAtCorners(
bottomLeftCutout,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_at_bottom_edge_at_bottom_corners() {
assertTrue(
areBottomDisplayCutoutsSmallAndAtCorners(
bottomLeftCutout,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_too_big_not_at_bottom_corners() {
// Rect in size of 200px
val bigBottomLeftCutout = Rect(0, 2300, 200, 2500)
assertFalse(
areBottomDisplayCutoutsSmallAndAtCorners(
bigBottomLeftCutout,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_too_small_at_bottom_corners() {
// Rect in size of 100px
val smallBottomLeft = Rect(0, 2400, 100, 2500)
assertTrue(
areBottomDisplayCutoutsSmallAndAtCorners(
smallBottomLeft,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
@Test
fun cutout_empty_not_at_bottom_corners() {
val emptyRect = Rect(0, 0, 0, 0)
assertFalse(
areBottomDisplayCutoutsSmallAndAtCorners(
emptyRect,
windowWidthPx,
maxWidthAndHeightOfSmallCutoutPx
)
)
}
}