Merge "Remove support v1"

This commit is contained in:
TreeHugger Robot
2018-01-08 18:29:18 +00:00
committed by Android (Google) Code Review
24 changed files with 13 additions and 2270 deletions

View File

@@ -17,10 +17,11 @@
package com.android.settings.dashboard;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.SupportItemAdapter.ViewHolder;
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
import org.junit.Test;
@@ -68,4 +69,12 @@ public class DashboardItemAnimatorTest {
.animateChange(mViewHolder, mViewHolder, 0, 1, 0, 1);
assertThat(hasPendingAnimation).isFalse();
}
// Sample viewholder to use for test
static final class ViewHolder extends RecyclerView.ViewHolder {
ViewHolder(View itemView) {
super(itemView);
}
}
}

View File

@@ -1,189 +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.dashboard;
import android.accounts.Account;
import android.app.Activity;
import android.content.Intent;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.dashboard.SupportItemAdapter.EscalationData;
import com.android.settings.overlay.SupportFeatureProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SupportItemAdapterTest {
private static final String ACCOUNT_TYPE = "com.google";
private final Account USER_1 = new Account("user1", ACCOUNT_TYPE);
private final Account USER_2 = new Account("user2", ACCOUNT_TYPE);
private final Account TWO_ACCOUNTS[] = {USER_1, USER_2};
private final Account ONE_ACCOUNT[] = {USER_1};
private final Account ZERO_ACCOUNT[] = {};
private ShadowActivity mShadowActivity;
private Activity mActivity;
private SupportItemAdapter mSupportItemAdapter;
private SupportItemAdapter.ViewHolder mViewHolder;
@Mock
private SupportFeatureProvider mSupportFeatureProvider;
@Mock
private MetricsFeatureProvider mMetricsFeatureProvider;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.setupActivity(Activity.class);
mShadowActivity = shadowOf(mActivity);
final View itemView = LayoutInflater.from(mActivity).inflate(
R.layout.support_escalation_options, null);
mViewHolder = new SupportItemAdapter.ViewHolder(itemView);
// Mock this to prevent crash in testing
when(mSupportFeatureProvider.getAccountLoginIntent()).thenReturn(
new Intent(Settings.ACTION_ADD_ACCOUNT));
}
@Test
public void testBindAccountPicker_TwoAccounts_ShouldHaveTwoAccounts() {
testBindAccountPickerInner(mViewHolder, TWO_ACCOUNTS);
}
@Test
public void testBindAccountPicker_OneAccount_ShouldHaveOneAccount() {
testBindAccountPickerInner(mViewHolder, ONE_ACCOUNT);
}
@Test
public void testOnSpinnerItemClick_AddAccountClicked_AccountLoginIntentInvoked() {
bindAccountPickerInner(mViewHolder, TWO_ACCOUNTS);
final Spinner spinner = (Spinner) mViewHolder.itemView.findViewById(R.id.account_spinner);
spinner.setSelection(TWO_ACCOUNTS.length);
Robolectric.flushForegroundThreadScheduler();
verify(mSupportFeatureProvider).getAccountLoginIntent();
}
@Test
public void testSetAccount_AccountEmpty_NotCrash() {
when(mSupportFeatureProvider.getSupportEligibleAccounts(mActivity)).thenReturn(
ZERO_ACCOUNT);
mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
mMetricsFeatureProvider, null);
// Should not crash in this method
mSupportItemAdapter.setAccounts(ONE_ACCOUNT);
verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
}
@Test
public void testRefreshData_CardUpdatedOnEnteringOrLeavingSupportHours() {
// pretend we have support right now
when(mSupportFeatureProvider.isSupportTypeEnabled(any(), anyInt()))
.thenReturn(true);
when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
when(mSupportFeatureProvider.getSupportEligibleAccounts(any())).thenReturn(ONE_ACCOUNT);
mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
mMetricsFeatureProvider, null);
// If this doesn't return escalation data something has gone wrong
EscalationData data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
// precondition, support is enabled
assertThat(data.enabled1).isTrue();
// pretend we support hours are over
when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(false);
mSupportItemAdapter.refreshData();
data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
assertThat(data.enabled1).isFalse();
// pretend support hours have started again
when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
mSupportItemAdapter.refreshData();
data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
assertThat(data.enabled1).isTrue();
}
/**
* Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
* invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref
* accounts}
*
* @param viewHolder holds the view that contains the spinner to test
* @param accounts holds the accounts info to be showed in spinner.
*/
private void testBindAccountPickerInner(SupportItemAdapter.ViewHolder viewHolder,
Account accounts[]) {
bindAccountPickerInner(viewHolder, accounts);
final Spinner spinner = (Spinner) viewHolder.itemView.findViewById(R.id.account_spinner);
final SpinnerAdapter adapter = spinner.getAdapter();
// Contains "Add account" option, so should be 'count+1'
assertThat(adapter.getCount()).isEqualTo(accounts.length + 1);
for (int i = 0; i < accounts.length; i++) {
assertThat(adapter.getItem(i)).isEqualTo(accounts[i].name);
}
}
/**
* Create {@link SupportItemAdapter} and bind the account picker view into
* {@paramref viewholder}
*
* @param viewHolder holds the view that contains the spinner to test
* @param accounts holds the accounts info to be showed in spinner.
*/
private void bindAccountPickerInner(SupportItemAdapter.ViewHolder viewHolder,
Account accounts[]) {
when(mSupportFeatureProvider.getSupportEligibleAccounts(mActivity)).thenReturn(accounts);
mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
mMetricsFeatureProvider, null);
mSupportItemAdapter.bindAccountPicker(viewHolder);
}
}

View File

@@ -1,119 +0,0 @@
package com.android.settings.support;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.shadow.api.Shadow.directlyOn;
import android.accounts.Account;
import android.annotation.NonNull;
import android.annotation.StringRes;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.text.Spannable;
import android.text.style.URLSpan;
import android.widget.CheckBox;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.overlay.SupportFeatureProvider.SupportType;
import com.android.settings.support.SupportDisclaimerDialogFragmentTest.SupportDisclaimerShadowResources;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {SupportDisclaimerShadowResources.class})
public class SupportDisclaimerDialogFragmentTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
Context mContext;
private FakeFeatureFactory mFakeFeatureFactory;
private MetricsFeatureProvider mMetricsFeatureProvider;
private SupportFeatureProvider mSupportFeatureProvider;
private final Account mFakeAccount = new Account("user1", "fake_type");
private static final int FAKE_RES_ID = -1000;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
mSupportFeatureProvider = mFakeFeatureFactory.getSupportFeatureProvider(mContext);
when(mSupportFeatureProvider.getDisclaimerStringResId())
.thenReturn(FAKE_RES_ID);
}
@Test
public void onClick_DoNotShowCheckedLogsAction() {
SupportDisclaimerDialogFragment fragment =
SupportDisclaimerDialogFragment.newInstance(mFakeAccount, SupportType.CHAT);
FragmentTestUtil.startFragment(fragment);
// pretend the user selected to skip the dialog in the future
CheckBox doNotShow = (CheckBox) fragment.getDialog()
.findViewById(R.id.support_disclaimer_do_not_show_again);
doNotShow.setChecked(true);
// verify we logged the action
fragment.onClick(fragment.getDialog(), Dialog.BUTTON_POSITIVE);
verify(mMetricsFeatureProvider, times(1)).action(any(),
eq(MetricsProto.MetricsEvent.ACTION_SKIP_DISCLAIMER_SELECTED));
}
@Test
public void onClick_DoNotShowUncheckedDoesNotLogAction() {
SupportDisclaimerDialogFragment fragment =
SupportDisclaimerDialogFragment.newInstance(mFakeAccount, SupportType.CHAT);
FragmentTestUtil.startFragment(fragment);
// pretend the user selected to skip the dialog in the future
CheckBox doNotShow = (CheckBox) fragment.getDialog()
.findViewById(R.id.support_disclaimer_do_not_show_again);
doNotShow.setChecked(false);
// verify we logged the action
fragment.onClick(fragment.getDialog(), Dialog.BUTTON_POSITIVE);
verify(mMetricsFeatureProvider, never()).action(any(),
eq(MetricsProto.MetricsEvent.ACTION_SKIP_DISCLAIMER_SELECTED));
}
@Implements(Resources.class)
public static class SupportDisclaimerShadowResources extends SettingsShadowResources {
@Implementation
@NonNull public CharSequence getText(@StringRes int id) throws NotFoundException {
if (id == FAKE_RES_ID) {
Spannable text = Spannable.Factory.getInstance()
.newSpannable("string with url");
text.setSpan(new URLSpan("https://google.com"), 0, 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return text;
}
return directlyOn(realResources, Resources.class).getText(id);
}
}
}