Build Intents at index time
In order to index Intents into Icing, they need to be built at Index time rather than at Search time. Test: make RunSettingsRoboTests Bug: 36443380 Change-Id: Ia731b5038380bb658232e2e175f52a81d86d7e02
This commit is contained in:
@@ -14,14 +14,17 @@
|
|||||||
package com.android.settings.display;
|
package com.android.settings.display;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.search2.DatabaseIndexingUtils;
|
||||||
import com.android.settings.search2.InlineSwitchPayload;
|
import com.android.settings.search2.InlineSwitchPayload;
|
||||||
import com.android.settings.search2.ResultPayload;
|
import com.android.settings.search2.ResultPayload;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -71,7 +74,11 @@ public class AutoBrightnessPreferenceController extends PreferenceController imp
|
|||||||
valueMap.put(SCREEN_BRIGHTNESS_MODE_AUTOMATIC, true);
|
valueMap.put(SCREEN_BRIGHTNESS_MODE_AUTOMATIC, true);
|
||||||
valueMap.put(SCREEN_BRIGHTNESS_MODE_MANUAL, false);
|
valueMap.put(SCREEN_BRIGHTNESS_MODE_MANUAL, false);
|
||||||
|
|
||||||
|
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||||
|
getClass().getName(), KEY_AUTO_BRIGHTNESS,
|
||||||
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(SCREEN_BRIGHTNESS_MODE,
|
return new InlineSwitchPayload(SCREEN_BRIGHTNESS_MODE,
|
||||||
ResultPayload.SettingsSource.SYSTEM, valueMap);
|
ResultPayload.SettingsSource.SYSTEM, valueMap, intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,21 +17,15 @@
|
|||||||
|
|
||||||
package com.android.settings.search2;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.BadParcelableException;
|
import android.os.BadParcelableException;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
|
||||||
import com.android.settings.SettingsActivity;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settings.dashboard.SiteMapManager;
|
import com.android.settings.dashboard.SiteMapManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -46,9 +40,6 @@ import java.util.Set;
|
|||||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_CLASS_NAME;
|
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_CLASS_NAME;
|
||||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ICON;
|
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ICON;
|
||||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ID;
|
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_ID;
|
||||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_INTENT_ACTION;
|
|
||||||
import static com.android.settings.search2.DatabaseResultLoader
|
|
||||||
.COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS;
|
|
||||||
import static com.android.settings.search2.DatabaseResultLoader
|
import static com.android.settings.search2.DatabaseResultLoader
|
||||||
.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
|
.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
|
||||||
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_KEY;
|
import static com.android.settings.search2.DatabaseResultLoader.COLUMN_INDEX_KEY;
|
||||||
@@ -132,7 +123,6 @@ class CursorToSearchResultConverter {
|
|||||||
mKeys.add(docId);
|
mKeys.add(docId);
|
||||||
|
|
||||||
final String pkgName = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
|
final String pkgName = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
|
||||||
final String action = cursor.getString(COLUMN_INDEX_INTENT_ACTION);
|
|
||||||
final String title = cursor.getString(COLUMN_INDEX_TITLE);
|
final String title = cursor.getString(COLUMN_INDEX_TITLE);
|
||||||
final String summaryOn = cursor.getString(COLUMN_INDEX_SUMMARY_ON);
|
final String summaryOn = cursor.getString(COLUMN_INDEX_SUMMARY_ON);
|
||||||
final String className = cursor.getString(COLUMN_INDEX_CLASS_NAME);
|
final String className = cursor.getString(COLUMN_INDEX_CLASS_NAME);
|
||||||
@@ -140,16 +130,7 @@ class CursorToSearchResultConverter {
|
|||||||
final String iconResStr = cursor.getString(COLUMN_INDEX_ICON);
|
final String iconResStr = cursor.getString(COLUMN_INDEX_ICON);
|
||||||
final int payloadType = cursor.getInt(COLUMN_INDEX_PAYLOAD_TYPE);
|
final int payloadType = cursor.getInt(COLUMN_INDEX_PAYLOAD_TYPE);
|
||||||
final byte[] marshalledPayload = cursor.getBlob(COLUMN_INDEX_PAYLOAD);
|
final byte[] marshalledPayload = cursor.getBlob(COLUMN_INDEX_PAYLOAD);
|
||||||
final ResultPayload payload;
|
final ResultPayload payload = getUnmarshalledPayload(marshalledPayload, payloadType);
|
||||||
|
|
||||||
if (marshalledPayload != null) {
|
|
||||||
payload = getUnmarshalledPayload(marshalledPayload, payloadType);
|
|
||||||
} else if (payloadType == ResultPayload.PayloadType.INTENT) {
|
|
||||||
payload = getIntentPayload(cursor, action, key, className, pkgName);
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "Error creating payload - bad marshalling data or mismatched types");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor);
|
final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor);
|
||||||
final int rank = getRank(title, breadcrumbs, baseRank, key);
|
final int rank = getRank(title, breadcrumbs, baseRank, key);
|
||||||
@@ -196,34 +177,12 @@ class CursorToSearchResultConverter {
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntentPayload getIntentPayload(Cursor cursor, String action, String key,
|
|
||||||
String className, String pkgName ) {
|
|
||||||
IntentPayload payload;
|
|
||||||
if (TextUtils.isEmpty(action)) {
|
|
||||||
final String screenTitle = cursor.getString(COLUMN_INDEX_SCREEN_TITLE);
|
|
||||||
// Action is null, we will launch it as a sub-setting
|
|
||||||
final Bundle args = new Bundle();
|
|
||||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
|
||||||
final Intent intent = Utils.onBuildStartFragmentIntent(mContext,
|
|
||||||
className, args, null, 0, screenTitle, false,
|
|
||||||
MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
|
|
||||||
payload = new IntentPayload(intent);
|
|
||||||
} else {
|
|
||||||
final Intent intent = new Intent(action);
|
|
||||||
final String targetClass = cursor.getString(COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS);
|
|
||||||
if (!TextUtils.isEmpty(pkgName) && !TextUtils.isEmpty(targetClass)) {
|
|
||||||
final ComponentName component = new ComponentName(pkgName, targetClass);
|
|
||||||
intent.setComponent(component);
|
|
||||||
}
|
|
||||||
intent.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
|
||||||
payload = new IntentPayload(intent);
|
|
||||||
}
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ResultPayload getUnmarshalledPayload(byte[] unmarshalledPayload, int payloadType) {
|
private ResultPayload getUnmarshalledPayload(byte[] unmarshalledPayload, int payloadType) {
|
||||||
try {
|
try {
|
||||||
switch (payloadType) {
|
switch (payloadType) {
|
||||||
|
case ResultPayload.PayloadType.INTENT:
|
||||||
|
return ResultPayloadUtils.unmarshall(unmarshalledPayload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
case ResultPayload.PayloadType.INLINE_SWITCH:
|
case ResultPayload.PayloadType.INLINE_SWITCH:
|
||||||
return ResultPayloadUtils.unmarshall(unmarshalledPayload,
|
return ResultPayloadUtils.unmarshall(unmarshalledPayload,
|
||||||
InlineSwitchPayload.CREATOR);
|
InlineSwitchPayload.CREATOR);
|
||||||
@@ -269,5 +228,4 @@ class CursorToSearchResultConverter {
|
|||||||
}
|
}
|
||||||
return baseRank;
|
return baseRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.android.settings.search2;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -39,6 +40,7 @@ import android.util.AttributeSet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
import com.android.settings.search.IndexDatabaseHelper;
|
import com.android.settings.search.IndexDatabaseHelper;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
@@ -927,7 +929,7 @@ public class DatabaseIndexingManager {
|
|||||||
.setNormalizedSummaryOff(normalizedSummaryOff)
|
.setNormalizedSummaryOff(normalizedSummaryOff)
|
||||||
.setSpaceDelimitedKeywords(spaceDelimitedKeywords);
|
.setSpaceDelimitedKeywords(spaceDelimitedKeywords);
|
||||||
|
|
||||||
updateOneRow(database, builder.build());
|
updateOneRow(database, builder.build(mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateOneRow(SQLiteDatabase database, DatabaseRow row) {
|
private void updateOneRow(SQLiteDatabase database, DatabaseRow row) {
|
||||||
@@ -1212,7 +1214,45 @@ public class DatabaseIndexingManager {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseRow build() {
|
/**
|
||||||
|
* Adds intent to inline payloads, or creates an Intent Payload as a fallback if the
|
||||||
|
* payload is null.
|
||||||
|
*/
|
||||||
|
private void setIntent(Context context) {
|
||||||
|
if (mPayload != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Intent intent = buildIntent(context);
|
||||||
|
mPayload = new ResultPayload(intent);
|
||||||
|
mPayloadType = ResultPayload.PayloadType.INTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds Intent payload to builder.
|
||||||
|
*/
|
||||||
|
private Intent buildIntent(Context context) {
|
||||||
|
final Intent intent;
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(mIntentAction)) {
|
||||||
|
// Action is null, we will launch it as a sub-setting
|
||||||
|
intent = DatabaseIndexingUtils.buildSubsettingIntent(context, mClassName, mKey,
|
||||||
|
mScreenTitle);
|
||||||
|
} else {
|
||||||
|
intent = new Intent(mIntentAction);
|
||||||
|
final String targetClass = mIntentTargetClass;
|
||||||
|
if (!TextUtils.isEmpty(mIntentTargetPackage)
|
||||||
|
&& !TextUtils.isEmpty(targetClass)) {
|
||||||
|
final ComponentName component = new ComponentName(mIntentTargetPackage,
|
||||||
|
targetClass);
|
||||||
|
intent.setComponent(component);
|
||||||
|
}
|
||||||
|
intent.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mKey);
|
||||||
|
}
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseRow build(Context context) {
|
||||||
|
setIntent(context);
|
||||||
return new DatabaseRow(this);
|
return new DatabaseRow(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,15 +19,20 @@ package com.android.settings.search2;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
|
|
||||||
@@ -57,6 +62,18 @@ public class DatabaseIndexingUtils {
|
|||||||
private static final Pattern REMOVE_DIACRITICALS_PATTERN
|
private static final Pattern REMOVE_DIACRITICALS_PATTERN
|
||||||
= Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
|
= Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds intent into a subsetting.
|
||||||
|
*/
|
||||||
|
public static Intent buildSubsettingIntent(Context context, String className, String key,
|
||||||
|
String screenTitle) {
|
||||||
|
final Bundle args = new Bundle();
|
||||||
|
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||||
|
return Utils.onBuildStartFragmentIntent(context,
|
||||||
|
className, args, null, 0, screenTitle, false,
|
||||||
|
MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param className which wil provide the map between from {@link Uri}s to
|
* @param className which wil provide the map between from {@link Uri}s to
|
||||||
* {@link PreferenceController}
|
* {@link PreferenceController}
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.search2;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Payload for inline settings results.
|
* Abstract Payload for inline settings results.
|
||||||
*/
|
*/
|
||||||
@@ -35,7 +37,9 @@ public abstract class InlinePayload extends ResultPayload {
|
|||||||
*/
|
*/
|
||||||
@SettingsSource public int settingSource;
|
@SettingsSource public int settingSource;
|
||||||
|
|
||||||
public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source) {
|
public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source,
|
||||||
|
Intent intent) {
|
||||||
|
super(intent);
|
||||||
settingsUri = uri;
|
settingsUri = uri;
|
||||||
inlineType = type;
|
inlineType = type;
|
||||||
settingSource = source;
|
settingSource = source;
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
package com.android.settings.search2;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -38,14 +39,15 @@ public class InlineSwitchPayload extends InlinePayload {
|
|||||||
public final Map<Integer, Boolean> valueMap;
|
public final Map<Integer, Boolean> valueMap;
|
||||||
|
|
||||||
public InlineSwitchPayload(String newUri, @SettingsSource int settingsSource,
|
public InlineSwitchPayload(String newUri, @SettingsSource int settingsSource,
|
||||||
Map<Integer, Boolean> map) {
|
Map<Integer, Boolean> map, Intent intent) {
|
||||||
super(newUri, PayloadType.INLINE_SWITCH, settingsSource);
|
super(newUri, PayloadType.INLINE_SWITCH, settingsSource, intent);
|
||||||
valueMap = map;
|
valueMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InlineSwitchPayload(Parcel in) {
|
private InlineSwitchPayload(Parcel in) {
|
||||||
super(in.readString() /* Uri */ , in.readInt() /* Payload Type */,
|
super(in.readString() /* Uri */ , in.readInt() /* Payload Type */,
|
||||||
in.readInt() /* Settings Source */);
|
in.readInt() /* Settings Source */,
|
||||||
|
(Intent) in.readParcelable(Intent.class.getClassLoader()) /* Intent */);
|
||||||
valueMap = in.readHashMap(Integer.class.getClassLoader());
|
valueMap = in.readHashMap(Integer.class.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +66,7 @@ public class InlineSwitchPayload extends InlinePayload {
|
|||||||
dest.writeString(settingsUri);
|
dest.writeString(settingsUri);
|
||||||
dest.writeInt(inlineType);
|
dest.writeInt(inlineType);
|
||||||
dest.writeInt(settingSource);
|
dest.writeInt(settingSource);
|
||||||
|
dest.writeParcelable(mIntent, flags);
|
||||||
dest.writeMap(valueMap);
|
dest.writeMap(valueMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,6 @@ import com.android.settings.SettingsActivity;
|
|||||||
import com.android.settings.applications.ManageApplications;
|
import com.android.settings.applications.ManageApplications;
|
||||||
import com.android.settings.applications.PackageManagerWrapper;
|
import com.android.settings.applications.PackageManagerWrapper;
|
||||||
import com.android.settings.dashboard.SiteMapManager;
|
import com.android.settings.dashboard.SiteMapManager;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
import com.android.settings.utils.AsyncLoader;
|
import com.android.settings.utils.AsyncLoader;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -98,7 +97,7 @@ public class InstalledAppResultLoader extends AsyncLoader<List<? extends SearchR
|
|||||||
.addTitle(info.loadLabel(pm))
|
.addTitle(info.loadLabel(pm))
|
||||||
.addRank(getRank(wordDiff))
|
.addRank(getRank(wordDiff))
|
||||||
.addBreadcrumbs(getBreadCrumb())
|
.addBreadcrumbs(getBreadCrumb())
|
||||||
.addPayload(new IntentPayload(intent));
|
.addPayload(new ResultPayload(intent));
|
||||||
results.add(builder.build());
|
results.add(builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,62 +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.search2;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Parcel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encapsulates the standard intent based results as seen in first party apps and Settings results.
|
|
||||||
*/
|
|
||||||
public class IntentPayload extends ResultPayload {
|
|
||||||
public final Intent intent;
|
|
||||||
|
|
||||||
private IntentPayload(Parcel in) {
|
|
||||||
intent = in.readParcelable(IntentPayload.class.getClassLoader());
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntentPayload(Intent newIntent) {
|
|
||||||
intent = newIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ResultPayload.PayloadType public int getType() {
|
|
||||||
return PayloadType.INTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeParcelable(intent, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Creator<IntentPayload> CREATOR = new Creator<IntentPayload>() {
|
|
||||||
@Override
|
|
||||||
public IntentPayload createFromParcel(Parcel in) {
|
|
||||||
return new IntentPayload(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IntentPayload[] newArray(int size) {
|
|
||||||
return new IntentPayload[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
@@ -40,7 +40,7 @@ public class IntentSearchViewHolder extends SearchViewHolder {
|
|||||||
|
|
||||||
itemView.setOnClickListener(v -> {
|
itemView.setOnClickListener(v -> {
|
||||||
fragment.onSearchResultClicked();
|
fragment.onSearchResultClicked();
|
||||||
final Intent intent = ((IntentPayload) result.payload).intent;
|
final Intent intent = result.payload.getIntent();
|
||||||
final ComponentName cn = intent.getComponent();
|
final ComponentName cn = intent.getComponent();
|
||||||
final Pair<Integer, Object> rank = Pair.create(
|
final Pair<Integer, Object> rank = Pair.create(
|
||||||
MetricsEvent.FIELD_SETTINGS_SERACH_RESULT_RANK, getAdapterPosition());
|
MetricsEvent.FIELD_SETTINGS_SERACH_RESULT_RANK, getAdapterPosition());
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
package com.android.settings.search2;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -26,14 +28,15 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
* A interface for search results types. Examples include Inline results, third party apps
|
* A interface for search results types. Examples include Inline results, third party apps
|
||||||
* or any future possibilities.
|
* or any future possibilities.
|
||||||
*/
|
*/
|
||||||
public abstract class ResultPayload implements Parcelable {
|
public class ResultPayload implements Parcelable {
|
||||||
|
protected final Intent mIntent;
|
||||||
|
|
||||||
@IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
|
@IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
|
||||||
PayloadType.INTENT, PayloadType.SAVED_QUERY})
|
PayloadType.INTENT, PayloadType.SAVED_QUERY})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface PayloadType {
|
public @interface PayloadType {
|
||||||
/**
|
/**
|
||||||
* Resulting page will be started using an intent
|
* Resulting page will be started using an mIntent
|
||||||
*/
|
*/
|
||||||
int INTENT = 0;
|
int INTENT = 0;
|
||||||
|
|
||||||
@@ -64,6 +67,42 @@ public abstract class ResultPayload implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ResultPayload(Parcel in) {
|
||||||
|
mIntent = in.readParcelable(ResultPayload.class.getClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultPayload(Intent intent) {
|
||||||
|
mIntent = intent;
|
||||||
|
}
|
||||||
|
|
||||||
@ResultPayload.PayloadType
|
@ResultPayload.PayloadType
|
||||||
public abstract int getType();
|
public int getType() {
|
||||||
|
return PayloadType.INTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeParcelable(mIntent, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<ResultPayload> CREATOR = new Creator<ResultPayload>() {
|
||||||
|
@Override
|
||||||
|
public ResultPayload createFromParcel(Parcel in) {
|
||||||
|
return new ResultPayload(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultPayload[] newArray(int size) {
|
||||||
|
return new ResultPayload[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public Intent getIntent() {
|
||||||
|
return mIntent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,11 +27,13 @@ public class SavedQueryPayload extends ResultPayload {
|
|||||||
public final String query;
|
public final String query;
|
||||||
|
|
||||||
public SavedQueryPayload(String query) {
|
public SavedQueryPayload(String query) {
|
||||||
|
super(null /* Intent */);
|
||||||
this.query = query;
|
this.query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
SavedQueryPayload(Parcel in) {
|
SavedQueryPayload(Parcel in) {
|
||||||
|
super(null /* Intent */);
|
||||||
query = in.readString();
|
query = in.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,14 +25,8 @@ import com.android.settings.SettingsRobolectricTestRunner;
|
|||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||||
import com.android.settings.gestures.DoubleTapPowerPreferenceController;
|
|
||||||
import com.android.settings.gestures.DoubleTapScreenPreferenceController;
|
|
||||||
import com.android.settings.gestures.DoubleTwistPreferenceController;
|
|
||||||
import com.android.settings.gestures.PickupGesturePreferenceController;
|
|
||||||
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
|
|
||||||
import com.android.settings.search2.DatabaseIndexingUtils;
|
import com.android.settings.search2.DatabaseIndexingUtils;
|
||||||
|
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import com.android.settings.search2.ResultPayload;
|
import com.android.settings.search2.ResultPayload;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -103,13 +97,13 @@ public class DatabaseIndexingUtilsTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultPayload getResultPayload() {
|
public ResultPayload getResultPayload() {
|
||||||
return new IntentPayload(null);
|
return new ResultPayload(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ArrayMap<String,PreferenceController> map = new ArrayMap<>();
|
ArrayMap<String,PreferenceController> map = new ArrayMap<>();
|
||||||
map.put(key, prefController);
|
map.put(key, prefController);
|
||||||
|
|
||||||
ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
|
ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
|
||||||
assertThat(payload).isInstanceOf(IntentPayload.class);
|
assertThat(payload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -43,7 +44,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
final int source = ResultPayload.SettingsSource.SECURE;
|
final int source = ResultPayload.SettingsSource.SECURE;
|
||||||
|
|
||||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, null);
|
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, null, null);
|
||||||
try {
|
try {
|
||||||
payload.getSwitchValue(context);
|
payload.getSwitchValue(context);
|
||||||
fail("Should have thrown exception for null map");
|
fail("Should have thrown exception for null map");
|
||||||
@@ -59,7 +60,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||||
|
|
||||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
|
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, null);
|
||||||
try {
|
try {
|
||||||
payload.getSwitchValue(context);
|
payload.getSwitchValue(context);
|
||||||
fail("Should have thrown exception for bad map");
|
fail("Should have thrown exception for bad map");
|
||||||
@@ -76,13 +77,19 @@ public class InlineSwitchPayloadTest {
|
|||||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||||
map.put(1, true);
|
map.put(1, true);
|
||||||
map.put(0, false);
|
map.put(0, false);
|
||||||
|
final String intentKey = "key";
|
||||||
|
final String intentVal = "value";
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.putExtra(intentKey, intentVal);
|
||||||
|
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
|
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, intent);
|
||||||
|
final Intent retainedIntent = payload.getIntent();
|
||||||
assertThat(payload.settingsUri).isEqualTo(uri);
|
assertThat(payload.settingsUri).isEqualTo(uri);
|
||||||
assertThat(payload.inlineType).isEqualTo(type);
|
assertThat(payload.inlineType).isEqualTo(type);
|
||||||
assertThat(payload.settingSource).isEqualTo(source);
|
assertThat(payload.settingSource).isEqualTo(source);
|
||||||
assertThat(payload.valueMap.get(1)).isTrue();
|
assertThat(payload.valueMap.get(1)).isTrue();
|
||||||
assertThat(payload.valueMap.get(0)).isFalse();
|
assertThat(payload.valueMap.get(0)).isFalse();
|
||||||
|
assertThat(retainedIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,20 +100,27 @@ public class InlineSwitchPayloadTest {
|
|||||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||||
map.put(1, true);
|
map.put(1, true);
|
||||||
map.put(0, false);
|
map.put(0, false);
|
||||||
|
final String intentKey = "key";
|
||||||
|
final String intentVal = "value";
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.putExtra(intentKey, intentVal);
|
||||||
|
|
||||||
Parcel parcel = Parcel.obtain();
|
Parcel parcel = Parcel.obtain();
|
||||||
parcel.writeString(uri);
|
parcel.writeString(uri);
|
||||||
parcel.writeInt(type);
|
parcel.writeInt(type);
|
||||||
parcel.writeInt(source);
|
parcel.writeInt(source);
|
||||||
|
parcel.writeParcelable(intent, 0);
|
||||||
parcel.writeMap(map);
|
parcel.writeMap(map);
|
||||||
parcel.setDataPosition(0);
|
parcel.setDataPosition(0);
|
||||||
|
|
||||||
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
|
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
|
||||||
|
final Intent builtIntent = payload.getIntent();
|
||||||
assertThat(payload.settingsUri).isEqualTo(uri);
|
assertThat(payload.settingsUri).isEqualTo(uri);
|
||||||
assertThat(payload.inlineType).isEqualTo(type);
|
assertThat(payload.inlineType).isEqualTo(type);
|
||||||
assertThat(payload.settingSource).isEqualTo(source);
|
assertThat(payload.settingSource).isEqualTo(source);
|
||||||
assertThat(payload.valueMap.get(1)).isTrue();
|
assertThat(payload.valueMap.get(1)).isTrue();
|
||||||
assertThat(payload.valueMap.get(0)).isFalse();
|
assertThat(payload.valueMap.get(0)).isFalse();
|
||||||
|
assertThat(builtIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -117,7 +117,7 @@ public class InlineSwitchViewHolderTest {
|
|||||||
builder.addTitle(TITLE)
|
builder.addTitle(TITLE)
|
||||||
.addSummary(SUMMARY)
|
.addSummary(SUMMARY)
|
||||||
.addRank(1)
|
.addRank(1)
|
||||||
.addPayload(new InlineSwitchPayload("", 0, null))
|
.addPayload(new InlineSwitchPayload("", 0, null, null))
|
||||||
.addBreadcrumbs(new ArrayList<>())
|
.addBreadcrumbs(new ArrayList<>())
|
||||||
.addIcon(mIcon)
|
.addIcon(mIcon)
|
||||||
.addPayload(mPayload);
|
.addPayload(mPayload);
|
||||||
|
@@ -18,12 +18,12 @@
|
|||||||
package com.android.settings.search;
|
package com.android.settings.search;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import com.android.settings.search2.ResultPayload;
|
import com.android.settings.search2.ResultPayload;
|
||||||
import com.android.settings.search2.SearchResult;
|
import com.android.settings.search2.SearchResult;
|
||||||
import com.android.settings.search2.SearchResult.Builder;
|
import com.android.settings.search2.SearchResult.Builder;
|
||||||
@@ -57,7 +57,7 @@ public class SearchResultBuilderTest {
|
|||||||
mSummary = "summary";
|
mSummary = "summary";
|
||||||
mBreadcrumbs = new ArrayList<>();
|
mBreadcrumbs = new ArrayList<>();
|
||||||
mRank = 3;
|
mRank = 3;
|
||||||
mResultPayload = new IntentPayload(null);
|
mResultPayload = new ResultPayload(new Intent());
|
||||||
|
|
||||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
mIcon = context.getDrawable(R.drawable.ic_search_history);
|
mIcon = context.getDrawable(R.drawable.ic_search_history);
|
||||||
|
@@ -31,9 +31,8 @@ import com.android.settings.search2.AppSearchResult;
|
|||||||
import com.android.settings.search2.DatabaseResultLoader;
|
import com.android.settings.search2.DatabaseResultLoader;
|
||||||
import com.android.settings.search2.InlineSwitchViewHolder;
|
import com.android.settings.search2.InlineSwitchViewHolder;
|
||||||
import com.android.settings.search2.InstalledAppResultLoader;
|
import com.android.settings.search2.InstalledAppResultLoader;
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import com.android.settings.search2.IntentSearchViewHolder;
|
|
||||||
import com.android.settings.search2.ResultPayload;
|
import com.android.settings.search2.ResultPayload;
|
||||||
|
import com.android.settings.search2.IntentSearchViewHolder;
|
||||||
import com.android.settings.search2.SearchFeatureProvider;
|
import com.android.settings.search2.SearchFeatureProvider;
|
||||||
import com.android.settings.search2.SearchFragment;
|
import com.android.settings.search2.SearchFragment;
|
||||||
import com.android.settings.search2.SearchResult;
|
import com.android.settings.search2.SearchResult;
|
||||||
@@ -154,7 +153,7 @@ public class SearchResultsAdapterTest {
|
|||||||
|
|
||||||
private List<SearchResult> getDummyDbResults() {
|
private List<SearchResult> getDummyDbResults() {
|
||||||
List<SearchResult> results = new ArrayList<>();
|
List<SearchResult> results = new ArrayList<>();
|
||||||
IntentPayload payload = new IntentPayload(new Intent());
|
ResultPayload payload = new ResultPayload(new Intent());
|
||||||
SearchResult.Builder builder = new SearchResult.Builder();
|
SearchResult.Builder builder = new SearchResult.Builder();
|
||||||
builder.addPayload(payload);
|
builder.addPayload(payload);
|
||||||
|
|
||||||
@@ -175,7 +174,7 @@ public class SearchResultsAdapterTest {
|
|||||||
|
|
||||||
private List<AppSearchResult> getDummyAppResults() {
|
private List<AppSearchResult> getDummyAppResults() {
|
||||||
List<AppSearchResult> results = new ArrayList<>();
|
List<AppSearchResult> results = new ArrayList<>();
|
||||||
IntentPayload payload = new IntentPayload(new Intent());
|
ResultPayload payload = new ResultPayload(new Intent());
|
||||||
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
AppSearchResult.Builder builder = new AppSearchResult.Builder();
|
||||||
builder.addPayload(payload);
|
builder.addPayload(payload);
|
||||||
|
|
||||||
@@ -198,7 +197,7 @@ public class SearchResultsAdapterTest {
|
|||||||
ArrayList<SearchResult> sampleResults = new ArrayList<>();
|
ArrayList<SearchResult> sampleResults = new ArrayList<>();
|
||||||
ArrayList<String> breadcrumbs = new ArrayList<>();
|
ArrayList<String> breadcrumbs = new ArrayList<>();
|
||||||
final Drawable icon = mContext.getDrawable(R.drawable.ic_search_history);
|
final Drawable icon = mContext.getDrawable(R.drawable.ic_search_history);
|
||||||
final ResultPayload payload = new IntentPayload(null);
|
final ResultPayload payload = new ResultPayload(null);
|
||||||
final SearchResult.Builder builder = new Builder();
|
final SearchResult.Builder builder = new Builder();
|
||||||
builder.addTitle("title")
|
builder.addTitle("title")
|
||||||
.addSummary("summary")
|
.addSummary("summary")
|
||||||
|
@@ -20,7 +20,9 @@ package com.android.settings.search2;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ public class CursorToSearchResultConverterTest {
|
|||||||
private static final String TARGET_PACKAGE = "a.b.c";
|
private static final String TARGET_PACKAGE = "a.b.c";
|
||||||
private static final String TARGET_CLASS = "a.b.c.class";
|
private static final String TARGET_CLASS = "a.b.c.class";
|
||||||
private static final String QUERY = "query";
|
private static final String QUERY = "query";
|
||||||
|
private static final String KEY = "key";
|
||||||
private static final Intent INTENT = new Intent("com.android.settings");
|
private static final Intent INTENT = new Intent("com.android.settings");
|
||||||
private static final int ICON = R.drawable.ic_search_history;
|
private static final int ICON = R.drawable.ic_search_history;
|
||||||
private static final int BASE_RANK = 1;
|
private static final int BASE_RANK = 1;
|
||||||
@@ -78,20 +81,20 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNullResults_ReturnsNull() {
|
public void testParseNullResults_ReturnsNull() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, null, BASE_RANK);
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, null, BASE_RANK);
|
||||||
assertThat(results).isNull();
|
assertThat(results).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_NotNull() {
|
public void testParseCursor_NotNull() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||||
assertThat(results).isNotNull();
|
assertThat(results).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesRank() {
|
public void testParseCursor_MatchesRank() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
assertThat(results.get(i).rank).isEqualTo(BASE_RANK);
|
assertThat(results.get(i).rank).isEqualTo(BASE_RANK);
|
||||||
@@ -100,7 +103,7 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesTitle() {
|
public void testParseCursor_MatchesTitle() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
assertThat(results.get(i).title).isEqualTo(TITLES[i]);
|
assertThat(results.get(i).title).isEqualTo(TITLES[i]);
|
||||||
@@ -109,7 +112,7 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesSummary() {
|
public void testParseCursor_MatchesSummary() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
assertThat(results.get(i).summary).isEqualTo(SUMMARY);
|
assertThat(results.get(i).summary).isEqualTo(SUMMARY);
|
||||||
@@ -118,19 +121,38 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesIcon() {
|
public void testParseCursor_MatchesIcon() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
final String BLANK = "";
|
||||||
Drawable resultDrawable = results.get(i).icon;
|
cursor.addRow(new Object[]{
|
||||||
|
ID, // Doc ID
|
||||||
|
"Longer than 20 characters", // Title
|
||||||
|
SUMMARY, // Summary on
|
||||||
|
SUMMARY, // summary off
|
||||||
|
DisplaySettings.class.getName(),
|
||||||
|
BLANK, // screen title
|
||||||
|
ICON, // icon
|
||||||
|
BLANK, // action
|
||||||
|
null, // target package
|
||||||
|
BLANK, // target class
|
||||||
|
BLANK, // Key
|
||||||
|
PayloadType.INTENT, // Payload Type
|
||||||
|
payload // Payload
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
|
mSiteMapManager, cursor, BASE_RANK);
|
||||||
|
|
||||||
|
Drawable resultDrawable = results.get(0).icon;
|
||||||
assertThat(resultDrawable).isNotNull();
|
assertThat(resultDrawable).isNotNull();
|
||||||
assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
|
assertThat(resultDrawable.toString()).isEqualTo(mDrawable.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_NoIcon() {
|
public void testParseCursor_NoIcon() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
mSiteMapManager, getDummyCursor(false /* hasIcon */), BASE_RANK);
|
mSiteMapManager, getDummyCursor(false /* hasIcon */, "" /* className */,
|
||||||
|
"" /* key */), BASE_RANK);
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
Drawable resultDrawable = results.get(i).icon;
|
Drawable resultDrawable = results.get(i).icon;
|
||||||
assertThat(resultDrawable).isNull();
|
assertThat(resultDrawable).isNull();
|
||||||
@@ -139,7 +161,7 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesPayloadType() {
|
public void testParseCursor_MatchesPayloadType() {
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||||
ResultPayload payload;
|
ResultPayload payload;
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
@@ -150,7 +172,8 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLongTitle_PenalizedInRank() {
|
public void testLongTitle_PenalizedInRank() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
final MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||||
|
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
|
||||||
final String BLANK = "";
|
final String BLANK = "";
|
||||||
cursor.addRow(new Object[]{
|
cursor.addRow(new Object[]{
|
||||||
ID, // Doc ID
|
ID, // Doc ID
|
||||||
@@ -164,75 +187,26 @@ public class CursorToSearchResultConverterTest {
|
|||||||
null, // target package
|
null, // target package
|
||||||
BLANK, // target class
|
BLANK, // target class
|
||||||
BLANK, // Key
|
BLANK, // Key
|
||||||
0, // Payload Type
|
PayloadType.INTENT, // Payload Type
|
||||||
null // Payload
|
payload // Payload
|
||||||
});
|
});
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
|
BASE_RANK);
|
||||||
assertThat(results.get(0).rank).isEqualTo(BASE_RANK + 2);
|
assertThat(results.get(0).rank).isEqualTo(BASE_RANK + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesIntentForSubSettings() {
|
public void testParseCursor_MatchesResultPayload() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
final List<SearchResult> results = mConverter.convertCursor(
|
||||||
final String BLANK = "";
|
|
||||||
cursor.addRow(new Object[]{
|
|
||||||
ID, // Doc ID
|
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
SwipeToNotificationSettings.class.getName(),
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
BLANK, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
IntentPayload payload = (IntentPayload) results.get(0).payload;
|
|
||||||
Intent intent = payload.intent;
|
|
||||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParseCursor_MatchesIntentPayload() {
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(
|
|
||||||
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
mSiteMapManager, getDummyCursor(), BASE_RANK);
|
||||||
IntentPayload payload;
|
ResultPayload payload;
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
payload = (IntentPayload) results.get(i).payload;
|
payload = results.get(i).payload;
|
||||||
Intent intent = payload.intent;
|
Intent intent = payload.getIntent();
|
||||||
assertThat(intent.getAction()).isEqualTo(INTENT.getAction());
|
assertThat(intent.getAction()).isEqualTo(INTENT.getAction());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParseCursor_MatchesIntentPayloadForExternalApps() {
|
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
cursor.addRow(new Object[]{
|
|
||||||
ID, // Doc ID
|
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
null, // class
|
|
||||||
TITLES[0], // Title
|
|
||||||
null, // icon
|
|
||||||
Intent.ACTION_VIEW, // action
|
|
||||||
TARGET_PACKAGE, // target package
|
|
||||||
TARGET_CLASS, // target class
|
|
||||||
QUERY, // Key
|
|
||||||
PayloadType.INTENT, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
IntentPayload payload = (IntentPayload) results.get(0).payload;
|
|
||||||
Intent intent = payload.intent;
|
|
||||||
|
|
||||||
assertThat(intent.getComponent().getPackageName()).isEqualTo(TARGET_PACKAGE);
|
|
||||||
assertThat(intent.getComponent().getClassName()).isEqualTo(TARGET_CLASS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCursor_MatchesInlineSwitchPayload() {
|
public void testParseCursor_MatchesInlineSwitchPayload() {
|
||||||
@@ -244,7 +218,11 @@ public class CursorToSearchResultConverterTest {
|
|||||||
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
final ArrayMap<Integer, Boolean> map = new ArrayMap<>();
|
||||||
map.put(1, true);
|
map.put(1, true);
|
||||||
map.put(0, false);
|
map.put(0, false);
|
||||||
final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map);
|
final String intentKey = "key";
|
||||||
|
final String intentVal = "value";
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.putExtra(intentKey, intentVal);
|
||||||
|
final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, map, intent);
|
||||||
|
|
||||||
cursor.addRow(new Object[]{
|
cursor.addRow(new Object[]{
|
||||||
ID, // Doc ID
|
ID, // Doc ID
|
||||||
@@ -261,14 +239,16 @@ public class CursorToSearchResultConverterTest {
|
|||||||
type, // Payload Type
|
type, // Payload Type
|
||||||
ResultPayloadUtils.marshall(payload) // Payload
|
ResultPayloadUtils.marshall(payload) // Payload
|
||||||
});
|
});
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
InlineSwitchPayload newPayload = (InlineSwitchPayload) results.get(0).payload;
|
BASE_RANK);
|
||||||
|
final InlineSwitchPayload newPayload = (InlineSwitchPayload) results.get(0).payload;
|
||||||
|
final Intent rebuiltIntent = newPayload.getIntent();
|
||||||
assertThat(newPayload.settingsUri).isEqualTo(uri);
|
assertThat(newPayload.settingsUri).isEqualTo(uri);
|
||||||
assertThat(newPayload.inlineType).isEqualTo(type);
|
assertThat(newPayload.inlineType).isEqualTo(type);
|
||||||
assertThat(newPayload.settingSource).isEqualTo(source);
|
assertThat(newPayload.settingSource).isEqualTo(source);
|
||||||
assertThat(newPayload.valueMap.get(1)).isTrue();
|
assertThat(newPayload.valueMap.get(1)).isTrue();
|
||||||
assertThat(newPayload.valueMap.get(0)).isFalse();
|
assertThat(newPayload.valueMap.get(0)).isFalse();
|
||||||
|
assertThat(rebuiltIntent.getStringExtra(intentKey)).isEqualTo(intentVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following tests are temporary, and should be removed when we replace the Search
|
// The following tests are temporary, and should be removed when we replace the Search
|
||||||
@@ -276,77 +256,28 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWifiKey_PrioritizedResult() {
|
public void testWifiKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "main_toggle_wifi";
|
final String key = "main_toggle_wifi";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBluetoothKey_PrioritizedResult() {
|
public void testBluetoothKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "main_toggle_bluetooth";
|
final String key = "main_toggle_bluetooth";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAirplaneKey_PrioritizedResult() {
|
public void testAirplaneKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "toggle_airplane";
|
final String key = "toggle_airplane";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
|
||||||
ID, // Doc ID
|
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
@@ -354,156 +285,60 @@ public class CursorToSearchResultConverterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHotspotKey_PrioritizedResult() {
|
public void testHotspotKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "tether_settings";
|
final String key = "tether_settings";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatterySaverKey_PrioritizedResult() {
|
public void testBatterySaverKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "battery_saver";
|
final String key = "battery_saver";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNFCKey_PrioritizedResult() {
|
public void testNFCKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "toggle_nfc";
|
final String key = "toggle_nfc";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataSaverKey_PrioritizedResult() {
|
public void testDataSaverKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "restrict_background";
|
final String key = "restrict_background";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataUsageKey_PrioritizedResult() {
|
public void testDataUsageKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "data_usage_enable";
|
final String key = "data_usage_enable";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRoamingKey_PrioritizedResult() {
|
public void testRoamingKey_PrioritizedResult() {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
|
||||||
final String BLANK = "";
|
|
||||||
final String key = "button_roaming_key";
|
final String key = "button_roaming_key";
|
||||||
|
final Cursor cursor = getDummyCursor(key, WifiSettings.class.getName());
|
||||||
cursor.addRow(new Object[]{
|
final List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor,
|
||||||
ID, // Doc ID
|
BASE_RANK);
|
||||||
TITLES[0], // Title
|
|
||||||
SUMMARY, // Summary on
|
|
||||||
SUMMARY, // summary off
|
|
||||||
WifiSettings.class.getName(), // ClassName
|
|
||||||
BLANK, // screen title
|
|
||||||
null, // icon
|
|
||||||
BLANK, // action
|
|
||||||
null, // target package
|
|
||||||
BLANK, // target class
|
|
||||||
key, // Key
|
|
||||||
0, // Payload Type
|
|
||||||
null // Payload
|
|
||||||
});
|
|
||||||
List<SearchResult> results = mConverter.convertCursor(mSiteMapManager, cursor, BASE_RANK);
|
|
||||||
|
|
||||||
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
assertThat(results.get(0).rank).isEqualTo(SearchResult.TOP_RANK);
|
||||||
}
|
}
|
||||||
@@ -511,28 +346,33 @@ public class CursorToSearchResultConverterTest {
|
|||||||
// End of temporary tests
|
// End of temporary tests
|
||||||
|
|
||||||
private MatrixCursor getDummyCursor() {
|
private MatrixCursor getDummyCursor() {
|
||||||
return getDummyCursor(true /* hasIcon */);
|
return getDummyCursor(true /* hasIcon */, KEY, "" /* className */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MatrixCursor getDummyCursor(boolean hasIcon) {
|
private MatrixCursor getDummyCursor(String key, String className) {
|
||||||
|
return getDummyCursor(false, key, className);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MatrixCursor getDummyCursor(boolean hasIcon, String key, String className) {
|
||||||
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
MatrixCursor cursor = new MatrixCursor(DatabaseResultLoader.SELECT_COLUMNS);
|
||||||
final String BLANK = "";
|
final String BLANK = "";
|
||||||
|
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(INTENT));
|
||||||
|
|
||||||
for (int i = 0; i < EXAMPLES; i++) {
|
for (int i = 0; i < EXAMPLES; i++) {
|
||||||
ArrayList<String> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
|
ArrayList<Object> item = new ArrayList<>(DatabaseResultLoader.SELECT_COLUMNS.length);
|
||||||
item.add(ID + i); // Doc ID
|
item.add(ID + i); // Doc ID
|
||||||
item.add(TITLES[i]); // Title
|
item.add(TITLES[i]); // Title
|
||||||
item.add(SUMMARY); // Summary on
|
item.add(SUMMARY); // Summary on
|
||||||
item.add(BLANK); // summary off
|
item.add(BLANK); // summary off
|
||||||
item.add(BLANK); // classname
|
item.add(className); // classname
|
||||||
item.add(BLANK); // screen title
|
item.add(BLANK); // screen title
|
||||||
item.add(hasIcon ? Integer.toString(ICON) : null); // Icon
|
item.add(hasIcon ? Integer.toString(ICON) : null); // Icon
|
||||||
item.add(INTENT.getAction()); // Intent action
|
item.add(INTENT.getAction()); // Intent action
|
||||||
item.add(BLANK); // target package
|
item.add(TARGET_PACKAGE); // target package
|
||||||
item.add(BLANK); // target class
|
item.add(TARGET_CLASS); // target class
|
||||||
item.add(BLANK); // Key
|
item.add(key); // Key
|
||||||
item.add(Integer.toString(0)); // Payload Type
|
item.add(Integer.toString(0)); // Payload Type
|
||||||
item.add(null); // Payload
|
item.add(payload); // Payload
|
||||||
|
|
||||||
cursor.addRow(item);
|
cursor.addRow(item);
|
||||||
}
|
}
|
||||||
|
@@ -225,7 +225,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload
|
// Payload
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -319,7 +322,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload - should be updated to real payloads as controllers are added
|
// Payload - should be updated to real payloads as controllers are added
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -401,7 +407,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload - should be updated to real payloads as controllers are added
|
// Payload - should be updated to real payloads as controllers are added
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -455,7 +464,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload - should be updated to real payloads as controllers are added
|
// Payload - should be updated to real payloads as controllers are added
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -509,7 +521,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload - should be updated to real payloads as controllers are added
|
// Payload - should be updated to real payloads as controllers are added
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests for the flow: IndexOneResource -> IndexFromProvider -> IndexFromResource ->
|
// Tests for the flow: IndexOneResource -> IndexFromProvider -> IndexFromResource ->
|
||||||
@@ -578,7 +593,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload - should be updated to real payloads as controllers are added
|
// Payload - should be updated to real payloads as controllers are added
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -643,7 +661,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload - should be updated to real payloads as controllers are added
|
// Payload - should be updated to real payloads as controllers are added
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -880,7 +901,10 @@ public class DatabaseIndexingManagerTest {
|
|||||||
// Payload Type - default is 0
|
// Payload Type - default is 0
|
||||||
assertThat(cursor.getInt(19)).isEqualTo(0);
|
assertThat(cursor.getInt(19)).isEqualTo(0);
|
||||||
// Payload
|
// Payload
|
||||||
assertThat(cursor.getBlob(20)).isNull();
|
byte[] payload = cursor.getBlob(20);
|
||||||
|
ResultPayload unmarshalledPayload = ResultPayloadUtils.unmarshall(payload,
|
||||||
|
ResultPayload.CREATOR);
|
||||||
|
assertThat(unmarshalledPayload).isInstanceOf(ResultPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -59,6 +59,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
private SiteMapManager mSiteMapManager;
|
private SiteMapManager mSiteMapManager;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private DatabaseResultLoader loader;
|
private DatabaseResultLoader loader;
|
||||||
|
private ResultPayload mResultPayload;
|
||||||
|
|
||||||
private final String titleOne = "titleOne";
|
private final String titleOne = "titleOne";
|
||||||
private final String titleTwo = "titleTwo";
|
private final String titleTwo = "titleTwo";
|
||||||
@@ -74,6 +75,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mResultPayload = new ResultPayload(new Intent());
|
||||||
FakeFeatureFactory.setupForTest(mMockContext);
|
FakeFeatureFactory.setupForTest(mMockContext);
|
||||||
FakeFeatureFactory factory =
|
FakeFeatureFactory factory =
|
||||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
|
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mMockContext);
|
||||||
@@ -215,12 +217,11 @@ public class DatabaseResultLoaderTest {
|
|||||||
public void testDeDupe_noDuplicates_originalListReturn() {
|
public void testDeDupe_noDuplicates_originalListReturn() {
|
||||||
// Three elements with unique titles and summaries
|
// Three elements with unique titles and summaries
|
||||||
List<SearchResult> results = new ArrayList();
|
List<SearchResult> results = new ArrayList();
|
||||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
|
||||||
|
|
||||||
SearchResult.Builder builder = new SearchResult.Builder();
|
SearchResult.Builder builder = new SearchResult.Builder();
|
||||||
builder.addTitle(titleOne)
|
builder.addTitle(titleOne)
|
||||||
.addSummary(summaryOne)
|
.addSummary(summaryOne)
|
||||||
.addPayload(intentPayload);
|
.addPayload(mResultPayload);
|
||||||
SearchResult resultOne = builder.build();
|
SearchResult resultOne = builder.build();
|
||||||
results.add(resultOne);
|
results.add(resultOne);
|
||||||
|
|
||||||
@@ -245,13 +246,12 @@ public class DatabaseResultLoaderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeDupe_oneDuplicate_duplicateRemoved() {
|
public void testDeDupe_oneDuplicate_duplicateRemoved() {
|
||||||
List<SearchResult> results = new ArrayList();
|
List<SearchResult> results = new ArrayList();
|
||||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
|
||||||
|
|
||||||
SearchResult.Builder builder = new SearchResult.Builder();
|
SearchResult.Builder builder = new SearchResult.Builder();
|
||||||
builder.addTitle(titleOne)
|
builder.addTitle(titleOne)
|
||||||
.addSummary(summaryOne)
|
.addSummary(summaryOne)
|
||||||
.addRank(0)
|
.addRank(0)
|
||||||
.addPayload(intentPayload);
|
.addPayload(mResultPayload);
|
||||||
SearchResult resultOne = builder.build();
|
SearchResult resultOne = builder.build();
|
||||||
results.add(resultOne);
|
results.add(resultOne);
|
||||||
|
|
||||||
@@ -278,9 +278,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeDupe_firstDupeInline_secondDuplicateRemoved() {
|
public void testDeDupe_firstDupeInline_secondDuplicateRemoved() {
|
||||||
List<SearchResult> results = new ArrayList();
|
List<SearchResult> results = new ArrayList();
|
||||||
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0,
|
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0, null, null);
|
||||||
null);
|
|
||||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
|
||||||
|
|
||||||
SearchResult.Builder builder = new SearchResult.Builder();
|
SearchResult.Builder builder = new SearchResult.Builder();
|
||||||
// Inline result
|
// Inline result
|
||||||
@@ -295,7 +293,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
builder.addTitle(titleOne)
|
builder.addTitle(titleOne)
|
||||||
.addSummary(summaryOne)
|
.addSummary(summaryOne)
|
||||||
.addRank(1)
|
.addRank(1)
|
||||||
.addPayload(intentPayload);
|
.addPayload(mResultPayload);
|
||||||
SearchResult resultTwo = builder.build();
|
SearchResult resultTwo = builder.build();
|
||||||
results.add(resultTwo);
|
results.add(resultTwo);
|
||||||
|
|
||||||
@@ -329,23 +327,20 @@ public class DatabaseResultLoaderTest {
|
|||||||
* (1) Intent One
|
* (1) Intent One
|
||||||
*/
|
*/
|
||||||
List<SearchResult> results = new ArrayList();
|
List<SearchResult> results = new ArrayList();
|
||||||
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0,
|
InlineSwitchPayload inlinePayload = new InlineSwitchPayload("", 0, null, null);
|
||||||
null);
|
|
||||||
IntentPayload intentPayload = new IntentPayload(new Intent());
|
|
||||||
|
|
||||||
|
|
||||||
SearchResult.Builder builder = new SearchResult.Builder();
|
SearchResult.Builder builder = new SearchResult.Builder();
|
||||||
// Intent One
|
// Intent One
|
||||||
builder.addTitle(titleOne)
|
builder.addTitle(titleOne)
|
||||||
.addSummary(summaryOne)
|
.addSummary(summaryOne)
|
||||||
.addPayload(intentPayload);
|
.addPayload(mResultPayload);
|
||||||
SearchResult resultOne = builder.build();
|
SearchResult resultOne = builder.build();
|
||||||
results.add(resultOne);
|
results.add(resultOne);
|
||||||
|
|
||||||
// Intent Two
|
// Intent Two
|
||||||
builder.addTitle(titleTwo)
|
builder.addTitle(titleTwo)
|
||||||
.addSummary(summaryTwo)
|
.addSummary(summaryTwo)
|
||||||
.addPayload(intentPayload);
|
.addPayload(mResultPayload);
|
||||||
SearchResult resultTwo = builder.build();
|
SearchResult resultTwo = builder.build();
|
||||||
results.add(resultTwo);
|
results.add(resultTwo);
|
||||||
|
|
||||||
@@ -365,7 +360,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
// Intent Four
|
// Intent Four
|
||||||
builder.addTitle(titleFour)
|
builder.addTitle(titleFour)
|
||||||
.addSummary(summaryOne)
|
.addSummary(summaryOne)
|
||||||
.addPayload(intentPayload);
|
.addPayload(mResultPayload);
|
||||||
SearchResult resultFive = builder.build();
|
SearchResult resultFive = builder.build();
|
||||||
results.add(resultFive);
|
results.add(resultFive);
|
||||||
|
|
||||||
@@ -395,6 +390,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
private void insertSpecialCase(String specialCase) {
|
private void insertSpecialCase(String specialCase) {
|
||||||
String normalized = DatabaseIndexingUtils.normalizeHyphen(specialCase);
|
String normalized = DatabaseIndexingUtils.normalizeHyphen(specialCase);
|
||||||
normalized = DatabaseIndexingUtils.normalizeString(normalized);
|
normalized = DatabaseIndexingUtils.normalizeString(normalized);
|
||||||
|
final ResultPayload payload = new ResultPayload(new Intent());
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, normalized.hashCode());
|
values.put(IndexDatabaseHelper.IndexColumns.DOCID, normalized.hashCode());
|
||||||
@@ -419,12 +415,14 @@ public class DatabaseResultLoaderTest {
|
|||||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, ResultPayloadUtils.marshall(payload));
|
||||||
|
|
||||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpDb() {
|
private void setUpDb() {
|
||||||
|
final byte[] payload = ResultPayloadUtils.marshall(new ResultPayload(new Intent()));
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.DOCID, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, "en-us");
|
||||||
@@ -448,7 +446,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||||
|
|
||||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||||
|
|
||||||
@@ -475,7 +473,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||||
|
|
||||||
values = new ContentValues();
|
values = new ContentValues();
|
||||||
@@ -501,7 +499,7 @@ public class DatabaseResultLoaderTest {
|
|||||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
values.put(IndexDatabaseHelper.IndexColumns.DATA_KEY_REF, "gesture_double_tap_power");
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.USER_ID, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD_TYPE, 0);
|
||||||
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, (String) null);
|
values.put(IndexDatabaseHelper.IndexColumns.PAYLOAD, payload);
|
||||||
|
|
||||||
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
mDb.replaceOrThrow(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, null, values);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -10,32 +10,37 @@
|
|||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License static for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow;
|
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow;
|
||||||
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow.Builder;
|
import com.android.settings.search2.DatabaseIndexingManager.DatabaseRow.Builder;
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import com.android.settings.search2.ResultPayload;
|
|
||||||
import com.android.settings.search2.ResultPayloadUtils;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.Result;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class DatabaseRowTest {
|
public class DatabaseRowTest {
|
||||||
private Builder builder;
|
private Builder mBuilder;
|
||||||
|
|
||||||
private static final String LOCALE = "locale";
|
private static final String LOCALE = "locale";
|
||||||
private static final String UPDATED_TITLE = "updated title";
|
private static final String UPDATED_TITLE = "updated title";
|
||||||
@@ -46,7 +51,7 @@ public class DatabaseRowTest {
|
|||||||
private static final String NORMALIZED_SUMMARY_OFF = "normalized summary off";
|
private static final String NORMALIZED_SUMMARY_OFF = "normalized summary off";
|
||||||
private static final String ENTRIES = "entries";
|
private static final String ENTRIES = "entries";
|
||||||
private static final String CLASS_NAME = "class name";
|
private static final String CLASS_NAME = "class name";
|
||||||
private static final String SCREEN_TITLE = "sceen title";
|
private static final String SCREEN_TITLE = "screen title";
|
||||||
private static final int ICON_RES_ID = 0xff;
|
private static final int ICON_RES_ID = 0xff;
|
||||||
private static final int RANK = 1;
|
private static final int RANK = 1;
|
||||||
private static final String SPACE_DELIMITED_KEYWORDS = "keywords";
|
private static final String SPACE_DELIMITED_KEYWORDS = "keywords";
|
||||||
@@ -56,28 +61,23 @@ public class DatabaseRowTest {
|
|||||||
private static final boolean ENABLED = true;
|
private static final boolean ENABLED = true;
|
||||||
private static final String KEY = "key";
|
private static final String KEY = "key";
|
||||||
private static final int USER_ID = 1;
|
private static final int USER_ID = 1;
|
||||||
private static IntentPayload intentPayload;
|
|
||||||
|
|
||||||
private final String EXTRA_KEY = "key";
|
private Context mContext;
|
||||||
private final String EXTRA_VALUE = "value";
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Intent intent = new Intent();
|
mContext = RuntimeEnvironment.application;
|
||||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
mBuilder = createBuilder();
|
||||||
intentPayload = new IntentPayload(intent);
|
|
||||||
|
|
||||||
builder = new DatabaseRow.Builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFullRowBuild_NonNull() {
|
public void testFullRowBuild_nonNull() {
|
||||||
DatabaseRow row = generateRow();
|
DatabaseRow row = generateRow();
|
||||||
assertThat(row).isNotNull();
|
assertThat(row).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrimativesBuild_NoDataLoss() {
|
public void testPrimitivesBuild_noDataLoss() {
|
||||||
DatabaseRow row = generateRow();
|
DatabaseRow row = generateRow();
|
||||||
|
|
||||||
assertThat(row.locale).isEqualTo(LOCALE);
|
assertThat(row.locale).isEqualTo(LOCALE);
|
||||||
@@ -100,30 +100,61 @@ public class DatabaseRowTest {
|
|||||||
assertThat(row.userId).isEqualTo(USER_ID);
|
assertThat(row.userId).isEqualTo(USER_ID);
|
||||||
assertThat(row.key).isEqualTo(KEY);
|
assertThat(row.key).isEqualTo(KEY);
|
||||||
assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INTENT);
|
assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INTENT);
|
||||||
|
assertThat(row.payload).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPayload_PayloadTypeAdded() {
|
public void testGenericIntent_addedToPayload() {
|
||||||
DatabaseRow row = generateRow();
|
final DatabaseRow row = generateRow();
|
||||||
byte[] marshalledPayload = row.payload;
|
final ResultPayload payload = ResultPayloadUtils.unmarshall(row.payload,
|
||||||
IntentPayload payload = ResultPayloadUtils.unmarshall(marshalledPayload,
|
ResultPayload.CREATOR);
|
||||||
IntentPayload.CREATOR);
|
final ComponentName name = payload.getIntent().getComponent();
|
||||||
|
assertThat(name.getClassName()).isEqualTo(INTENT_TARGET_CLASS);
|
||||||
Intent intent = payload.intent;
|
assertThat(name.getPackageName()).isEqualTo(INTENT_TARGET_PACKAGE);
|
||||||
assertThat(intent.getExtra(EXTRA_KEY)).isEqualTo(EXTRA_VALUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestNullPayload_NoCrash() {
|
public void testRowWithInlinePayload_genericPayloadNotAdded() {
|
||||||
Builder builder = new Builder();
|
final String URI = "test uri";
|
||||||
builder.setPayload(null);
|
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0,
|
||||||
DatabaseRow row = builder.build();
|
new HashMap<Integer, Boolean>(), null);
|
||||||
|
mBuilder.setPayload(payload);
|
||||||
|
final DatabaseRow row = generateRow();
|
||||||
|
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
||||||
|
.unmarshall(row.payload, InlineSwitchPayload.CREATOR);
|
||||||
|
|
||||||
assertThat(row.payload).isNull();
|
assertThat(row.payloadType).isEqualTo(ResultPayload.PayloadType.INLINE_SWITCH);
|
||||||
|
assertThat(unmarshalledPayload.settingsUri).isEqualTo(URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRowWithInlinePayload_intentAddedToInlinePayload() {
|
||||||
|
final String URI = "test uri";
|
||||||
|
final ComponentName component = new ComponentName(INTENT_TARGET_PACKAGE,
|
||||||
|
INTENT_TARGET_CLASS);
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.setComponent(component);
|
||||||
|
|
||||||
|
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0,
|
||||||
|
new HashMap<Integer, Boolean>(), intent);
|
||||||
|
mBuilder.setPayload(payload);
|
||||||
|
final DatabaseRow row = generateRow();
|
||||||
|
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
||||||
|
.unmarshall(row.payload, InlineSwitchPayload.CREATOR);
|
||||||
|
final ComponentName name = unmarshalledPayload.getIntent().getComponent();
|
||||||
|
|
||||||
|
assertThat(name.getClassName()).isEqualTo(INTENT_TARGET_CLASS);
|
||||||
|
assertThat(name.getPackageName()).isEqualTo(INTENT_TARGET_PACKAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private DatabaseRow generateRow() {
|
private DatabaseRow generateRow() {
|
||||||
builder.setLocale(LOCALE)
|
return mBuilder.build(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DatabaseRow.Builder createBuilder() {
|
||||||
|
mBuilder = new DatabaseRow.Builder();
|
||||||
|
mBuilder.setLocale(LOCALE)
|
||||||
.setUpdatedTitle(UPDATED_TITLE)
|
.setUpdatedTitle(UPDATED_TITLE)
|
||||||
.setNormalizedTitle(NORMALIZED_TITLE)
|
.setNormalizedTitle(NORMALIZED_TITLE)
|
||||||
.setUpdatedSummaryOn(UPDATED_SUMMARY_ON)
|
.setUpdatedSummaryOn(UPDATED_SUMMARY_ON)
|
||||||
@@ -141,10 +172,7 @@ public class DatabaseRowTest {
|
|||||||
.setIntentTargetClass(INTENT_TARGET_CLASS)
|
.setIntentTargetClass(INTENT_TARGET_CLASS)
|
||||||
.setEnabled(ENABLED)
|
.setEnabled(ENABLED)
|
||||||
.setKey(KEY)
|
.setKey(KEY)
|
||||||
.setUserId(USER_ID)
|
.setUserId(USER_ID);
|
||||||
.setPayload(intentPayload);
|
return mBuilder;
|
||||||
|
|
||||||
return(builder.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -29,10 +29,6 @@ import com.android.internal.logging.nano.MetricsProto;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import com.android.settings.search2.IntentSearchViewHolder;
|
|
||||||
import com.android.settings.search2.SearchFragment;
|
|
||||||
import com.android.settings.search2.SearchResult;
|
|
||||||
import com.android.settings.search2.SearchResult.Builder;
|
import com.android.settings.search2.SearchResult.Builder;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
@@ -105,7 +101,7 @@ public class IntentSearchViewHolderTest {
|
|||||||
verify(mFragment).startActivity(any(Intent.class));
|
verify(mFragment).startActivity(any(Intent.class));
|
||||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||||
eq(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT),
|
eq(MetricsProto.MetricsEvent.ACTION_CLICK_SETTINGS_SEARCH_RESULT),
|
||||||
eq(((IntentPayload)result.payload).intent.getComponent().flattenToString()),
|
eq(((ResultPayload)result.payload).getIntent().getComponent().flattenToString()),
|
||||||
any(Pair.class));
|
any(Pair.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +109,7 @@ public class IntentSearchViewHolderTest {
|
|||||||
public void testBindViewElements_emptySummary_hideSummaryView() {
|
public void testBindViewElements_emptySummary_hideSummaryView() {
|
||||||
final SearchResult result = new Builder().addTitle(TITLE)
|
final SearchResult result = new Builder().addTitle(TITLE)
|
||||||
.addRank(1)
|
.addRank(1)
|
||||||
.addPayload(new IntentPayload(null))
|
.addPayload(new ResultPayload(null))
|
||||||
.addIcon(mIcon)
|
.addIcon(mIcon)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -129,7 +125,7 @@ public class IntentSearchViewHolderTest {
|
|||||||
breadcrumbs.add("c");
|
breadcrumbs.add("c");
|
||||||
final SearchResult result = new Builder().addTitle(TITLE)
|
final SearchResult result = new Builder().addTitle(TITLE)
|
||||||
.addRank(1)
|
.addRank(1)
|
||||||
.addPayload(new IntentPayload(null))
|
.addPayload(new ResultPayload(null))
|
||||||
.addBreadcrumbs(breadcrumbs)
|
.addBreadcrumbs(breadcrumbs)
|
||||||
.addIcon(mIcon)
|
.addIcon(mIcon)
|
||||||
.build();
|
.build();
|
||||||
@@ -144,7 +140,7 @@ public class IntentSearchViewHolderTest {
|
|||||||
builder.addTitle(TITLE)
|
builder.addTitle(TITLE)
|
||||||
.addSummary(SUMMARY)
|
.addSummary(SUMMARY)
|
||||||
.addRank(1)
|
.addRank(1)
|
||||||
.addPayload(new IntentPayload(
|
.addPayload(new ResultPayload(
|
||||||
new Intent().setComponent(new ComponentName("pkg", "class"))))
|
new Intent().setComponent(new ComponentName("pkg", "class"))))
|
||||||
.addBreadcrumbs(new ArrayList<>())
|
.addBreadcrumbs(new ArrayList<>())
|
||||||
.addIcon(mIcon);
|
.addIcon(mIcon);
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,13 +15,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@@ -31,8 +30,8 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class IntentPayloadTest {
|
public class ResultPayloadTest {
|
||||||
private IntentPayload mPayload;
|
private ResultPayload mPayload;
|
||||||
|
|
||||||
private final String EXTRA_KEY = "key";
|
private final String EXTRA_KEY = "key";
|
||||||
private final String EXTRA_VALUE = "value";
|
private final String EXTRA_VALUE = "value";
|
||||||
@@ -43,14 +42,14 @@ public class IntentPayloadTest {
|
|||||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
||||||
Parcel parcel = Parcel.obtain();
|
Parcel parcel = Parcel.obtain();
|
||||||
|
|
||||||
mPayload = new IntentPayload(intent);
|
mPayload = new ResultPayload(intent);
|
||||||
mPayload.writeToParcel(parcel, 0);
|
mPayload.writeToParcel(parcel, 0);
|
||||||
// Reset parcel for reading
|
// Reset parcel for reading
|
||||||
parcel.setDataPosition(0);
|
parcel.setDataPosition(0);
|
||||||
IntentPayload newPayload = IntentPayload.CREATOR.createFromParcel(parcel);
|
ResultPayload newPayload = ResultPayload.CREATOR.createFromParcel(parcel);
|
||||||
|
|
||||||
String originalIntentExtra = mPayload.intent.getStringExtra(EXTRA_KEY);
|
String originalIntentExtra = mPayload.getIntent().getStringExtra(EXTRA_KEY);
|
||||||
String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
|
String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
|
||||||
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,28 +15,23 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings.search;
|
package com.android.settings.search2;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.BadParcelableException;
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.search2.IntentPayload;
|
|
||||||
import com.android.settings.search2.ResultPayloadUtils;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import java.io.StreamCorruptedException;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static junit.framework.Assert.fail;
|
import static junit.framework.Assert.fail;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class ResultPayloadUtilsTest {
|
public class ResultPayloadUtilsTest {
|
||||||
private IntentPayload payload;
|
private ResultPayload payload;
|
||||||
|
|
||||||
private final String EXTRA_KEY = "key";
|
private final String EXTRA_KEY = "key";
|
||||||
private final String EXTRA_VALUE = "value";
|
private final String EXTRA_VALUE = "value";
|
||||||
@@ -45,14 +40,14 @@ public class ResultPayloadUtilsTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
intent.putExtra(EXTRA_KEY, EXTRA_VALUE);
|
||||||
payload = new IntentPayload(intent);
|
payload = new ResultPayload(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmarshallBadData_ExceptionThrown() {
|
public void testUnmarshallBadData_ExceptionThrown() {
|
||||||
byte[] badData = "I'm going to fail :)".getBytes();
|
byte[] badData = "I'm going to fail :)".getBytes();
|
||||||
try {
|
try {
|
||||||
ResultPayloadUtils.unmarshall(badData, IntentPayload.CREATOR);
|
ResultPayloadUtils.unmarshall(badData, ResultPayload.CREATOR);
|
||||||
fail("unmarshall should throw exception");
|
fail("unmarshall should throw exception");
|
||||||
} catch ( RuntimeException e) {
|
} catch ( RuntimeException e) {
|
||||||
assertThat(e).isNotNull();
|
assertThat(e).isNotNull();
|
||||||
@@ -60,7 +55,7 @@ public class ResultPayloadUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarshallIntentPayload_NonEmptyArray() {
|
public void testMarshallResultPayload_NonEmptyArray() {
|
||||||
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
|
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
|
||||||
assertThat(marshalledPayload).isNotNull();
|
assertThat(marshalledPayload).isNotNull();
|
||||||
assertThat(marshalledPayload).isNotEmpty();
|
assertThat(marshalledPayload).isNotEmpty();
|
||||||
@@ -69,11 +64,11 @@ public class ResultPayloadUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUnmarshall_PreservedData() {
|
public void testUnmarshall_PreservedData() {
|
||||||
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
|
byte[] marshalledPayload = ResultPayloadUtils.marshall(payload);
|
||||||
IntentPayload newPayload = ResultPayloadUtils.unmarshall(marshalledPayload,
|
ResultPayload newPayload = ResultPayloadUtils.unmarshall(marshalledPayload,
|
||||||
IntentPayload.CREATOR);
|
ResultPayload.CREATOR);
|
||||||
|
|
||||||
String originalIntentExtra = payload.intent.getStringExtra(EXTRA_KEY);
|
String originalIntentExtra = payload.getIntent().getStringExtra(EXTRA_KEY);
|
||||||
String copiedIntentExtra = newPayload.intent.getStringExtra(EXTRA_KEY);
|
String copiedIntentExtra = newPayload.getIntent().getStringExtra(EXTRA_KEY);
|
||||||
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
assertThat(originalIntentExtra).isEqualTo(copiedIntentExtra);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user