DatabaseIndexingManagerTest.java revision 015a50bef99a23a8c795486b99021a5784d65d64
11dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze/*
21dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * Copyright (C) 2016 The Android Open Source Project
31dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze *
41dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * Licensed under the Apache License, Version 2.0 (the "License");
51dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * you may not use this file except in compliance with the License.
61dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * You may obtain a copy of the License at
71dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze *
81dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze *      http://www.apache.org/licenses/LICENSE-2.0
91dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze *
101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * Unless required by applicable law or agreed to in writing, software
111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * distributed under the License is distributed on an "AS IS" BASIS,
121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * See the License for the specific language governing permissions and
141dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * limitations under the License.
151dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze *
161dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze */
171dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
181dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzepackage com.android.settings.search;
191dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
201dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport android.content.Context;
211dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport android.database.Cursor;
221dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport android.database.sqlite.SQLiteDatabase;
231dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport android.provider.SearchIndexableResource;
24a8b089db8a6d495a18dc3ad91d3bd84b042fb004Fan Zhang
251dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport com.android.settings.R;
261dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport com.android.settings.SettingsRobolectricTestRunner;
271dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport com.android.settings.TestConfig;
28a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhangimport com.android.settings.search.IndexDatabaseHelper.SiteMapColumns;
291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport com.android.settings.search2.DatabaseIndexingManager;
30a8b089db8a6d495a18dc3ad91d3bd84b042fb004Fan Zhangimport com.android.settings.testutils.DatabaseTestUtils;
311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport org.junit.After;
331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport org.junit.Before;
341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport org.junit.Test;
351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport org.junit.runner.RunWith;
361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport org.robolectric.annotation.Config;
371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport org.robolectric.shadows.ShadowApplication;
381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport java.util.ArrayList;
401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport java.util.Arrays;
411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport java.util.HashMap;
421dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport java.util.List;
431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport java.util.Locale;
443f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritzeimport java.util.Map;
451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
46a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhangimport static com.android.settings.dashboard.SiteMapManager.SITE_MAP_COLUMNS;
471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport static com.google.common.truth.Truth.assertThat;
481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport static org.mockito.Mockito.spy;
491dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze@RunWith(SettingsRobolectricTestRunner.class)
511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzepublic class DatabaseIndexingManagerTest {
531dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String localeStr = "en_US";
541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
553f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    private final int rank = 8;
561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String title = "title\u2011title";
571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String updatedTitle = "title-title";
581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String normalizedTitle = "titletitle";
591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String summaryOn = "summary\u2011on";
601dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String updatedSummaryOn = "summary-on";
611dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String normalizedSummaryOn = "summaryon";
621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String summaryOff = "summary\u2011off";
63a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang    private final String updatedSummaryOff = "summary-off";
641dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String normalizedSummaryOff = "summaryoff";
651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String entries = "entries";
661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String keywords = "keywords, keywordss, keywordsss";
671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String spaceDelimittedKeywords = "keywords keywordss keywordsss";
681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String screenTitle = "screen title";
691dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String className = "class name";
701dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final int iconResId = 0xff;
711dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String action = "action";
721dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String targetPackage = "target package";
731dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String targetClass = "target class";
741dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String packageName = "package name";
751dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final String key = "key";
761dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final int userId = -1;
771dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private final boolean enabled = true;
781dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
791dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private Context mContext;
801dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private DatabaseIndexingManager mManager;
811dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private SQLiteDatabase mDb;
821dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
831dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Before
841dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void setUp() {
851dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mContext = ShadowApplication.getInstance().getApplicationContext();
861dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager = spy(new DatabaseIndexingManager(mContext, mContext.getPackageName()));
871dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mDb = IndexDatabaseHelper.getInstance(mContext).getWritableDatabase();
881dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
891dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
901dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @After
911dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void cleanUp() {
92a8b089db8a6d495a18dc3ad91d3bd84b042fb004Fan Zhang        DatabaseTestUtils.clearDb();
931dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
941dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
951dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
961dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testDatabaseSchema() {
971dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor dbCursor = mDb.query("prefs_index", null, null, null, null, null, null);
981dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        List<String> columnNames = new ArrayList<>(Arrays.asList(dbCursor.getColumnNames()));
991dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Note that docid is not included.
100a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang        List<String> expColumnNames = new ArrayList<>(Arrays.asList(new String[]{
1011dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "locale",
1021dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_rank",
1031dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_title",
1041dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_title_normalized",
1051dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_summary_on",
1061dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_summary_on_normalized",
1071dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_summary_off",
1081dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_summary_off_normalized",
1091dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_entries",
1101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_keywords",
1111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "class_name",
1121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "screen_title",
1131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "intent_action",
1141dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "intent_target_package",
1151dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "intent_target_class",
1161dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "icon",
1171dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "enabled",
1181dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "data_key_reference",
1191dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "user_id",
1201dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "payload_type",
1211dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                "payload"
1221dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        }));
1231dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Prevent database schema regressions
1241dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(columnNames).containsAllIn(expColumnNames);
1251dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
1261dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1271dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    // Tests for the flow: IndexOneRaw -> UpdateOneRowWithFilteredData -> UpdateOneRow
1281dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
1301dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testInsertRawColumn_RowInserted() {
1311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableRaw raw = getFakeRaw();
1321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, raw, null /* Non-indexable keys */);
1331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
1341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(1);
1351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
1361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
1381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testInsertRawColumn_RowMatches() {
1391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableRaw raw = getFakeRaw();
1401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, raw, null /* Non-indexable keys */);
1411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
1421dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        cursor.moveToPosition(0);
1431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1441dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
1451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
1461dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
1471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(raw.rank);
1481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
1491dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(2)).isEqualTo(updatedTitle);
1501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
1511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(3)).isEqualTo(normalizedTitle);
1521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
1531dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(4)).isEqualTo(updatedSummaryOn);
1541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
1551dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(5)).isEqualTo(normalizedSummaryOn);
1561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off
1571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEqualTo(updatedSummaryOff);
1581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary off normalized
1591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEqualTo(normalizedSummaryOff);
1601dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries
1611dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isEqualTo(raw.entries);
1621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
1631dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(9)).isEqualTo(spaceDelimittedKeywords);
1641dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
1651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(10)).isEqualTo(raw.screenTitle);
1661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
1671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11)).isEqualTo(raw.className);
1681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
1691dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(raw.iconResId);
1701dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
1711dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isEqualTo(raw.intentAction);
1721dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
1731dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isEqualTo(raw.intentTargetPackage);
1741dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
1751dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isEqualTo(raw.intentTargetClass);
1761dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
1771dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(raw.enabled);
1781dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
1791dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isNotNull();
1801dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
1811dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(raw.userId);
1821dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
1831dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
1841dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload
1851dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
1861dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
1871dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1881dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
1891dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testInsertRawColumnMismatchedLocale_NoRowInserted() {
1901dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableRaw raw = getFakeRaw("ca-fr");
1911dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, raw, null /* Non-indexable keys */);
1921dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
1931dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(0);
1941dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
1951dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1961dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    // Tests for the flow: IndexOneResource -> IndexFromResource ->
1971dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    //                     UpdateOneRowWithFilteredData -> UpdateOneRow
1981dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
1991dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
2001dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testNullResource_NothingInserted() {
2011dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, null /* searchIndexableResource */,
202248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
2031dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
2041dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(0);
2051dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
2061dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
2071dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
2081dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testAddResource_RowsInserted() {
2091dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
2101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
211248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
2121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
2131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(6);
2141dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
2151dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
2161dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
2173f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    public void testAddResourceWithNIKs_RowsInsertedDisabled() {
2183f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
2193f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        // Only add 2 of 6 items to be disabled.
2203f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        String[] keys = {"gesture_double_tap_power", "gesture_swipe_down_fingerprint"};
2213f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        Map<String, List<String>> niks = getNonIndexableKeys(keys);
2223f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource, niks);
2233f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze
2243f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 0", null);
2253f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(2);
2263f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 1", null);
2273f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(4);
2283f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    }
2293f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze
2303f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    @Test
2311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testAddResourceHeader_RowsMatch() {
2321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.application_settings);
2331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
234248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
2351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
2361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
2371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        cursor.moveToPosition(1);
2381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
2391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
2401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
2411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
2421dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(rank);
2431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
244015a50bef99a23a8c795486b99021a5784d65d64Doris Ling        assertThat(cursor.getString(2)).isEqualTo("App info");
2451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
246015a50bef99a23a8c795486b99021a5784d65d64Doris Ling        assertThat(cursor.getString(3)).isEqualTo("app info");
2471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
2481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(4)).isEqualTo("Manage apps, set up quick launch shortcuts");
2491dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
2501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(5)).isEqualTo("manage apps, set up quick launch shortcuts");
2511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off - only on for checkbox preferences
2521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEmpty();
2531dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary off normalized - only on for checkbox preferences
2541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEmpty();
2551dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries - only on for list preferences
2561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isNull();
2571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
2581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(9)).isEmpty();
2591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
260015a50bef99a23a8c795486b99021a5784d65d64Doris Ling        assertThat(cursor.getString(10)).isEqualTo("App info");
2611dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
2621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11)).isEqualTo(className);
2631dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
2641dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(iconResId);
2651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
2661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isEqualTo(action);
2671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
2681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isEqualTo(targetPackage);
2691dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
2701dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isEqualTo(targetClass);
2711dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
2721dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(enabled);
2731dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
2741dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isEqualTo("applications_settings");
2751dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
2761dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(userId);
2771dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
2781dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
2791dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload - should be updated to real payloads as controllers are added
2801dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
2811dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
2821dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
2831dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
284a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang    public void testAddResourceWithChildFragment_shouldUpdateSiteMapDb() {
285f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam        // FIXME: This test was failing. (count = 6 at the end)
286f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam
287f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        SearchIndexableResource resource = getFakeResource(R.xml.network_and_internet);
288f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
289f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//                new HashMap<>());
290f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        Cursor query = mDb.query(IndexDatabaseHelper.Tables.TABLE_SITE_MAP, SITE_MAP_COLUMNS,
291f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//                null, null, null, null, null);
292f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        query.moveToPosition(-1);
293f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        int count = 0;
294f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        while (query.moveToNext()) {
295f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//            count++;
296f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//            assertThat(query.getString(query.getColumnIndex(SiteMapColumns.PARENT_CLASS)))
297f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//                    .isEqualTo(className);
298f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//            assertThat(query.getString(query.getColumnIndex(SiteMapColumns.PARENT_TITLE)))
299f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//                    .isEqualTo(mContext.getString(R.string.network_dashboard_title));
300f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//            assertThat(query.getString(query.getColumnIndex(SiteMapColumns.CHILD_CLASS)))
301f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//                    .isNotEmpty();
302f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//            assertThat(query.getString(query.getColumnIndex(SiteMapColumns.CHILD_TITLE)))
303f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//                    .isNotEmpty();
304f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        }
305f04ff76af05823619f1c522f22d8193edbb56bfaMaurice Lam//        assertThat(count).isEqualTo(5);
306a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang    }
307a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang
308a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang    @Test
3091dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testAddResourceCustomSetting_RowsMatch() {
3101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
3111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
312248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
313248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        final String prefTitle =
314248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                mContext.getString(R.string.fingerprint_swipe_for_notifications_title);
315248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        final String prefSummary =
316248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                mContext.getString(R.string.fingerprint_swipe_for_notifications_summary);
317248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        Cursor cursor = mDb.rawQuery(
318248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                "SELECT * FROM prefs_index where data_title='" + prefTitle + "'", null);
319248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        cursor.moveToFirst();
3201dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
3211dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
3221dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
3231dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
3241dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(rank);
3251dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
326248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        assertThat(cursor.getString(2)).isEqualTo(prefTitle);
3271dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
328248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        assertThat(cursor.getString(3)).isEqualTo(prefTitle.toLowerCase());
3291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
330248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        assertThat(cursor.getString(4)).isEqualTo(prefSummary);
3311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
332248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        assertThat(cursor.getString(5)).isEqualTo(prefSummary.toLowerCase());
3331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off - only on for checkbox preferences
3341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEmpty();
3351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary off normalized - only on for checkbox preferences
3361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEmpty();
3371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries - only on for list preferences
3381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isNull();
3391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
3401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(9)).isEmpty();
3411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
342248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang        assertThat(cursor.getString(10)).isEqualTo(
343248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                mContext.getString(R.string.gesture_preference_title));
3441dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
3451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11)).isEqualTo(className);
3461dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
3471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(iconResId);
3481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
3491dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isEqualTo(action);
3501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
3511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isEqualTo(targetPackage);
3521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
3531dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isEqualTo(targetClass);
3541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
3551dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(enabled);
3561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
3571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isEqualTo("gesture_swipe_down_fingerprint");
3581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
3591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(userId);
3601dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
3611dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
3621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload - should be updated to real payloads as controllers are added
3631dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
3641dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
3651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
3661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
3671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testAddResourceCheckboxPreference_RowsMatch() {
3681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.application_settings);
3691dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
370248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
3711dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
3721dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        /* Should return 6 results, with the following titles:
3731dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze         * Advanced Settings, Apps, Manage Apps, Preferred install location, Running Services
3741dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze         */
3751dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
3761dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        cursor.moveToPosition(0);
3771dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
3781dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
3791dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
3801dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(rank);
3811dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
3821dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(2)).isEqualTo("Advanced settings");
3831dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
3841dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(3)).isEqualTo("advanced settings");
3851dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
3861dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(4)).isEqualTo("Enable more settings options");
3871dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
3881dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(5)).isEqualTo("enable more settings options");
3891dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off
3901dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEqualTo("Enable more settings options");
3911dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off
3921dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEqualTo("enable more settings options");
3931dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries - only on for list preferences
3941dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isNull();
3951dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
3961dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(9)).isEmpty();
3971dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
398015a50bef99a23a8c795486b99021a5784d65d64Doris Ling        assertThat(cursor.getString(10)).isEqualTo("App info");
3991dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
4001dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11)).isEqualTo(className);
4011dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
4021dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(iconResId);
4031dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
4041dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isEqualTo(action);
4051dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
4061dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isEqualTo(targetPackage);
4071dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
4081dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isEqualTo(targetClass);
4091dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
4101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(enabled);
4111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
4121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isEqualTo("toggle_advanced_settings");
4131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
4141dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(userId);
4151dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
4161dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
4171dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload - should be updated to real payloads as controllers are added
4181dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
4191dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
4201dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4211dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
4221dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testAddResourceListPreference_RowsMatch() {
4231dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.application_settings);
4241dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
425248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
4261dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4271dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
4281dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        cursor.moveToPosition(3);
4291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
4301dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
4311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
4321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(rank);
4331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
4341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(2)).isEqualTo("Preferred install location");
4351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
4361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(3)).isEqualTo("preferred install location");
4371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
438a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang        assertThat(cursor.getString(4)).isEqualTo(
439a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang                "Change the preferred installation location for new apps");
4401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
441a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang        assertThat(cursor.getString(5)).isEqualTo(
442a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang                "change the preferred installation location for new apps");
4431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off - only on for checkbox preferences
4441dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEmpty();
4451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary off normalized - only on for checkbox preferences
4461dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEmpty();
4471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries - only on for list preferences
4481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isEqualTo("Internal device storage|Removable SD card|" +
449a96b11f65d9f29dd4037da85e12f5cf9dcfa0176Fan Zhang                "Let the system decide|");
4501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
4511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(9)).isEmpty();
4521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
453015a50bef99a23a8c795486b99021a5784d65d64Doris Ling        assertThat(cursor.getString(10)).isEqualTo("App info");
4541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
4551dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11)).isEqualTo(className);
4561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
4571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(iconResId);
4581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
4591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isEqualTo(action);
4601dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
4611dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isEqualTo(targetPackage);
4621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
4631dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isEqualTo(targetClass);
4641dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
4651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(enabled);
4661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
4671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isEqualTo("app_install_location");
4681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
4691dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(userId);
4701dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
4711dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
4721dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload - should be updated to real payloads as controllers are added
4731dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
4741dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
4751dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4761dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    // Tests for the flow: IndexOneResource -> IndexFromProvider -> IndexFromResource ->
4771dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    //                     UpdateOneRowWithFilteredData -> UpdateOneRow
4781dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4791dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
4801dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testResourceProvider_RowInserted() {
4811dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
4821dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        resource.xmlResId = 0;
4831dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        resource.className = "com.android.settings.display.ScreenZoomSettings";
4841dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4851dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
486248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
4871dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
4881dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(1);
4891dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
4901dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4911dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
4921dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testResourceProvider_Matches() {
4931dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
4941dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        resource.xmlResId = 0;
4951dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        resource.className = "com.android.settings.display.ScreenZoomSettings";
4961dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
4971dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
498248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
4991dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
5001dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        cursor.moveToPosition(0);
5011dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
5021dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
5031dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
5041dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
5051dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(rank);
5061dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
5071dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(2)).isEqualTo("Display size");
5081dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
5091dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(3)).isEqualTo("display size");
5101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
5111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(4)).isEmpty();
5121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
5131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(5)).isEmpty();
5141dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off - only on for checkbox preferences
5151dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEmpty();
5161dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary off normalized - only on for checkbox preferences
5171dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEmpty();
5181dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries - only on for list preferences
5191dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isNull();
5201dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
5211dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(9)).isEqualTo("display density screen zoom scale scaling");
5221dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
5231dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(10)).isEqualTo("Display size");
5241dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
5251dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11))
5261dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze                .isEqualTo("com.android.settings.display.ScreenZoomSettings");
5271dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
5281dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(iconResId);
5291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
5301dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isNull();
5311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
5321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isNull();
5331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
5341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isNull();
5351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
5361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(enabled);
5371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
5381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isNull();
5391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
5401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(userId);
5411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
5421dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
5431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload - should be updated to real payloads as controllers are added
5441dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
5451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
5461dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
5471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
5481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testResourceProvider_ResourceRowInserted() {
5493f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        SearchIndexableResource resource = getFakeResource(0);
5501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        resource.className = "com.android.settings.LegalSettings";
5511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
5521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
553248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
5541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
5553f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(6);
5561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
5571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
5581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    @Test
5591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    public void testResourceProvider_ResourceRowMatches() {
5603f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        SearchIndexableResource resource = getFakeResource(0);
5613f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        resource.className = "com.android.settings.display.ScreenZoomSettings";
5621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
5631dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
564248d95c61809b253eb16fb1d597ed5e2f83ada78Fan Zhang                new HashMap<>());
5651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
5661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        cursor.moveToPosition(0);
5671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
5681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Locale
5691dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(0)).isEqualTo(localeStr);
5701dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Rank
5711dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(1)).isEqualTo(rank);
5721dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data Title
5733f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getString(2)).isEqualTo("Display size");
5741dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Normalized Title
5753f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getString(3)).isEqualTo("display size");
5761dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On
5771dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(4)).isEmpty();
5781dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary On Normalized
5791dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(5)).isEmpty();
5801dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary Off - only on for checkbox preferences
5811dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(6)).isEmpty();
5821dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Summary off normalized - only on for checkbox preferences
5831dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(7)).isEmpty();
5841dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Entries - only on for list preferences
5851dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(8)).isNull();
5861dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Keywords
5873f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getString(9)).isEqualTo(
5883f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze                "display density screen zoom scale scaling");
5891dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Screen Title
5903f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getString(10)).isEqualTo("Display size");
5911dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Class Name
5921dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(11))
5933f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze                .isEqualTo("com.android.settings.display.ScreenZoomSettings");
5941dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Icon
5951dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(12)).isEqualTo(iconResId);
5961dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Intent Action
5971dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(13)).isNull();
5981dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Package
5991dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(14)).isNull();
6001dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Target Class
6011dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(15)).isNull();
6021dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Enabled
6031dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(16) == 1).isEqualTo(enabled);
6041dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Data ref key
6051dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getString(17)).isNull();
6061dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // User Id
6071dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(18)).isEqualTo(userId);
6081dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload Type - default is 0
6091dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getInt(19)).isEqualTo(0);
6101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        // Payload - should be updated to real payloads as controllers are added
6111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        assertThat(cursor.getBlob(20)).isNull();
6121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
6131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
6143f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    @Test
6153f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    public void testResourceProvider_DisabledResourceRowsInserted() {
6163f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        SearchIndexableResource resource = getFakeResource(0);
6173f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        resource.className = "com.android.settings.LegalSettings";
6183f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze
6193f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
6203f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze                new HashMap<String, List<String>>());
6213f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze
6223f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 1", null);
6233f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(2);
6243f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 0", null);
6253f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        assertThat(cursor.getCount()).isEqualTo(4);
6263f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    }
6273f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze
6281dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    // Util functions
6291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
6301dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private SearchIndexableRaw getFakeRaw() {
6311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        return getFakeRaw(localeStr);
6321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
6331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
6341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private SearchIndexableRaw getFakeRaw(String localeStr) {
6351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableRaw data = new SearchIndexableRaw(mContext);
6361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.locale = new Locale(localeStr);
6371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.rank = rank;
6381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.title = title;
6391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.summaryOn = summaryOn;
6401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.summaryOff = summaryOff;
6411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.entries = entries;
6421dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.keywords = keywords;
6431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.screenTitle = screenTitle;
6441dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.className = className;
6451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.packageName = packageName;
6461dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.iconResId = iconResId;
6471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.intentAction = action;
6481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.intentTargetPackage = targetPackage;
6491dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.intentTargetClass = targetClass;
6501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.key = key;
6511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.userId = userId;
6521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        data.enabled = enabled;
6531dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        return data;
6541dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
6551dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze
6561dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    private SearchIndexableResource getFakeResource(int xml) {
6571dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        SearchIndexableResource sir = new SearchIndexableResource(mContext);
6581dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.rank = rank;
6591dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.xmlResId = xml;
6601dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.className = className;
6611dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.packageName = packageName;
6621dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.iconResId = iconResId;
6631dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.intentAction = action;
6641dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.intentTargetPackage = targetPackage;
6651dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.intentTargetClass = targetClass;
6661dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        sir.enabled = enabled;
6671dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze        return sir;
6681dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze    }
6693f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze
6703f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    private Map<String, List<String>> getNonIndexableKeys(String[] keys) {
6713f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        Map<String, List<String>> niks = new HashMap<>();
6723f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        List<String> keysList = new ArrayList<>(Arrays.asList(keys));
6733f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        niks.put(packageName, keysList);
6743f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze        return niks;
6753f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze    }
6763f3b547e4a2eeeb362d9b7c98b05f9a244cd754eMatthew Fritze}