After getting the full list from CardContentProvider, at render side (Settings side) we should perform final filtering to filter out those data that are not applicable at that moment. Apart from that, we should also perform slice URI check in this stage to take out invalid slices. Bug: 116063073 Test: robotests Change-Id: Idfa94ec6176a9d9cb3379543e0a23858941af742
68 lines
2.2 KiB
Java
68 lines
2.2 KiB
Java
/*
|
|
* Copyright (C) 2018 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.homepage;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
|
|
import android.content.Context;
|
|
import android.support.test.InstrumentationRegistry;
|
|
import android.support.test.runner.AndroidJUnit4;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@RunWith(AndroidJUnit4.class)
|
|
public class CardContentLoaderTest {
|
|
|
|
private Context mContext;
|
|
private CardContentLoader mCardContentLoader;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
mContext = InstrumentationRegistry.getTargetContext();
|
|
mCardContentLoader = new CardContentLoader(mContext);
|
|
}
|
|
|
|
@Test
|
|
public void filter_twoInvalidCards_shouldReturnOneCard() {
|
|
final String sliceUri1 = "content://com.android.settings.slices/action/flashlight"; //valid
|
|
final String sliceUri2 = "content://com.android.settings.test.slices/action/flashlight";
|
|
final String sliceUri3 = "cotent://com.android.settings.slices/action/flashlight";
|
|
|
|
final List<ContextualCard> cards = new ArrayList<>();
|
|
cards.add(getContextualCard(sliceUri1));
|
|
cards.add(getContextualCard(sliceUri2));
|
|
cards.add(getContextualCard(sliceUri3));
|
|
|
|
final List<ContextualCard> result = mCardContentLoader.filter(cards);
|
|
|
|
assertThat(result).hasSize(1);
|
|
}
|
|
|
|
private ContextualCard getContextualCard(String sliceUri) {
|
|
return new ContextualCard.Builder()
|
|
.setName("test_card")
|
|
.setCardType(ContextualCard.CardType.SLICE)
|
|
.setSliceUri(sliceUri)
|
|
.build();
|
|
}
|
|
}
|