• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.launcher3.folder;
17 
18 import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
19 
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 
23 import android.content.ComponentName;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.os.UserHandle;
27 
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 import androidx.test.filters.SmallTest;
30 
31 import com.android.launcher3.model.data.AppInfo;
32 import com.android.launcher3.model.data.WorkspaceItemInfo;
33 import com.android.launcher3.util.ActivityContextWrapper;
34 import com.android.launcher3.util.Executors;
35 
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 
40 import java.util.ArrayList;
41 
42 @SmallTest
43 @RunWith(AndroidJUnit4.class)
44 public final class FolderNameProviderTest {
45     private Context mContext;
46     private WorkspaceItemInfo mItem1;
47     private WorkspaceItemInfo mItem2;
48 
49     @Before
setUp()50     public void setUp() {
51         mContext = new ActivityContextWrapper(getApplicationContext());
52         mItem1 = new WorkspaceItemInfo(new AppInfo(
53                 new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
54                 "title1",
55                 UserHandle.of(10),
56                 new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
57         ));
58         mItem2 = new WorkspaceItemInfo(new AppInfo(
59                 new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
60                 "title2",
61                 UserHandle.of(10),
62                 new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
63         ));
64     }
65 
66     @Test
getSuggestedFolderName_workAssignedToEnd()67     public void getSuggestedFolderName_workAssignedToEnd() throws Exception {
68         ArrayList<WorkspaceItemInfo> list = new ArrayList<>();
69         list.add(mItem1);
70         list.add(mItem2);
71         FolderNameInfos nameInfos = new FolderNameInfos();
72         Executors.MODEL_EXECUTOR.submit(() ->
73                 new FolderNameProvider().getSuggestedFolderName(mContext, list, nameInfos)).get();
74         assertEquals("Work", nameInfos.getLabels()[0]);
75 
76         nameInfos.setLabel(0, "candidate1", 1.0f);
77         nameInfos.setLabel(1, "candidate2", 1.0f);
78         nameInfos.setLabel(2, "candidate3", 1.0f);
79         Executors.MODEL_EXECUTOR.submit(() ->
80                 new FolderNameProvider().getSuggestedFolderName(mContext, list, nameInfos)).get();
81         assertEquals("Work", nameInfos.getLabels()[3]);
82         assertTrue(nameInfos.hasSuggestions());
83         assertTrue(nameInfos.hasPrimary());
84     }
85 }
86