Move AppPreference to settingslib, and change imports.

Bug: 116364655
Test: robotests
Change-Id: I313272737dc7c068c47abf8ea021de7d2bea0a25
This commit is contained in:
Fan Zhang
2018-09-24 12:29:57 -07:00
parent 2a1e59063d
commit 754f737c2c
21 changed files with 37 additions and 281 deletions

View File

@@ -42,10 +42,10 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.AppPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.location.RecentLocationApps.Request;
import com.android.settingslib.widget.apppreference.AppPreference;
import org.junit.Before;
import org.junit.Test;
@@ -173,7 +173,7 @@ public class RecentLocationRequestPreferenceControllerTest {
@Test
public void onPreferenceClick_shouldLaunchAppDetails() {
final Context context= mock(Context.class);
final Context context = mock(Context.class);
when(mFragment.getContext()).thenReturn(context);
final List<RecentLocationApps.Request> requests = new ArrayList<>();
@@ -210,7 +210,7 @@ public class RecentLocationRequestPreferenceControllerTest {
AppPreference appPreference = mock(AppPreference.class, "AppPreference" + i);
doReturn(title).when(appPreference).getTitle();
doReturn(appPreference)
.when(mController).createAppPreference(any(Context.class), eq(req));
.when(mController).createAppPreference(any(Context.class), eq(req));
}
return requests;
}

View File

@@ -32,10 +32,10 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.AppPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.location.RecentLocationApps.Request;
import com.android.settingslib.widget.apppreference.AppPreference;
import org.junit.Before;
import org.junit.Test;

View File

@@ -75,6 +75,8 @@ public class SettingsRobolectricTestRunner extends RobolectricTestRunner {
Fs.fromURL(new URL("file:packages/apps/Settings/res")), null));
paths.add(new ResourcePath(null,
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/res")), null));
paths.add(new ResourcePath(null,
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/AppPreference/res/")), null));
paths.add(new ResourcePath(null,
Fs.fromURL(new URL("file:frameworks/base/packages/SettingsLib/HelpUtils/res/")), null));
paths.add(new ResourcePath(null,

View File

@@ -1,82 +0,0 @@
/*
* Copyright (C) 2017 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.widget;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.view.View;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class AppPreferenceTest {
private Context mContext;
private View mRootView;
private AppPreference mPref;
private PreferenceViewHolder mHolder;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mRootView = View.inflate(mContext, R.layout.preference_app, null /* parent */);
mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
mPref = new AppPreference(mContext);
}
@Test
public void setProgress_showProgress() {
mPref.setProgress(1);
mPref.onBindViewHolder(mHolder);
assertThat(mHolder.findViewById(android.R.id.progress).getVisibility())
.isEqualTo(View.VISIBLE);
}
@Test
public void setSummary_showSummaryContainer() {
mPref.setSummary("test");
mPref.onBindViewHolder(mHolder);
assertThat(mHolder.findViewById(R.id.summary_container).getVisibility())
.isEqualTo(View.VISIBLE);
}
@Test
public void noSummary_hideSummaryContainer() {
mPref.setSummary(null);
mPref.onBindViewHolder(mHolder);
assertThat(mHolder.findViewById(R.id.summary_container).getVisibility())
.isEqualTo(View.GONE);
}
@Test
public void foobar_testName() {
float iconSize = mContext.getResources().getDimension(R.dimen.secondary_app_icon_size);
assertThat(Float.floatToIntBits(iconSize)).isEqualTo(Float.floatToIntBits(32));
}
}