• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.model;
2 
3 import android.support.test.runner.AndroidJUnit4;
4 
5 import com.android.launcher3.ItemInfo;
6 import com.android.launcher3.LauncherAppWidgetInfo;
7 import com.android.launcher3.ShortcutInfo;
8 import com.android.launcher3.compat.PackageInstallerCompat;
9 import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
10 
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 
15 import java.util.Arrays;
16 import java.util.HashSet;
17 
18 import static org.junit.Assert.assertEquals;
19 
20 /**
21  * Tests for {@link PackageInstallStateChangedTask}
22  */
23 @RunWith(AndroidJUnit4.class)
24 public class PackageInstallStateChangedTaskTest extends BaseModelUpdateTaskTestCase {
25 
26     @Before
initData()27     public void initData() throws Exception {
28         initializeData("package_install_state_change_task_data");
29     }
30 
newTask(String pkg, int progress)31     private PackageInstallStateChangedTask newTask(String pkg, int progress) {
32         int state = PackageInstallerCompat.STATUS_INSTALLING;
33         PackageInstallInfo installInfo = new PackageInstallInfo(pkg, state, progress);
34         return new PackageInstallStateChangedTask(installInfo);
35     }
36 
37     @Test
testSessionUpdate_ignore_installed()38     public void testSessionUpdate_ignore_installed() throws Exception {
39         executeTaskForTest(newTask("app1", 30));
40 
41         // No shortcuts were updated
42         verifyProgressUpdate(0);
43     }
44 
45     @Test
testSessionUpdate_shortcuts_updated()46     public void testSessionUpdate_shortcuts_updated() throws Exception {
47         executeTaskForTest(newTask("app3", 30));
48 
49         verifyProgressUpdate(30, 5L, 6L, 7L);
50     }
51 
52     @Test
testSessionUpdate_widgets_updated()53     public void testSessionUpdate_widgets_updated() throws Exception {
54         executeTaskForTest(newTask("app4", 30));
55 
56         verifyProgressUpdate(30, 8L, 9L);
57     }
58 
verifyProgressUpdate(int progress, Long... idsUpdated)59     private void verifyProgressUpdate(int progress, Long... idsUpdated) {
60         HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated));
61         for (ItemInfo info : bgDataModel.itemsIdMap) {
62             if (info instanceof ShortcutInfo) {
63                 assertEquals(updates.contains(info.id) ? progress: 0,
64                         ((ShortcutInfo) info).getInstallProgress());
65             } else {
66                 assertEquals(updates.contains(info.id) ? progress: -1,
67                         ((LauncherAppWidgetInfo) info).installProgress);
68             }
69         }
70     }
71 }
72