Update SetupChooseLockPatternTest to SDK 26
- create a new ShadowResourcesImpl because sdk 26 calls loadDrawable from ResourcesImpl instead of Resources Test: make RunSettingsRoboTests -j40 Change-Id: I8eed76ea779972c68893d4e7fdfc4493465b9b22
This commit is contained in:
@@ -30,6 +30,7 @@ import com.android.settings.password.ChooseLockPattern.IntentBuilder;
|
||||
import com.android.settings.password.SetupChooseLockPattern;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
|
||||
@@ -44,9 +45,10 @@ import org.robolectric.shadows.ShadowPackageManager.ComponentState;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResourcesImpl.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowUtils.class
|
||||
|
@@ -101,6 +101,13 @@ public class SettingsShadowResources extends ShadowResources {
|
||||
return directlyOn(realResources, Resources.class).getColorStateList(id, theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated because SDK 24+ uses
|
||||
* {@link SettingsShadowResourcesImpl#loadDrawable(Resources, TypedValue, int, int, Theme)}
|
||||
*
|
||||
* TODO: Delete when all tests have been migrated to sdk 26
|
||||
*/
|
||||
@Deprecated
|
||||
@Implementation
|
||||
public Drawable loadDrawable(TypedValue value, int id, Theme theme)
|
||||
throws NotFoundException {
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.testutils.shadow;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.ResourcesImpl;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowResourcesImpl;
|
||||
|
||||
@Implements(
|
||||
value = ResourcesImpl.class,
|
||||
isInAndroidSdk = false,
|
||||
minSdk = 26
|
||||
)
|
||||
public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
|
||||
|
||||
@Implementation
|
||||
public Drawable loadDrawable(Resources wrapper, TypedValue value, int id, int density,
|
||||
Resources.Theme theme) {
|
||||
// The drawable item in switchbar_background.xml refers to a very recent color attribute
|
||||
// that Robolectric isn't yet aware of.
|
||||
// TODO: Remove this once Robolectric is updated.
|
||||
if (id == R.drawable.switchbar_background) {
|
||||
return new ColorDrawable();
|
||||
} else if (id == R.drawable.ic_launcher_settings) {
|
||||
// ic_launcher_settings uses adaptive-icon, which is not supported by robolectric,
|
||||
// change it to a normal drawable.
|
||||
id = R.drawable.ic_settings_wireless;
|
||||
} else if (id == R.drawable.app_filter_spinner_background) {
|
||||
id = R.drawable.ic_expand_more_inverse;
|
||||
} else if (id == R.drawable.selectable_card_grey) {
|
||||
id = R.drawable.ic_expand_more_inverse;
|
||||
}
|
||||
return super.loadDrawable(wrapper, value, id, density, theme);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user