Remove search v1
Fixes: 69851037 Test: robotests Change-Id: I53bc6408116031619053066055cb26cac67b9945
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.UserManager;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AccessibilityServiceResultFutureTaskTest {
|
||||
|
||||
private static final String QUERY = "test_query";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private AccessibilityManager mAccessibilityManager;
|
||||
@Mock
|
||||
private SiteMapManager mSiteMapManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
private AccessibilityServiceResultLoader.AccessibilityServiceResultCallable mCallable;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.ACCESSIBILITY_SERVICE))
|
||||
.thenReturn(mAccessibilityManager);
|
||||
when((Object)mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
|
||||
mCallable = new AccessibilityServiceResultLoader.AccessibilityServiceResultCallable(
|
||||
mContext, QUERY, mSiteMapManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_noService_shouldNotReturnAnything() throws Exception {
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_hasServiceMatchingTitle_shouldReturnResult() throws Exception {
|
||||
addFakeAccessibilityService();
|
||||
|
||||
List<? extends SearchResult> results = mCallable.call();
|
||||
assertThat(results).hasSize(1);
|
||||
|
||||
SearchResult result = results.get(0);
|
||||
assertThat(result.title).isEqualTo(QUERY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_serviceDoesNotMatchTitle_shouldReturnResult() throws Exception {
|
||||
addFakeAccessibilityService();
|
||||
|
||||
mCallable = new AccessibilityServiceResultLoader.AccessibilityServiceResultCallable(
|
||||
mContext,
|
||||
QUERY + "no_match", mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
private void addFakeAccessibilityService() {
|
||||
final List<AccessibilityServiceInfo> services = new ArrayList<>();
|
||||
final AccessibilityServiceInfo info = mock(AccessibilityServiceInfo.class);
|
||||
final ResolveInfo resolveInfo = mock(ResolveInfo.class);
|
||||
when(info.getResolveInfo()).thenReturn(resolveInfo);
|
||||
when(resolveInfo.loadIcon(mPackageManager)).thenReturn(new ColorDrawable(Color.BLUE));
|
||||
when(resolveInfo.loadLabel(mPackageManager)).thenReturn(QUERY);
|
||||
resolveInfo.serviceInfo = new ServiceInfo();
|
||||
resolveInfo.serviceInfo.packageName = "pkg";
|
||||
resolveInfo.serviceInfo.name = "class";
|
||||
services.add(info);
|
||||
|
||||
when(mAccessibilityManager.getInstalledAccessibilityServiceList()).thenReturn(services);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InlineSwitchViewHolderTest {
|
||||
|
||||
private static final String TITLE = "title";
|
||||
private static final String SUMMARY = "summary";
|
||||
|
||||
@Mock
|
||||
private SearchFragment mFragment;
|
||||
|
||||
@Mock
|
||||
private InlineSwitchPayload mPayload;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private InlineSwitchViewHolder mHolder;
|
||||
private Drawable mIcon;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
mIcon = context.getDrawable(R.drawable.ic_search_24dp);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mHolder = new InlineSwitchViewHolder(
|
||||
LayoutInflater.from(context).inflate(R.layout.search_inline_switch_item, null),
|
||||
context);
|
||||
ReflectionHelpers.setField(mHolder, "mMetricsFeatureProvider",
|
||||
mFeatureFactory.metricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_MembersNotNull() {
|
||||
assertThat(mHolder.titleView).isNotNull();
|
||||
assertThat(mHolder.summaryView).isNotNull();
|
||||
assertThat(mHolder.iconView).isNotNull();
|
||||
assertThat(mHolder.switchView).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_AllUpdated() {
|
||||
when(mPayload.getValue(any(Context.class))).thenReturn(1);
|
||||
SearchResult result = getSearchResult();
|
||||
mHolder.onBind(mFragment, result);
|
||||
// Precondition: switch is on.
|
||||
assertThat(mHolder.switchView.isChecked()).isTrue();
|
||||
|
||||
mHolder.switchView.performClick();
|
||||
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.iconView.getDrawable()).isEqualTo(mIcon);
|
||||
assertThat(mHolder.switchView.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
private SearchResult getSearchResult() {
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
|
||||
builder.setTitle(TITLE)
|
||||
.setSummary(SUMMARY)
|
||||
.setRank(1)
|
||||
.setPayload(new InlineSwitchPayload("" /* uri */, 0 /* mSettingSource */,
|
||||
1 /* onValue */, null /* intent */, true /* isDeviceSupported */,
|
||||
1 /* default */))
|
||||
.addBreadcrumbs(new ArrayList<>())
|
||||
.setIcon(mIcon)
|
||||
.setPayload(mPayload)
|
||||
.setStableId(TITLE.hashCode());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static android.content.Context.INPUT_METHOD_SERVICE;
|
||||
|
||||
import static com.android.settings.search.InputDeviceResultLoader.PHYSICAL_KEYBOARD_FRAGMENT;
|
||||
import static com.android.settings.search.InputDeviceResultLoader.VIRTUAL_KEYBOARD_FRAGMENT;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.view.InputDevice;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowInputDevice;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
ShadowInputDevice.class
|
||||
})
|
||||
public class InputDeviceResultFutureTaskTest {
|
||||
|
||||
private static final String QUERY = "test_query";
|
||||
private static final List<String> PHYSICAL_KEYBOARD_BREADCRUMB;
|
||||
private static final List<String> VIRTUAL_KEYBOARD_BREADCRUMB;
|
||||
|
||||
static {
|
||||
PHYSICAL_KEYBOARD_BREADCRUMB = new ArrayList<>();
|
||||
VIRTUAL_KEYBOARD_BREADCRUMB = new ArrayList<>();
|
||||
PHYSICAL_KEYBOARD_BREADCRUMB.add("Settings");
|
||||
PHYSICAL_KEYBOARD_BREADCRUMB.add("physical keyboard");
|
||||
VIRTUAL_KEYBOARD_BREADCRUMB.add("Settings");
|
||||
VIRTUAL_KEYBOARD_BREADCRUMB.add("virtual keyboard");
|
||||
}
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SiteMapManager mSiteMapManager;
|
||||
@Mock
|
||||
private InputManager mInputManager;
|
||||
@Mock
|
||||
private InputMethodManager mImm;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private InputDeviceResultLoader.InputDeviceResultCallable mCallable;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(Context.INPUT_SERVICE))
|
||||
.thenReturn(mInputManager);
|
||||
when(mContext.getSystemService(INPUT_METHOD_SERVICE))
|
||||
.thenReturn(mImm);
|
||||
when(mContext.getPackageManager())
|
||||
.thenReturn(mPackageManager);
|
||||
when(mContext.getString(anyInt()))
|
||||
.thenAnswer(invocation -> RuntimeEnvironment.application.getString(
|
||||
(Integer) invocation.getArguments()[0]));
|
||||
mCallable = new InputDeviceResultLoader.InputDeviceResultCallable(mContext, QUERY,
|
||||
mSiteMapManager);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowInputDevice.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_noKeyboard_shouldNotReturnAnything() throws Exception {
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_hasPhysicalKeyboard_match() throws Exception {
|
||||
addPhysicalKeyboard(QUERY);
|
||||
when(mSiteMapManager.buildBreadCrumb(mContext, PHYSICAL_KEYBOARD_FRAGMENT,
|
||||
RuntimeEnvironment.application.getString(R.string.physical_keyboard_title)))
|
||||
.thenReturn(PHYSICAL_KEYBOARD_BREADCRUMB);
|
||||
|
||||
final List<? extends SearchResult> results = mCallable.call();
|
||||
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(results.get(0).title).isEqualTo(QUERY);
|
||||
assertThat(results.get(0).breadcrumbs)
|
||||
.containsExactlyElementsIn(PHYSICAL_KEYBOARD_BREADCRUMB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_hasVirtualKeyboard_match() throws Exception {
|
||||
addVirtualKeyboard(QUERY);
|
||||
when(mSiteMapManager.buildBreadCrumb(mContext, VIRTUAL_KEYBOARD_FRAGMENT,
|
||||
RuntimeEnvironment.application.getString(R.string.add_virtual_keyboard)))
|
||||
.thenReturn(VIRTUAL_KEYBOARD_BREADCRUMB);
|
||||
|
||||
final List<? extends SearchResult> results = mCallable.call();
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(results.get(0).title).isEqualTo(QUERY);
|
||||
assertThat(results.get(0).breadcrumbs)
|
||||
.containsExactlyElementsIn(VIRTUAL_KEYBOARD_BREADCRUMB);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_hasPhysicalVirtualKeyboard_doNotMatch() throws Exception {
|
||||
addPhysicalKeyboard("abc");
|
||||
addVirtualKeyboard("def");
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
verifyZeroInteractions(mSiteMapManager);
|
||||
}
|
||||
|
||||
private void addPhysicalKeyboard(String name) {
|
||||
final InputDevice device = mock(InputDevice.class);
|
||||
when(device.isVirtual()).thenReturn(false);
|
||||
when(device.isFullKeyboard()).thenReturn(true);
|
||||
when(device.getName()).thenReturn(name);
|
||||
ShadowInputDevice.sDeviceIds = new int[]{0};
|
||||
ShadowInputDevice.addDevice(0, device);
|
||||
}
|
||||
|
||||
private void addVirtualKeyboard(String name) {
|
||||
final List<InputMethodInfo> imis = new ArrayList<>();
|
||||
final InputMethodInfo info = mock(InputMethodInfo.class);
|
||||
imis.add(info);
|
||||
when(info.getServiceInfo()).thenReturn(new ServiceInfo());
|
||||
when(info.loadLabel(mPackageManager)).thenReturn(name);
|
||||
info.getServiceInfo().packageName = "pkg";
|
||||
info.getServiceInfo().name = "class";
|
||||
when(mImm.getInputMethodList()).thenReturn(imis);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,441 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
|
||||
import static android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyList;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.testutils.ApplicationTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class InstalledAppResultLoaderTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PackageManagerWrapper mPackageManagerWrapper;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private SiteMapManager mSiteMapManager;
|
||||
|
||||
private InstalledAppResultLoader.InstalledAppResultCallable mCallable;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
|
||||
when(factory.searchFeatureProvider.getSiteMapManager())
|
||||
.thenReturn(mSiteMapManager);
|
||||
final List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(1, "user 1", 0));
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
when(mContext.getString(R.string.applications_settings))
|
||||
.thenReturn("app");
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */),
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app2", FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */),
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app3", FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */),
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app4", 0 /* flags */,
|
||||
0 /* targetSdkVersion */),
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app", 0 /* flags */,
|
||||
0 /* targetSdkVersion */),
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "appBuffer", 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_noMatchingQuery_shouldReturnEmptyResult() throws Exception {
|
||||
final String query = "abc";
|
||||
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_matchingQuery_shouldReturnNonSystemApps() throws Exception {
|
||||
final String query = "app";
|
||||
|
||||
mCallable = spy(new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager));
|
||||
when(mSiteMapManager.buildBreadCrumb(eq(mContext), anyString(), anyString()))
|
||||
.thenReturn(Arrays.asList(new String[] {"123"}));
|
||||
|
||||
assertThat(mCallable.call()).hasSize(3);
|
||||
verify(mSiteMapManager)
|
||||
.buildBreadCrumb(eq(mContext), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_matchingQuery_shouldReturnSystemAppUpdates() throws Exception {
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_UPDATED_SYSTEM_APP,
|
||||
0 /* targetSdkVersion */)));
|
||||
final String query = "app";
|
||||
|
||||
mCallable = spy(new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager));
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
verify(mSiteMapManager)
|
||||
.buildBreadCrumb(eq(mContext), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_matchingQuery_shouldReturnSystemAppIfLaunchable() throws Exception {
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */)));
|
||||
final List<ResolveInfo> list = mock(List.class);
|
||||
when(list.size()).thenReturn(1);
|
||||
when(mPackageManagerWrapper.queryIntentActivitiesAsUser(
|
||||
any(Intent.class), anyInt(), anyInt()))
|
||||
.thenReturn(list);
|
||||
|
||||
final String query = "app";
|
||||
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_matchingQuery_shouldReturnSystemAppIfHomeApp() throws Exception {
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */)));
|
||||
when(mPackageManagerWrapper.queryIntentActivitiesAsUser(
|
||||
any(Intent.class), anyInt(), anyInt()))
|
||||
.thenReturn(null);
|
||||
|
||||
when(mPackageManagerWrapper.getHomeActivities(anyList())).thenAnswer(invocation -> {
|
||||
final List<ResolveInfo> list = (List<ResolveInfo>) invocation.getArguments()[0];
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.activityInfo = new ActivityInfo();
|
||||
info.activityInfo.packageName = "app1";
|
||||
list.add(info);
|
||||
return null;
|
||||
});
|
||||
|
||||
final String query = "app";
|
||||
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_matchingQuery_shouldNotReturnSystemAppIfNotLaunchable() throws Exception {
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, "app1", FLAG_SYSTEM,
|
||||
0 /* targetSdkVersion */)));
|
||||
when(mPackageManagerWrapper.queryIntentActivitiesAsUser(
|
||||
any(Intent.class), anyInt(), anyInt()))
|
||||
.thenReturn(null);
|
||||
|
||||
final String query = "app";
|
||||
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
verify(mSiteMapManager, never())
|
||||
.buildBreadCrumb(eq(mContext), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_matchingQuery_multipleResults() throws Exception {
|
||||
final String query = "app";
|
||||
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
final List<? extends SearchResult> results = mCallable.call();
|
||||
|
||||
Set<CharSequence> expectedTitles = new HashSet<>(Arrays.asList("app4", "app", "appBuffer"));
|
||||
Set<CharSequence> actualTitles = new HashSet<>();
|
||||
for (SearchResult result : results) {
|
||||
actualTitles.add(result.title);
|
||||
}
|
||||
assertThat(actualTitles).isEqualTo(expectedTitles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_normalWord_MatchPrefix() throws Exception {
|
||||
final String query = "ba";
|
||||
final String packageName = "Bananas";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_CapitalCase_DoestMatchSecondWord() throws Exception {
|
||||
final String query = "Apples";
|
||||
final String packageName = "BananasApples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_TwoWords_MatchesFirstWord() throws Exception {
|
||||
final String query = "Banana";
|
||||
final String packageName = "Bananas Apples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_TwoWords_MatchesSecondWord() throws Exception {
|
||||
final String query = "Apple";
|
||||
final String packageName = "Bananas Apples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_ThreeWords_MatchesThirdWord() throws Exception {
|
||||
final String query = "Pear";
|
||||
final String packageName = "Bananas Apples Pears";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_DoubleSpacedWords_MatchesSecondWord() throws Exception {
|
||||
final String query = "Apple";
|
||||
final String packageName = "Bananas Apples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_SpecialChar_MatchesSecondWord() throws Exception {
|
||||
final String query = "Apple";
|
||||
final String packageName = "Bananas & Apples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_TabSeparated_MatchesSecondWord() throws Exception {
|
||||
final String query = "Apple";
|
||||
final String packageName = "Bananas\tApples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_LeadingNumber_MatchesWord() throws Exception {
|
||||
final String query = "4";
|
||||
final String packageName = "4Bananas";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_FirstWordPrefixOfQuery_NoMatch() throws Exception {
|
||||
final String query = "Bananass";
|
||||
final String packageName = "Bananas Apples";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_QueryLongerThanAppName_NoMatch() throws Exception {
|
||||
final String query = "BananasApples";
|
||||
final String packageName = "Bananas";
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), anyInt()))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(0 /* uid */, packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(mCallable.call()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void query_appExistsInBothProfiles() throws Exception {
|
||||
final String query = "carrot";
|
||||
final String packageName = "carrot";
|
||||
final int user1 = 0;
|
||||
final int user2 = 10;
|
||||
final int uid = 67672;
|
||||
List<UserInfo> infos = new ArrayList<>();
|
||||
infos.add(new UserInfo(user1, "user 1", 0));
|
||||
infos.add(new UserInfo(user2, "user 2", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
|
||||
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), eq(user1)))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(UserHandle.getUid(user1, uid) /* uid */,
|
||||
packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
when(mPackageManagerWrapper.getInstalledApplicationsAsUser(anyInt(), eq(user2)))
|
||||
.thenReturn(Arrays.asList(
|
||||
ApplicationTestUtils.buildInfo(UserHandle.getUid(user2, uid) /* uid */,
|
||||
packageName, 0 /* flags */,
|
||||
0 /* targetSdkVersion */)));
|
||||
|
||||
mCallable = new InstalledAppResultLoader.InstalledAppResultCallable(mContext,
|
||||
mPackageManagerWrapper, query,
|
||||
mSiteMapManager);
|
||||
|
||||
List<AppSearchResult> searchResults = (List<AppSearchResult>) mCallable.call();
|
||||
assertThat(searchResults).hasSize(2);
|
||||
|
||||
Set<Integer> uidResults = searchResults.stream().map(result -> result.info.uid).collect(
|
||||
Collectors.toSet());
|
||||
assertThat(uidResults).containsExactly(
|
||||
UserHandle.getUid(user1, uid),
|
||||
UserHandle.getUid(user2, uid));
|
||||
}
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.SearchResult.Builder;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class IntentSearchViewHolderTest {
|
||||
|
||||
private static final String TITLE = "title";
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final int USER_ID = 10;
|
||||
private static final String BADGED_LABEL = "work title";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private SearchFragment mFragment;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private IntentSearchViewHolder mHolder;
|
||||
private Drawable mIcon;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.search_intent_item, null);
|
||||
mHolder = new IntentSearchViewHolder(view);
|
||||
|
||||
mIcon = context.getDrawable(R.drawable.ic_search_24dp);
|
||||
when(mFragment.getActivity().getPackageManager()).thenReturn(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_membersNotNull() {
|
||||
assertThat(mHolder.titleView).isNotNull();
|
||||
assertThat(mHolder.summaryView).isNotNull();
|
||||
assertThat(mHolder.iconView).isNotNull();
|
||||
assertThat(mHolder.breadcrumbView).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_allUpdated() {
|
||||
final SearchResult result = getSearchResult(TITLE, SUMMARY, mIcon);
|
||||
mHolder.onBind(mFragment, result);
|
||||
mHolder.itemView.performClick();
|
||||
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.iconView.getDrawable()).isEqualTo(mIcon);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mHolder.breadcrumbView.getVisibility()).isEqualTo(View.GONE);
|
||||
|
||||
verify(mFragment).onSearchResultClicked(eq(mHolder), any(SearchResult.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewIcon_nullIcon_imageDrawableIsNull() {
|
||||
final SearchResult result = getSearchResult(TITLE, SUMMARY, null);
|
||||
mHolder.onBind(mFragment, result);
|
||||
|
||||
assertThat(mHolder.iconView.getDrawable()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_emptySummary_hideSummaryView() {
|
||||
final SearchResult result = new Builder()
|
||||
.setTitle(TITLE)
|
||||
.setRank(1)
|
||||
.setPayload(new ResultPayload(null))
|
||||
.setIcon(mIcon)
|
||||
.setStableId(1)
|
||||
.build();
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_withBreadcrumb_shouldFormatBreadcrumb() {
|
||||
final List<String> breadcrumbs = new ArrayList<>();
|
||||
breadcrumbs.add("a");
|
||||
breadcrumbs.add("b");
|
||||
breadcrumbs.add("c");
|
||||
final SearchResult result = new Builder()
|
||||
.setTitle(TITLE)
|
||||
.setRank(1)
|
||||
.setPayload(new ResultPayload(null))
|
||||
.addBreadcrumbs(breadcrumbs)
|
||||
.setIcon(mIcon)
|
||||
.setStableId(1)
|
||||
.build();
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
assertThat(mHolder.breadcrumbView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mHolder.breadcrumbView.getText()).isEqualTo("a > b > c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindElements_placeholderSummary_visibilityIsGone() {
|
||||
final String nonBreakingSpace = mContext.getString(R.string.summary_placeholder);
|
||||
final SearchResult result = new Builder()
|
||||
.setTitle(TITLE)
|
||||
.setSummary(nonBreakingSpace)
|
||||
.setPayload(new ResultPayload(null))
|
||||
.setStableId(1)
|
||||
.build();
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindElements_dynamicSummary_visibilityIsGone() {
|
||||
final String dynamicSummary = "%s";
|
||||
final SearchResult result = new Builder()
|
||||
.setTitle(TITLE)
|
||||
.setSummary(dynamicSummary)
|
||||
.setPayload(new ResultPayload(null))
|
||||
.setStableId(1)
|
||||
.build();
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_appSearchResult() {
|
||||
mHolder = spy(mHolder);
|
||||
doReturn(new ColorDrawable(0)).when(mHolder).getBadgedIcon(any(ApplicationInfo.class),
|
||||
anyInt());
|
||||
when(mPackageManager.getUserBadgedLabel(any(CharSequence.class),
|
||||
eq(new UserHandle(USER_ID)))).thenReturn(BADGED_LABEL);
|
||||
|
||||
final SearchResult result = getAppSearchResult(
|
||||
TITLE, SUMMARY, mIcon, getApplicationInfo(USER_ID, TITLE, mIcon));
|
||||
mHolder.onBind(mFragment, result);
|
||||
mHolder.itemView.performClick();
|
||||
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mHolder.breadcrumbView.getVisibility()).isEqualTo(View.GONE);
|
||||
assertThat(mHolder.titleView.getContentDescription()).isEqualTo(BADGED_LABEL);
|
||||
|
||||
verify(mFragment).onSearchResultClicked(eq(mHolder), any(SearchResult.class));
|
||||
verify(mFragment.getActivity()).startActivityAsUser(
|
||||
any(Intent.class), eq(new UserHandle(USER_ID)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_validSubSettingIntent_shouldLaunch() {
|
||||
final SearchResult result = getSearchResult(TITLE, SUMMARY, mIcon);
|
||||
when(mPackageManager.queryIntentActivities(result.payload.getIntent(), 0 /* flags */))
|
||||
.thenReturn(Arrays.asList(new ResolveInfo()));
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
mHolder.itemView.performClick();
|
||||
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
verify(mFragment).onSearchResultClicked(eq(mHolder), any(SearchResult.class));
|
||||
verify(mFragment).startActivityForResult(result.payload.getIntent(),
|
||||
IntentSearchViewHolder.REQUEST_CODE_NO_OP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_invalidSubSettingIntent_shouldNotLaunchAnything() {
|
||||
final SearchResult result = getSearchResult(TITLE, SUMMARY, mIcon);
|
||||
when(mPackageManager.queryIntentActivities(result.payload.getIntent(), 0 /* flags */))
|
||||
.thenReturn(null);
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
mHolder.itemView.performClick();
|
||||
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
verify(mFragment).onSearchResultClicked(eq(mHolder), any(SearchResult.class));
|
||||
verify(mFragment, never()).startActivityForResult(result.payload.getIntent(),
|
||||
IntentSearchViewHolder.REQUEST_CODE_NO_OP);
|
||||
}
|
||||
|
||||
private SearchResult getSearchResult(String title, String summary, Drawable icon) {
|
||||
Builder builder = new Builder();
|
||||
builder.setStableId(Objects.hash(title, summary, icon))
|
||||
.setTitle(title)
|
||||
.setSummary(summary)
|
||||
.setRank(1)
|
||||
.setPayload(new ResultPayload(
|
||||
new Intent().setComponent(new ComponentName("pkg", "class"))))
|
||||
.addBreadcrumbs(new ArrayList<>())
|
||||
.setStableId(1)
|
||||
.setIcon(icon);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private SearchResult getAppSearchResult(
|
||||
String title, String summary, Drawable icon, ApplicationInfo applicationInfo) {
|
||||
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
||||
builder.setTitle(title)
|
||||
.setSummary(summary)
|
||||
.setRank(1)
|
||||
.setPayload(new ResultPayload(
|
||||
new Intent().setComponent(new ComponentName("pkg", "class"))))
|
||||
.addBreadcrumbs(new ArrayList<>())
|
||||
.setIcon(icon);
|
||||
builder.setAppInfo(applicationInfo);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private ApplicationInfo getApplicationInfo(int userId, CharSequence appLabel, Drawable icon) {
|
||||
ApplicationInfo applicationInfo = spy(new ApplicationInfo());
|
||||
applicationInfo.uid = UserHandle.getUid(userId, 12345);
|
||||
doReturn(icon).when(applicationInfo).loadIcon(any(PackageManager.class));
|
||||
doReturn(appLabel).when(applicationInfo).loadLabel(any(PackageManager.class));
|
||||
return applicationInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.search.SearchResult;
|
||||
import com.android.settings.search.SearchResultLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mock loader to subvert the requirements of returning data while also driving the Loader
|
||||
* lifecycle.
|
||||
*/
|
||||
public class MockSearchResultLoader extends SearchResultLoader {
|
||||
|
||||
public MockSearchResultLoader(Context context) {
|
||||
super(context, "test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SearchResult> loadInBackground() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDiscardResult(List<? extends SearchResult> result) {
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SavedQueryLoaderTest {
|
||||
|
||||
private Context mContext;
|
||||
private SQLiteDatabase mDb;
|
||||
private SavedQueryLoader mLoader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
mLoader = new SavedQueryLoader(mContext);
|
||||
setUpDb();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
DatabaseTestUtils.clearDb(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadInBackground_shouldReturnSavedQueries() {
|
||||
final List<? extends SearchResult> results = mLoader.loadInBackground();
|
||||
assertThat(results.size()).isEqualTo(SavedQueryLoader.MAX_PROPOSED_SUGGESTIONS);
|
||||
for (SearchResult result : results) {
|
||||
assertThat(result.viewType).isEqualTo(ResultPayload.PayloadType.SAVED_QUERY);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpDb() {
|
||||
final long now = System.currentTimeMillis();
|
||||
for (int i = 0; i < SavedQueryLoader.MAX_PROPOSED_SUGGESTIONS + 2; i++) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.SavedQueriesColumns.QUERY, String.valueOf(i));
|
||||
values.put(IndexDatabaseHelper.SavedQueriesColumns.TIME_STAMP, now);
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES, null, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SavedQueryPayloadTest {
|
||||
|
||||
private SavedQueryPayload mPayload;
|
||||
|
||||
@Test
|
||||
public void getType_shouldBeSavedQueryType() {
|
||||
mPayload = new SavedQueryPayload("Test");
|
||||
assertThat(mPayload.getType()).isEqualTo(ResultPayload.PayloadType.SAVED_QUERY);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SavedQueryRecorderAndRemoverTest {
|
||||
|
||||
private Context mContext;
|
||||
private SavedQueryRecorder mRecorder;
|
||||
private SavedQueryRemover mRemover;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
DatabaseTestUtils.clearDb(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSaveAndRemoveQuery() {
|
||||
final String query = "test";
|
||||
mRecorder = new SavedQueryRecorder(mContext, query);
|
||||
mRemover = new SavedQueryRemover(mContext);
|
||||
|
||||
// Record a new query and load all queries from DB
|
||||
mRecorder.loadInBackground();
|
||||
final SavedQueryLoader loader = new SavedQueryLoader(mContext);
|
||||
List<? extends SearchResult> results = loader.loadInBackground();
|
||||
|
||||
// Should contain the newly recorded query
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(results.get(0).title).isEqualTo(query);
|
||||
|
||||
// Remove the query and load all queries from DB
|
||||
mRemover.loadInBackground();
|
||||
results = loader.loadInBackground();
|
||||
|
||||
// Saved query list should be empty because it's removed.
|
||||
assertThat(results).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canRemoveAllQueriesAtOnce() {
|
||||
mRemover = new SavedQueryRemover(mContext);;
|
||||
|
||||
// Record a new query and load all queries from DB
|
||||
new SavedQueryRecorder(mContext, "Test1").loadInBackground();
|
||||
new SavedQueryRecorder(mContext, "Test2").loadInBackground();
|
||||
final SavedQueryLoader loader = new SavedQueryLoader(mContext);
|
||||
List<? extends SearchResult> results = loader.loadInBackground();
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
|
||||
mRemover.loadInBackground();
|
||||
results = loader.loadInBackground();
|
||||
|
||||
// Saved query list should be empty because it's removed.
|
||||
assertThat(results).isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SavedQueryViewHolderTest {
|
||||
|
||||
@Mock
|
||||
private SearchFragment mSearchFragment;
|
||||
private Context mContext;
|
||||
private SavedQueryViewHolder mHolder;
|
||||
private View mView;
|
||||
private View mTitleView;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mView = LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.search_saved_query_item, null);
|
||||
mTitleView = mView.findViewById(android.R.id.title);
|
||||
mHolder = new SavedQueryViewHolder(mView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBind_shouldBindClickCallback() {
|
||||
final SearchResult result = mock(SearchResult.class);
|
||||
mHolder.onBind(mSearchFragment, result);
|
||||
|
||||
mHolder.itemView.performClick();
|
||||
|
||||
verify(mSearchFragment).onSavedQueryClicked(nullable(CharSequence.class));
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,15 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
@@ -73,31 +69,10 @@ public class SearchFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDatabaseSearchLoader_shouldCleanupQuery() {
|
||||
final String query = " space ";
|
||||
|
||||
mProvider.getStaticSearchResultTask(mActivity, query);
|
||||
|
||||
verify(mProvider).cleanQuery(eq(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInstalledAppSearchLoader_shouldCleanupQuery() {
|
||||
final String query = " space ";
|
||||
|
||||
mProvider.getInstalledAppSearchTask(mActivity, query);
|
||||
|
||||
verify(mProvider).cleanQuery(eq(query));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initSearchToolbar_searchV2_shouldInitWithOnClickListener() {
|
||||
public void initSearchToolbar_shouldInitWithOnClickListener() {
|
||||
mProvider.initSearchToolbar(mActivity, null);
|
||||
// Should not crash.
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.SEARCH_V2,
|
||||
"true");
|
||||
final Toolbar toolbar = new Toolbar(mActivity);
|
||||
mProvider.initSearchToolbar(mActivity, toolbar);
|
||||
|
||||
@@ -109,25 +84,6 @@ public class SearchFeatureProviderImplTest {
|
||||
.isEqualTo("com.android.settings.action.SETTINGS_SEARCH");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initSearchToolbar_searchV1_shouldInitWithOnClickListener() {
|
||||
mProvider.initSearchToolbar(mActivity, null);
|
||||
// Should not crash.
|
||||
|
||||
SettingsShadowSystemProperties.set(
|
||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.SEARCH_V2,
|
||||
"false");
|
||||
final Toolbar toolbar = new Toolbar(mActivity);
|
||||
mProvider.initSearchToolbar(mActivity, toolbar);
|
||||
|
||||
toolbar.performClick();
|
||||
|
||||
final Intent launchIntent = shadowOf(mActivity).getNextStartedActivity();
|
||||
|
||||
assertThat(launchIntent.getComponent().getClassName())
|
||||
.isEqualTo(SearchActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void verifyLaunchSearchResultPageCaller_nullCaller_shouldCrash() {
|
||||
mProvider.verifyLaunchSearchResultPageCaller(mActivity, null /* caller */);
|
||||
|
||||
@@ -1,413 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.LoaderManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
})
|
||||
public class SearchFragmentTest {
|
||||
@Mock
|
||||
private SearchResultLoader mSearchResultLoader;
|
||||
@Mock
|
||||
private SavedQueryLoader mSavedQueryLoader;
|
||||
@Mock
|
||||
private SavedQueryController mSavedQueryController;
|
||||
@Mock
|
||||
private SearchResultsAdapter mSearchResultsAdapter;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
DatabaseTestUtils.clearDb(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void screenRotate_shouldPersistQuery() {
|
||||
when(mFeatureFactory.searchFeatureProvider
|
||||
.getSearchResultLoader(any(Context.class), anyString()))
|
||||
.thenReturn(new MockSearchResultLoader(RuntimeEnvironment.application));
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
final String testQuery = "test";
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
|
||||
ReflectionHelpers.setField(fragment, "mShowingSavedQuery", false);
|
||||
fragment.mQuery = testQuery;
|
||||
|
||||
activityController.saveInstanceState(bundle).pause().stop().destroy();
|
||||
|
||||
activityController = Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup(bundle);
|
||||
|
||||
assertThat(fragment.mQuery).isEqualTo(testQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void screenRotateEmptyString_ShouldNotCrash() {
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
fragment.mQuery = "";
|
||||
|
||||
activityController.saveInstanceState(bundle).pause().stop().destroy();
|
||||
|
||||
activityController = Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup(bundle);
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider, never())
|
||||
.getStaticSearchResultTask(any(Context.class), anyString());
|
||||
verify(mFeatureFactory.searchFeatureProvider, never())
|
||||
.getInstalledAppSearchTask(any(Context.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTextChange_shouldTriggerLoader() {
|
||||
when(mFeatureFactory.searchFeatureProvider
|
||||
.getSearchResultLoader(any(Context.class), anyString()))
|
||||
.thenReturn(mSearchResultLoader);
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
|
||||
final String testQuery = "test";
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
fragment.onQueryTextChange(testQuery);
|
||||
activityController.get().onBackPressed();
|
||||
|
||||
activityController.pause().stop().destroy();
|
||||
|
||||
verify(mFeatureFactory.metricsFeatureProvider, never()).action(
|
||||
any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_LEAVE_SEARCH_RESULT_WITHOUT_QUERY));
|
||||
verify(mFeatureFactory.searchFeatureProvider)
|
||||
.getSearchResultLoader(any(Context.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSearchResultsDisplayed_noResult_shouldShowNoResultView() {
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = spy((SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
fragment.onSearchResultsDisplayed(0 /* count */);
|
||||
|
||||
assertThat(fragment.mNoResultsView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).visible(
|
||||
any(Context.class),
|
||||
anyInt(),
|
||||
eq(MetricsProto.MetricsEvent.SETTINGS_SEARCH_NO_RESULT));
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(
|
||||
any(VisibilityLoggerMixin.class),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_SEARCH_RESULTS),
|
||||
eq(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTextChangeToEmpty_shouldLoadSavedQueryAndNotInitializeSearch() {
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = spy((SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
ReflectionHelpers.setField(fragment, "mSavedQueryController", mSavedQueryController);
|
||||
ReflectionHelpers.setField(fragment, "mSearchAdapter", mSearchResultsAdapter);
|
||||
fragment.mQuery = "123";
|
||||
|
||||
fragment.onQueryTextChange("");
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider, never())
|
||||
.getStaticSearchResultTask(any(Context.class), anyString());
|
||||
verify(mFeatureFactory.searchFeatureProvider, never())
|
||||
.getInstalledAppSearchTask(any(Context.class), anyString());
|
||||
verify(mSavedQueryController).loadSavedQueries();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateIndex_TriggerOnCreate() {
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
fragment.onAttach(null);
|
||||
verify(mFeatureFactory.searchFeatureProvider).updateIndexAsync(any(Context.class),
|
||||
any(IndexingCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNoQuery_HideFeedbackIsCalled() {
|
||||
when(mFeatureFactory.searchFeatureProvider
|
||||
.getSearchResultLoader(any(Context.class), anyString()))
|
||||
.thenReturn(new MockSearchResultLoader(RuntimeEnvironment.application));
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
when(fragment.getLoaderManager()).thenReturn(mock(LoaderManager.class));
|
||||
|
||||
fragment.onQueryTextChange("");
|
||||
Robolectric.flushForegroundThreadScheduler();
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider).hideFeedbackButton();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onLoadFinished_ShowsFeedback() {
|
||||
when(mFeatureFactory.searchFeatureProvider
|
||||
.getSearchResultLoader(any(Context.class), anyString()))
|
||||
.thenReturn(new MockSearchResultLoader(RuntimeEnvironment.application));
|
||||
when(mFeatureFactory.searchFeatureProvider.getSavedQueryLoader(any(Context.class)))
|
||||
.thenReturn(mSavedQueryLoader);
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
fragment.onQueryTextChange("non-empty");
|
||||
Robolectric.flushForegroundThreadScheduler();
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider).showFeedbackButton(any(SearchFragment.class),
|
||||
any(View.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preIndexingFinished_isIndexingFinishedFlag_isFalse() {
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onIndexingFinished_notShowingSavedQuery_initLoaders() {
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
final LoaderManager loaderManager = mock(LoaderManager.class);
|
||||
when(fragment.getLoaderManager()).thenReturn(loaderManager);
|
||||
fragment.mShowingSavedQuery = false;
|
||||
fragment.mQuery = null;
|
||||
|
||||
fragment.onIndexingFinished();
|
||||
|
||||
verify(loaderManager).initLoader(eq(SearchFragment.SearchLoaderId.SEARCH_RESULT),
|
||||
eq(null), any(LoaderManager.LoaderCallbacks.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onIndexingFinished_showingSavedQuery_loadsSavedQueries() {
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
fragment.mShowingSavedQuery = true;
|
||||
ReflectionHelpers.setField(fragment, "mSavedQueryController", mSavedQueryController);
|
||||
|
||||
fragment.onIndexingFinished();
|
||||
|
||||
verify(fragment.mSavedQueryController).loadSavedQueries();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onIndexingFinished_noActivity_shouldNotCrash() {
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) spy(activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
when(mFeatureFactory.searchFeatureProvider.isIndexingComplete(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
fragment.mQuery = "bright";
|
||||
ReflectionHelpers.setField(fragment, "mLoaderManager", null);
|
||||
ReflectionHelpers.setField(fragment, "mHost", null);
|
||||
|
||||
fragment.onIndexingFinished();
|
||||
// no crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSearchResultClicked_shouldLogResultMeta() {
|
||||
SearchFragment fragment = new SearchFragment();
|
||||
ReflectionHelpers.setField(fragment, "mMetricsFeatureProvider",
|
||||
mFeatureFactory.metricsFeatureProvider);
|
||||
ReflectionHelpers.setField(fragment, "mSearchFeatureProvider",
|
||||
mFeatureFactory.searchFeatureProvider);
|
||||
ReflectionHelpers.setField(fragment, "mSearchAdapter", mock(SearchResultsAdapter.class));
|
||||
fragment.mSavedQueryController = mock(SavedQueryController.class);
|
||||
|
||||
// Should log result name, result count, clicked rank, etc.
|
||||
final SearchViewHolder resultViewHolder = mock(SearchViewHolder.class);
|
||||
when(resultViewHolder.getClickActionMetricName())
|
||||
.thenReturn(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT);
|
||||
ResultPayload payLoad = new ResultPayload(
|
||||
(new Intent()).putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, "test_setting"));
|
||||
SearchResult searchResult = new SearchResult.Builder()
|
||||
.setStableId(payLoad.hashCode())
|
||||
.setPayload(payLoad)
|
||||
.setTitle("setting_title")
|
||||
.build();
|
||||
fragment.onSearchResultClicked(resultViewHolder, searchResult);
|
||||
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(
|
||||
nullable(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT),
|
||||
eq("test_setting"),
|
||||
argThat(pairMatches(MetricsProto.MetricsEvent.FIELD_SETTINGS_SEARCH_RESULT_COUNT)),
|
||||
argThat(pairMatches(MetricsProto.MetricsEvent.FIELD_SETTINGS_SEARCH_RESULT_RANK)),
|
||||
argThat(pairMatches(MetricsProto.MetricsEvent.FIELD_SETTINGS_SEARCH_QUERY_LENGTH)));
|
||||
verify(mFeatureFactory.searchFeatureProvider).searchResultClicked(nullable(Context.class),
|
||||
nullable(String.class), eq(searchResult));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldCallSearchRankingWarmupIfSmartSearchRankingEnabled() {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider)
|
||||
.searchRankingWarmup(any(Context.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldNotCallSearchRankingWarmupIfSmartSearchRankingDisabled() {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any(Context.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
ActivityController<SearchActivity> activityController =
|
||||
Robolectric.buildActivity(SearchActivity.class);
|
||||
activityController.setup();
|
||||
SearchFragment fragment = (SearchFragment) activityController.get().getFragmentManager()
|
||||
.findFragmentById(R.id.main_content);
|
||||
|
||||
verify(mFeatureFactory.searchFeatureProvider, never())
|
||||
.searchRankingWarmup(any(Context.class));
|
||||
}
|
||||
|
||||
private ArgumentMatcher<Pair<Integer, Object>> pairMatches(int tag) {
|
||||
return pair -> pair.first == tag;
|
||||
}
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SearchResultAggregatorTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private SearchResultAggregator mAggregator;
|
||||
|
||||
@Mock
|
||||
private DatabaseResultLoader mStaticTask;
|
||||
@Mock
|
||||
private InstalledAppResultLoader mAppTask;
|
||||
@Mock
|
||||
private InputDeviceResultLoader mInputTask;
|
||||
@Mock
|
||||
private AccessibilityServiceResultLoader mMAccessibilityTask;
|
||||
@Mock
|
||||
private ExecutorService mService;
|
||||
|
||||
|
||||
private String[] DB_TITLES = {"static_one", "static_two"};
|
||||
private String[] INPUT_TITLES = {"input_one", "input_two"};
|
||||
private String[] ACCESS_TITLES = {"access_one", "access_two"};
|
||||
private String[] APP_TITLES = {"app_one", "app_two"};
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mAggregator = spy(SearchResultAggregator.getInstance());
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
// Return mock loaders from feature provider
|
||||
when(mFeatureFactory.searchFeatureProvider.getStaticSearchResultTask(any(Context.class),
|
||||
anyString())).thenReturn(mStaticTask);
|
||||
when(mFeatureFactory.searchFeatureProvider.getInstalledAppSearchTask(any(Context.class),
|
||||
anyString())).thenReturn(mAppTask);
|
||||
when(mFeatureFactory.searchFeatureProvider.getInputDeviceResultTask(any(Context.class),
|
||||
anyString())).thenReturn(mInputTask);
|
||||
when(mFeatureFactory.searchFeatureProvider.getAccessibilityServiceResultTask(
|
||||
any(Context.class),
|
||||
anyString())).thenReturn(mMAccessibilityTask);
|
||||
when(mFeatureFactory.searchFeatureProvider.getExecutorService()).thenReturn(mService);
|
||||
|
||||
// Return fake data from the loaders
|
||||
List<? extends SearchResult> dbResults = getDummyDbResults();
|
||||
doReturn(dbResults).when(mStaticTask).get(anyLong(), any(TimeUnit.class));
|
||||
|
||||
List<? extends SearchResult> appResults = getDummyAppResults();
|
||||
doReturn(appResults).when(mAppTask).get(anyLong(), any(TimeUnit.class));
|
||||
|
||||
List<? extends SearchResult> inputResults = getDummyInputDeviceResults();
|
||||
doReturn(inputResults).when(mInputTask).get(anyLong(), any(TimeUnit.class));
|
||||
|
||||
List<? extends SearchResult> accessResults = getDummyAccessibilityResults();
|
||||
doReturn(accessResults).when(mMAccessibilityTask).get(anyLong(), any(TimeUnit.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticResults_mergedProperly() {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(mContext))
|
||||
.thenReturn(false);
|
||||
|
||||
List<? extends SearchResult> results = mAggregator.fetchResults(mContext, "test");
|
||||
|
||||
assertThat(results).hasSize(8);
|
||||
assertThat(results.get(0).title).isEqualTo(DB_TITLES[0]);
|
||||
assertThat(results.get(1).title).isEqualTo(DB_TITLES[1]);
|
||||
assertThat(results.get(2).title).isEqualTo(APP_TITLES[0]);
|
||||
assertThat(results.get(3).title).isEqualTo(ACCESS_TITLES[0]);
|
||||
assertThat(results.get(4).title).isEqualTo(INPUT_TITLES[0]);
|
||||
assertThat(results.get(5).title).isEqualTo(APP_TITLES[1]);
|
||||
assertThat(results.get(6).title).isEqualTo(ACCESS_TITLES[1]);
|
||||
assertThat(results.get(7).title).isEqualTo(INPUT_TITLES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticRanking_staticThrowsException_dbResultsAreMissing() throws Exception {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(mContext))
|
||||
.thenReturn(false);
|
||||
when(mStaticTask.get(anyLong(), any(TimeUnit.class))).thenThrow(new InterruptedException());
|
||||
|
||||
List<? extends SearchResult> results = mAggregator.fetchResults(mContext, "test");
|
||||
|
||||
assertThat(results).hasSize(6);
|
||||
assertThat(results.get(0).title).isEqualTo(APP_TITLES[0]);
|
||||
assertThat(results.get(1).title).isEqualTo(ACCESS_TITLES[0]);
|
||||
assertThat(results.get(2).title).isEqualTo(INPUT_TITLES[0]);
|
||||
assertThat(results.get(3).title).isEqualTo(APP_TITLES[1]);
|
||||
assertThat(results.get(4).title).isEqualTo(ACCESS_TITLES[1]);
|
||||
assertThat(results.get(5).title).isEqualTo(INPUT_TITLES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticRanking_appsThrowException_appResultsAreMissing() throws Exception {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(mContext))
|
||||
.thenReturn(false);
|
||||
when(mAppTask.get(anyLong(), any(TimeUnit.class))).thenThrow(new InterruptedException());
|
||||
|
||||
List<? extends SearchResult> results = mAggregator.fetchResults(mContext, "test");
|
||||
|
||||
assertThat(results).hasSize(6);
|
||||
assertThat(results.get(0).title).isEqualTo(DB_TITLES[0]);
|
||||
assertThat(results.get(1).title).isEqualTo(DB_TITLES[1]);
|
||||
assertThat(results.get(2).title).isEqualTo(ACCESS_TITLES[0]);
|
||||
assertThat(results.get(3).title).isEqualTo(INPUT_TITLES[0]);
|
||||
assertThat(results.get(4).title).isEqualTo(ACCESS_TITLES[1]);
|
||||
assertThat(results.get(5).title).isEqualTo(INPUT_TITLES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticRanking_inputThrowException_inputResultsAreMissing() throws Exception {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(mContext))
|
||||
.thenReturn(false);
|
||||
when(mInputTask.get(anyLong(), any(TimeUnit.class))).thenThrow(new InterruptedException());
|
||||
|
||||
List<? extends SearchResult> results = mAggregator.fetchResults(mContext, "test");
|
||||
|
||||
assertThat(results).hasSize(6);
|
||||
assertThat(results.get(0).title).isEqualTo(DB_TITLES[0]);
|
||||
assertThat(results.get(1).title).isEqualTo(DB_TITLES[1]);
|
||||
assertThat(results.get(2).title).isEqualTo(APP_TITLES[0]);
|
||||
assertThat(results.get(3).title).isEqualTo(ACCESS_TITLES[0]);
|
||||
assertThat(results.get(4).title).isEqualTo(APP_TITLES[1]);
|
||||
assertThat(results.get(5).title).isEqualTo(ACCESS_TITLES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticRanking_accessThrowException_accessResultsAreMissing() throws Exception {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(mContext))
|
||||
.thenReturn(false);
|
||||
when(mMAccessibilityTask.get(anyLong(), any(TimeUnit.class))).thenThrow(
|
||||
new InterruptedException());
|
||||
|
||||
List<? extends SearchResult> results = mAggregator.fetchResults(mContext, "test");
|
||||
|
||||
assertThat(results).hasSize(6);
|
||||
assertThat(results.get(0).title).isEqualTo(DB_TITLES[0]);
|
||||
assertThat(results.get(1).title).isEqualTo(DB_TITLES[1]);
|
||||
assertThat(results.get(2).title).isEqualTo(APP_TITLES[0]);
|
||||
assertThat(results.get(3).title).isEqualTo(INPUT_TITLES[0]);
|
||||
assertThat(results.get(4).title).isEqualTo(APP_TITLES[1]);
|
||||
assertThat(results.get(5).title).isEqualTo(INPUT_TITLES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDynamicRanking_sortsWithDynamicRanking() {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any())).thenReturn(
|
||||
true);
|
||||
|
||||
List<? extends SearchResult> results = mAggregator.fetchResults(mContext, "test");
|
||||
|
||||
assertThat(results).hasSize(8);
|
||||
assertThat(results.get(0).title).isEqualTo(DB_TITLES[0]);
|
||||
assertThat(results.get(1).title).isEqualTo(DB_TITLES[1]);
|
||||
assertThat(results.get(2).title).isEqualTo(APP_TITLES[0]);
|
||||
assertThat(results.get(3).title).isEqualTo(ACCESS_TITLES[0]);
|
||||
assertThat(results.get(4).title).isEqualTo(INPUT_TITLES[0]);
|
||||
assertThat(results.get(5).title).isEqualTo(APP_TITLES[1]);
|
||||
assertThat(results.get(6).title).isEqualTo(ACCESS_TITLES[1]);
|
||||
assertThat(results.get(7).title).isEqualTo(INPUT_TITLES[1]);
|
||||
}
|
||||
|
||||
private List<? extends SearchResult> getDummyDbResults() {
|
||||
List<SearchResult> results = new ArrayList<>();
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.setPayload(payload)
|
||||
.setTitle(DB_TITLES[0])
|
||||
.setRank(1)
|
||||
.setStableId(Objects.hash(DB_TITLES[0], "db"));
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle(DB_TITLES[1])
|
||||
.setRank(2)
|
||||
.setStableId(Objects.hash(DB_TITLES[1], "db"));
|
||||
results.add(builder.build());
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<? extends SearchResult> getDummyAppResults() {
|
||||
List<AppSearchResult> results = new ArrayList<>();
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
||||
builder.setPayload(payload)
|
||||
.setTitle(APP_TITLES[0])
|
||||
.setRank(1)
|
||||
.setStableId(Objects.hash(APP_TITLES[0], "app"));
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle(APP_TITLES[1])
|
||||
.setRank(2)
|
||||
.setStableId(Objects.hash(APP_TITLES[1], "app"));
|
||||
results.add(builder.build());
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<? extends SearchResult> getDummyInputDeviceResults() {
|
||||
List<SearchResult> results = new ArrayList<>();
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
||||
builder.setPayload(payload)
|
||||
.setTitle(INPUT_TITLES[0])
|
||||
.setRank(1)
|
||||
.setStableId(Objects.hash(INPUT_TITLES[0], "app"));
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle(INPUT_TITLES[1])
|
||||
.setRank(2)
|
||||
.setStableId(Objects.hash(INPUT_TITLES[1], "app"));
|
||||
results.add(builder.build());
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<? extends SearchResult> getDummyAccessibilityResults() {
|
||||
List<SearchResult> results = new ArrayList<>();
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
||||
builder.setPayload(payload)
|
||||
.setTitle(ACCESS_TITLES[0])
|
||||
.setRank(1)
|
||||
.setStableId(Objects.hash(ACCESS_TITLES[0], "app"));
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle(ACCESS_TITLES[1])
|
||||
.setRank(2)
|
||||
.setStableId(Objects.hash(ACCESS_TITLES[1], "app"));
|
||||
results.add(builder.build());
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* 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.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SearchResultsAdapterTest {
|
||||
|
||||
@Mock
|
||||
private SearchFragment mFragment;
|
||||
@Mock
|
||||
private SearchFeatureProvider mSearchFeatureProvider;
|
||||
@Mock
|
||||
private Context mMockContext;
|
||||
private SearchResultsAdapter mAdapter;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = Robolectric.buildActivity(Activity.class).get();
|
||||
when(mFragment.getContext()).thenReturn(mMockContext);
|
||||
when(mMockContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mSearchFeatureProvider.smartSearchRankingTimeoutMs(any(Context.class)))
|
||||
.thenReturn(300L);
|
||||
mAdapter = new SearchResultsAdapter(mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoResultsAdded_emptyListReturned() {
|
||||
List<SearchResult> updatedResults = mAdapter.getSearchResults();
|
||||
assertThat(updatedResults).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateViewHolder_returnsIntentResult() {
|
||||
ViewGroup group = new FrameLayout(mContext);
|
||||
SearchViewHolder view = mAdapter.onCreateViewHolder(group,
|
||||
ResultPayload.PayloadType.INTENT);
|
||||
assertThat(view).isInstanceOf(IntentSearchViewHolder.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateViewHolder_returnsIntentSwitchResult() {
|
||||
// TODO (b/62807132) test for InlineResult
|
||||
ViewGroup group = new FrameLayout(mContext);
|
||||
SearchViewHolder view = mAdapter.onCreateViewHolder(group,
|
||||
ResultPayload.PayloadType.INLINE_SWITCH);
|
||||
assertThat(view).isInstanceOf(IntentSearchViewHolder.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostSearchResults_addsDataAndDisplays() {
|
||||
List<SearchResult> results = getDummyDbResults();
|
||||
|
||||
mAdapter.postSearchResults(results);
|
||||
|
||||
assertThat(mAdapter.getSearchResults()).containsExactlyElementsIn(results);
|
||||
verify(mFragment).onSearchResultsDisplayed(anyInt());
|
||||
}
|
||||
|
||||
private List<SearchResult> getDummyDbResults() {
|
||||
List<SearchResult> results = new ArrayList<>();
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.setPayload(payload)
|
||||
.setTitle("one")
|
||||
.setRank(1)
|
||||
.setStableId(Objects.hash("one", "db"));
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle("two")
|
||||
.setRank(3)
|
||||
.setStableId(Objects.hash("two", "db"));
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle("three")
|
||||
.setRank(6)
|
||||
.setStableId(Objects.hash("three", "db"));
|
||||
results.add(builder.build());
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -1,513 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
import com.android.settings.search.DatabaseResultLoader.StaticSearchResultCallable;
|
||||
import com.android.settings.search.indexing.IndexData;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class StaticSearchResultFutureTaskTest {
|
||||
|
||||
@Mock
|
||||
private SiteMapManager mSiteMapManager;
|
||||
@Mock
|
||||
private ExecutorService mService;
|
||||
private Context mContext;
|
||||
|
||||
SQLiteDatabase mDb;
|
||||
|
||||
FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private final String[] STATIC_TITLES = {"static one", "static two", "static three"};
|
||||
private final int[] STABLE_IDS =
|
||||
{"id_one".hashCode(), "id_two".hashCode(), "id_three".hashCode()};
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(mFeatureFactory.searchFeatureProvider.getExecutorService()).thenReturn(mService);
|
||||
when(mFeatureFactory.searchFeatureProvider.getSiteMapManager())
|
||||
.thenReturn(mSiteMapManager);
|
||||
mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
||||
setUpDb();
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
DatabaseTestUtils.clearDb(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchTitle() throws Exception {
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "title",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(2);
|
||||
verify(mSiteMapManager, times(2)).buildBreadCrumb(eq(mContext), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchSummary() throws Exception {
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "summary",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchKeywords() throws Exception {
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "keywords",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchEntries() throws Exception {
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "entries",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseWord_matchesNonPrefix() throws Exception {
|
||||
insertSpecialCase("Data usage");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "usage",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseDash_matchesWordNoDash() throws Exception {
|
||||
insertSpecialCase("wi-fi calling");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "wifi",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseDash_matchesWordWithDash() throws Exception {
|
||||
insertSpecialCase("priorités seulment");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "priorités",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseDash_matchesWordWithoutDash() throws Exception {
|
||||
insertSpecialCase("priorités seulment");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "priorites",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseDash_matchesEntireQueryWithoutDash() throws Exception {
|
||||
insertSpecialCase("wi-fi calling");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "wifi calling",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCasePrefix_matchesPrefixOfEntry() throws Exception {
|
||||
insertSpecialCase("Photos");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "pho",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCasePrefix_DoesNotMatchNonPrefixSubstring() throws Exception {
|
||||
insertSpecialCase("Photos");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "hot",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseMultiWordPrefix_matchesPrefixOfEntry() throws Exception {
|
||||
insertSpecialCase("Apps Notifications");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "Apps",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseMultiWordPrefix_matchesSecondWordPrefixOfEntry() throws Exception {
|
||||
insertSpecialCase("Apps Notifications");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "Not",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseMultiWordPrefix_DoesNotMatchMatchesPrefixOfFirstEntry()
|
||||
throws Exception {
|
||||
insertSpecialCase("Apps Notifications");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "pp",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseMultiWordPrefix_DoesNotMatchMatchesPrefixOfSecondEntry()
|
||||
throws Exception {
|
||||
insertSpecialCase("Apps Notifications");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "tion",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseMultiWordPrefixWithSpecial_matchesPrefixOfEntry() throws
|
||||
Exception {
|
||||
insertSpecialCase("Apps & Notifications");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "App",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseMultiWordPrefixWithSpecial_matchesPrefixOfSecondEntry()
|
||||
throws Exception {
|
||||
insertSpecialCase("Apps & Notifications");
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "No",
|
||||
mSiteMapManager);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultMatchedByMultipleQueries_duplicatesRemoved() throws Exception {
|
||||
String key = "durr";
|
||||
insertSameValueAllFieldsCase(key);
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, key, null);
|
||||
|
||||
assertThat(loader.call()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCaseTwoWords_multipleResults() throws Exception {
|
||||
final String caseOne = "Apple pear";
|
||||
final String caseTwo = "Banana apple";
|
||||
insertSpecialCase(caseOne);
|
||||
insertSpecialCase(caseTwo);
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "App", null);
|
||||
|
||||
List<? extends SearchResult> results = loader.call();
|
||||
|
||||
Set<String> actualTitles = new HashSet<>();
|
||||
for (SearchResult result : results) {
|
||||
actualTitles.add(result.title.toString());
|
||||
}
|
||||
assertThat(actualTitles).containsAllOf(caseOne, caseTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRankingScoreByStableId_sortedDynamically() throws Exception {
|
||||
FutureTask<List<Pair<String, Float>>> task = mock(FutureTask.class);
|
||||
when(task.get(anyLong(), any(TimeUnit.class))).thenReturn(getDummyRankingScores());
|
||||
when(mFeatureFactory.searchFeatureProvider.getRankerTask(any(Context.class),
|
||||
anyString())).thenReturn(task);
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any())).thenReturn(
|
||||
true);
|
||||
|
||||
insertSpecialCase(STATIC_TITLES[0], STABLE_IDS[0]);
|
||||
insertSpecialCase(STATIC_TITLES[1], STABLE_IDS[1]);
|
||||
insertSpecialCase(STATIC_TITLES[2], STABLE_IDS[2]);
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "Static",
|
||||
null);
|
||||
|
||||
List<? extends SearchResult> results = loader.call();
|
||||
|
||||
assertThat(results.get(0).title).isEqualTo(STATIC_TITLES[2]);
|
||||
assertThat(results.get(1).title).isEqualTo(STATIC_TITLES[0]);
|
||||
assertThat(results.get(2).title).isEqualTo(STATIC_TITLES[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRankingScoreByStableId_scoresTimeout_sortedStatically() throws Exception {
|
||||
Callable<List<Pair<String, Float>>> callable = mock(Callable.class);
|
||||
when(callable.call()).thenThrow(new TimeoutException());
|
||||
FutureTask<List<Pair<String, Float>>> task = new FutureTask<>(callable);
|
||||
when(mFeatureFactory.searchFeatureProvider.isSmartSearchRankingEnabled(any())).thenReturn(
|
||||
true);
|
||||
when(mFeatureFactory.searchFeatureProvider.getRankerTask(any(Context.class),
|
||||
anyString())).thenReturn(task);
|
||||
insertSpecialCase("title", STABLE_IDS[0]);
|
||||
|
||||
StaticSearchResultCallable loader = new StaticSearchResultCallable(mContext, "title", null);
|
||||
|
||||
List<? extends SearchResult> results = loader.call();
|
||||
assertThat(results.get(0).title).isEqualTo("title");
|
||||
assertThat(results.get(1).title).isEqualTo("alpha_title");
|
||||
assertThat(results.get(2).title).isEqualTo("bravo_title");
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String specialCase) {
|
||||
insertSpecialCase(specialCase, specialCase.hashCode());
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String specialCase, int docId) {
|
||||
String normalized = IndexData.normalizeHyphen(specialCase);
|
||||
normalized = IndexData.normalizeString(normalized);
|
||||
final ResultPayload payload = new ResultPayload(new Intent());
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, docId);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_RANK, 1);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE, specialCase);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED, normalized);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_ENTRIES, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.CLASS_NAME,
|
||||
"com.android.settings.gestures.GestureSettings");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.SCREEN_TITLE, "Moves");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_ACTION, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_PACKAGE, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_CLASS, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ICON, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ENABLED, true);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, normalized.hashCode());
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, ResultPayloadUtils.marshall(payload));
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
}
|
||||
|
||||
private void setUpDb() {
|
||||
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(new Intent()));
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 1);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_RANK, 1);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE, "alpha_title");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED, "alpha title");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON, "alpha_summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED, "alpha summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF, "alpha_summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, "alpha summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_ENTRIES, "alpha entries");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS, "alpha keywords");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.CLASS_NAME,
|
||||
"com.android.settings.gestures.GestureSettings");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.SCREEN_TITLE, "Moves");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_ACTION, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_PACKAGE, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_CLASS, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ICON, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ENABLED, true);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power_0");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
|
||||
values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 2);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_RANK, 1);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE, "bravo_title");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED, "bravo title");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON, "bravo_summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED, "bravo summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF, "bravo_summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, "bravo summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_ENTRIES, "bravo entries");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS, "bravo keywords");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.CLASS_NAME,
|
||||
"com.android.settings.gestures.GestureSettings");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.SCREEN_TITLE, "Moves");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_ACTION, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_PACKAGE, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_CLASS, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ICON, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ENABLED, true);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power_1");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
|
||||
values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 3);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_RANK, 1);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE, "charlie_title");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED, "charlie title");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON, "charlie_summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED, "charlie summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF, "charlie_summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, "charlie summary");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_ENTRIES, "charlie entries");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS, "charlie keywords");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.CLASS_NAME,
|
||||
"com.android.settings.gestures.GestureSettings");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.SCREEN_TITLE, "Moves");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_ACTION, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_PACKAGE, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_CLASS, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ICON, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ENABLED, false);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power_2");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
}
|
||||
|
||||
private void insertSameValueAllFieldsCase(String key) {
|
||||
final ResultPayload payload = new ResultPayload(new Intent());
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, key.hashCode());
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_RANK, 1);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_ENTRIES, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.CLASS_NAME, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.SCREEN_TITLE, "Moves");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_ACTION, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_PACKAGE, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.INTENT_TARGET_CLASS, key);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ICON, "");
|
||||
values.put(IndexDatabaseHelper.IndexColumns.ENABLED, true);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, key.hashCode());
|
||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, ResultPayloadUtils.marshall(payload));
|
||||
|
||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||
}
|
||||
|
||||
private List<? extends SearchResult> getDummyDbResults() {
|
||||
List<SearchResult> results = new ArrayList<>();
|
||||
ResultPayload payload = new ResultPayload(new Intent());
|
||||
SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.setPayload(payload)
|
||||
.setTitle(STATIC_TITLES[0])
|
||||
.setStableId(STABLE_IDS[0]);
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle(STATIC_TITLES[1])
|
||||
.setStableId(STABLE_IDS[1]);
|
||||
results.add(builder.build());
|
||||
|
||||
builder.setTitle(STATIC_TITLES[2])
|
||||
.setStableId(STABLE_IDS[2]);
|
||||
results.add(builder.build());
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Pair<String, Float>> getDummyRankingScores() {
|
||||
List<? extends SearchResult> results = getDummyDbResults();
|
||||
List<Pair<String, Float>> scores = new ArrayList<>();
|
||||
scores.add(new Pair<>(Long.toString(results.get(2).stableId), 0.9f)); // static_three
|
||||
scores.add(new Pair<>(Long.toString(results.get(0).stableId), 0.8f)); // static_one
|
||||
scores.add(new Pair<>(Long.toString(results.get(1).stableId), 0.2f)); // static_two
|
||||
return scores;
|
||||
}
|
||||
}
|
||||
@@ -16,20 +16,16 @@
|
||||
|
||||
package com.android.settings.search.actionbar;
|
||||
|
||||
import static org.mockito.Matchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
|
||||
|
||||
@@ -47,30 +43,15 @@ public class SearchMenuControllerTest {
|
||||
@Mock
|
||||
private Menu mMenu;
|
||||
private TestFragment mHost;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mHost = new TestFragment();
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_searchV2Disabled_shouldNotAddMenu() {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSearchV2Enabled(nullable(Context.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
SearchMenuController.init(mHost);
|
||||
mHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
|
||||
|
||||
verifyZeroInteractions(mMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_searchV2Enabled_shouldAddMenu() {
|
||||
when(mFeatureFactory.searchFeatureProvider.isSearchV2Enabled(nullable(Context.class)))
|
||||
.thenReturn(true);
|
||||
public void init_shouldAddMenu() {
|
||||
when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
|
||||
.thenReturn(mock(MenuItem.class));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user