Moving various runnables in LauncherModel to individual tasks

> Adding tests for some of the runnable

Change-Id: I1a315d38878857df3371f0e69d622a41fc3b081a
This commit is contained in:
Sunny Goyal
2016-09-09 15:47:55 -07:00
parent 0d547bfd57
commit f0ba8b7ca1
22 changed files with 1812 additions and 909 deletions

View File

@@ -0,0 +1,81 @@
package com.android.launcher3.model;
import com.android.launcher3.AppInfo;
import com.android.launcher3.IconCache;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.ShortcutInfo;
import java.util.Arrays;
import java.util.HashSet;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link CacheDataUpdatedTask}
*/
public class CacheDataUpdatedTaskTest extends BaseModelUpdateTaskTestCase {
private static final String NEW_LABEL_PREFIX = "new-label-";
@Override
protected void setUp() throws Exception {
super.setUp();
initializeData("cache_data_updated_task_data");
// Add dummy entries in the cache to simulate update
for (ItemInfo info : bgDataModel.itemsIdMap) {
iconCache.addCache(info.getTargetComponent(), NEW_LABEL_PREFIX + info.id);
}
}
private CacheDataUpdatedTask newTask(int op, String... pkg) {
return new CacheDataUpdatedTask(op, myUser, new HashSet<>(Arrays.asList(pkg)));
}
public void testCacheUpdate_update_apps() throws Exception {
executeTaskForTest(newTask(CacheDataUpdatedTask.OP_CACHE_UPDATE, "app1"));
// Verify that only the app icons of app1 (id 1 & 2) are updated. Custom shortcut (id 7)
// is not updated
verifyUpdate(1L, 2L);
// Verify that only app1 var updated in allAppsList
assertFalse(allAppsList.data.isEmpty());
for (AppInfo info : allAppsList.data) {
if (info.componentName.getPackageName().equals("app1")) {
assertNotNull(info.iconBitmap);
} else {
assertNull(info.iconBitmap);
}
}
}
public void testSessionUpdate_ignores_normal_apps() throws Exception {
executeTaskForTest(newTask(CacheDataUpdatedTask.OP_SESSION_UPDATE, "app1"));
// app1 has no restored shortcuts. Verify that nothing was updated.
verifyUpdate();
}
public void testSessionUpdate_updates_pending_apps() throws Exception {
executeTaskForTest(newTask(CacheDataUpdatedTask.OP_SESSION_UPDATE, "app3"));
// app3 has only restored apps (id 5, 6) and shortcuts (id 9). Verify that only apps were
// were updated
verifyUpdate(5L, 6L);
}
private void verifyUpdate(Long... idsUpdated) {
HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated));
IconCache noOpIconCache = mock(IconCache.class);
for (ItemInfo info : bgDataModel.itemsIdMap) {
if (updates.contains(info.id)) {
assertEquals(NEW_LABEL_PREFIX + info.id, info.title);
assertNotNull(((ShortcutInfo) info).getIcon(noOpIconCache));
} else {
assertNotSame(NEW_LABEL_PREFIX + info.id, info.title);
assertNull(((ShortcutInfo) info).getIcon(noOpIconCache));
}
}
}
}