Use new app header in more screens.
- This covers all subclasses of AppInfoWithHeader: app launch settings, app storage settings, draw over settings, write setting details, usage access settings. Bug: 32442716 Test: RunSettingsRoboTests Change-Id: I8e5831a4fcce5f98c3a6cc6b0fd66bc4a53d1330
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.applications;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
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.shadows.ShadowApplication;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AppInfoWithHeaderTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private FakeFeatureFactory mFactory;
|
||||
private TestFragment mAppInfoWithHeader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
|
||||
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
mAppInfoWithHeader = new TestFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppHeaderIsAdded() {
|
||||
when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
||||
when(mFactory.applicationFeatureProvider.newAppHeaderController(mAppInfoWithHeader, null))
|
||||
.thenReturn(new AppHeaderController(
|
||||
ShadowApplication.getInstance().getApplicationContext(),
|
||||
mAppInfoWithHeader,
|
||||
null));
|
||||
mAppInfoWithHeader.onActivityCreated(null);
|
||||
|
||||
verify(mAppInfoWithHeader.mScreen).addPreference(any(LayoutPreference.class));
|
||||
}
|
||||
|
||||
public static class TestFragment extends AppInfoWithHeader {
|
||||
|
||||
PreferenceManager mManager;
|
||||
PreferenceScreen mScreen;
|
||||
|
||||
public TestFragment() {
|
||||
mPm = mock(PackageManager.class);
|
||||
mManager = mock(PreferenceManager.class);
|
||||
mScreen = mock(PreferenceScreen.class);
|
||||
mPackageInfo = new PackageInfo();
|
||||
mPackageInfo.applicationInfo = new ApplicationInfo();
|
||||
|
||||
when(mManager.getContext())
|
||||
.thenReturn(ShadowApplication.getInstance().getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean refreshUi() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AlertDialog createDialog(int id, int errorCode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceScreen getPreferenceScreen() {
|
||||
return mScreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreferenceManager getPreferenceManager() {
|
||||
return mManager;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user