Merge "Loading suggestions via legacy SuggestionService sometimes"
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
<bool name="config_show_wifi_mac_address">false</bool>
|
||||
<bool name="config_disable_uninstall_update">true</bool>
|
||||
<bool name="config_show_device_name">false</bool>
|
||||
<bool name="config_use_legacy_suggestion">false</bool>
|
||||
|
||||
<!-- Whether or not extra preview panels should be used for screen zoom setting. -->
|
||||
<bool name="config_enable_extra_screen_zoom_preview">false</bool>
|
||||
|
@@ -30,7 +30,7 @@ public class ConditionalContextualCardTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void newInstance_changeCardType_shouldCrash() {
|
||||
new ConditionalContextualCard.Builder()
|
||||
.setCardType(ContextualCard.CardType.SUGGESTION)
|
||||
.setCardType(ContextualCard.CardType.LEGACY_SUGGESTION)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.contextualcards.legacysuggestion;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
import com.android.settingslib.suggestions.SuggestionController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowThreadUtils.class)
|
||||
public class LegacySuggestionContextualCardControllerTest {
|
||||
|
||||
@Mock
|
||||
private SuggestionController mSuggestionController;
|
||||
@Mock
|
||||
private ContextualCardUpdateListener mCardUpdateListener;
|
||||
|
||||
private Context mContext;
|
||||
private LegacySuggestionContextualCardController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new LegacySuggestionContextualCardController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_configOn_shouldCreateSuggestionController() {
|
||||
final LegacySuggestionContextualCardController controller =
|
||||
new LegacySuggestionContextualCardController(mContext);
|
||||
assertThat(controller.mSuggestionController).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void init_configOff_shouldNotCreateSuggestionController() {
|
||||
final LegacySuggestionContextualCardController controller =
|
||||
new LegacySuggestionContextualCardController(mContext);
|
||||
|
||||
assertThat(controller.mSuggestionController).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void goThroughLifecycle_hasSuggestionController_shouldStartStopController() {
|
||||
mController.mSuggestionController = mSuggestionController;
|
||||
mController.onStart();
|
||||
verify(mSuggestionController).start();
|
||||
|
||||
mController.onStop();
|
||||
verify(mSuggestionController).stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onServiceConnected_shouldLoadSuggestion() {
|
||||
mController.mSuggestionController = mSuggestionController;
|
||||
mController.setCardUpdateListener(mCardUpdateListener);
|
||||
mController.onServiceConnected();
|
||||
|
||||
verify(mSuggestionController).getSuggestions();
|
||||
}
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.contextualcards.legacysuggestion;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
import com.android.settings.homepage.contextualcards.ControllerRendererPool;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class LegacySuggestionContextualCardRendererTest {
|
||||
@Mock
|
||||
private ControllerRendererPool mControllerRendererPool;
|
||||
@Mock
|
||||
private LegacySuggestionContextualCardController mController;
|
||||
private Context mContext;
|
||||
private LegacySuggestionContextualCardRenderer mRenderer;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mRenderer = new LegacySuggestionContextualCardRenderer(mContext, mControllerRendererPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindView_shouldSetListener() {
|
||||
final int viewType = mRenderer.getViewType(true /* isHalfWidth */);
|
||||
final RecyclerView recyclerView = new RecyclerView(mContext);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
final View card = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
|
||||
final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(card);
|
||||
|
||||
when(mControllerRendererPool.getController(mContext,
|
||||
ContextualCard.CardType.LEGACY_SUGGESTION)).thenReturn(mController);
|
||||
|
||||
mRenderer.bindView(viewHolder, buildContextualCard());
|
||||
|
||||
assertThat(card).isNotNull();
|
||||
assertThat(card.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewClick_shouldInvokeControllerPrimaryClick() {
|
||||
final int viewType = mRenderer.getViewType(true /* isHalfWidth */);
|
||||
final RecyclerView recyclerView = new RecyclerView(mContext);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
final View card = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
|
||||
final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(card);
|
||||
when(mControllerRendererPool.getController(mContext,
|
||||
ContextualCard.CardType.LEGACY_SUGGESTION)).thenReturn(mController);
|
||||
|
||||
mRenderer.bindView(viewHolder, buildContextualCard());
|
||||
|
||||
assertThat(card).isNotNull();
|
||||
card.performClick();
|
||||
|
||||
verify(mController).onPrimaryClick(any(ContextualCard.class));
|
||||
}
|
||||
|
||||
private ContextualCard buildContextualCard() {
|
||||
return new LegacySuggestionContextualCard.Builder()
|
||||
.setName("test_name")
|
||||
.setTitleText("test_title")
|
||||
.setSummaryText("test_summary")
|
||||
.setIconDrawable(mContext.getDrawable(R.drawable.ic_do_not_disturb_on_24dp))
|
||||
.build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.contextualcards.legacysuggestion;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class LegacySuggestionContextualCardTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void newInstance_changeCardType_shouldCrash() {
|
||||
new LegacySuggestionContextualCard.Builder()
|
||||
.setCardType(ContextualCard.CardType.CONDITIONAL)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCardType_shouldAlwaysBeSuggestionType() {
|
||||
assertThat(new LegacySuggestionContextualCard.Builder().build().getCardType())
|
||||
.isEqualTo(ContextualCard.CardType.LEGACY_SUGGESTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void build_shouldSetPendingIntent() {
|
||||
assertThat(new LegacySuggestionContextualCard.Builder()
|
||||
.setPendingIntent(mock(PendingIntent.class))
|
||||
.build()
|
||||
.getPendingIntent()).isNotNull();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user