Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 914afbfb authored by Fan Zhang's avatar Fan Zhang
Browse files

Create test for CategoryManager.

- Move SettingsLibTests to tests/integ
- Create a new robotests directory for SettingsLib.
- Add test cases for CategoryManager#backwardCompatCleanupForCategory

Bug: 32382487
Test: make RunSettingsLibRoboTests
Change-Id: I7ef5921ce8c47a3e1e7209be1abc97ea549a2378
parent 31f4c544
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.settingslib.drawer;

import android.content.ComponentName;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
@@ -109,18 +110,21 @@ public class CategoryManager {
            for (DashboardCategory category : mCategories) {
                mCategoryByKeyMap.put(category.key, category);
            }
            backwardCompatCleanupForCategory();
            backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
        }
    }

    private synchronized void backwardCompatCleanupForCategory() {
    @VisibleForTesting
    synchronized void backwardCompatCleanupForCategory(
            Map<Pair<String, String>, Tile> tileByComponentCache,
            Map<String, DashboardCategory> categoryByKeyMap) {
        // A package can use a) CategoryKey, b) old category keys, c) both.
        // Check if a package uses old category key only.
        // If yes, map them to new category key.

        // Build a package name -> tile map first.
        final Map<String, List<Tile>> packageToTileMap = new HashMap<>();
        for (Entry<Pair<String, String>, Tile> tileEntry : mTileByComponentCache.entrySet()) {
        for (Entry<Pair<String, String>, Tile> tileEntry : tileByComponentCache.entrySet()) {
            final String packageName = tileEntry.getKey().first;
            List<Tile> tiles = packageToTileMap.get(packageName);
            if (tiles == null) {
@@ -149,7 +153,11 @@ public class CategoryManager {
                    final String newCategoryKey = CategoryKey.KEY_COMPAT_MAP.get(tile.category);
                    tile.category = newCategoryKey;
                    // move tile to new category.
                    final DashboardCategory newCategory = mCategoryByKeyMap.get(newCategoryKey);
                    DashboardCategory newCategory = categoryByKeyMap.get(newCategoryKey);
                    if (newCategory == null) {
                        newCategory = new DashboardCategory();
                        categoryByKeyMap.put(newCategoryKey, newCategory);
                    }
                    newCategory.tiles.add(tile);
                }
            }
+3 −18
Original line number Diff line number Diff line
# Copyright (C) 2015 The Android Open Source Project
# 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.
@@ -15,20 +15,5 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := tests
LOCAL_CERTIFICATE := platform

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_JAVA_LIBRARIES := android.test.runner telephony-common

LOCAL_PACKAGE_NAME := SettingsLibTests

LOCAL_STATIC_JAVA_LIBRARIES := \
    android-support-test \
    espresso-core \
    mockito-target-minus-junit4

include frameworks/base/packages/SettingsLib/common.mk

include $(BUILD_PACKAGE)
# Include all makefiles in subdirectories
include $(call all-makefiles-under,$(LOCAL_PATH))
+34 −0
Original line number Diff line number Diff line
# Copyright (C) 2015 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.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := tests
LOCAL_CERTIFICATE := platform

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_JAVA_LIBRARIES := android.test.runner telephony-common

LOCAL_PACKAGE_NAME := SettingsLibTests

LOCAL_STATIC_JAVA_LIBRARIES := \
    android-support-test \
    espresso-core \
    mockito-target-minus-junit4

include frameworks/base/packages/SettingsLib/common.mk

include $(BUILD_PACKAGE)
Loading