lineage-sdk: Fix LineageSettingsProvider tests
* Fix bp and manifest to work with AndroidJUnitRunner. * Remove broken tests (we no longer intercept in fw/b settings provider and QS_USE_MAIN_TILES was removed). * Tests pass when executed using: adb shell am instrument org.lineageos.lineagesettings.tests/androidx.test.runner.AndroidJUnitRunner (see README.md for more info) Change-Id: I3fcf4885c61106f43e99847293220afee78e2f6a
This commit is contained in:
@@ -22,10 +22,17 @@ android_test {
|
||||
srcs: ["**/*.java"],
|
||||
|
||||
certificate: "platform",
|
||||
libs: ["android.test.runner"],
|
||||
libs: [
|
||||
"android.test.base",
|
||||
"android.test.runner",
|
||||
],
|
||||
optimize: {
|
||||
optimize: true,
|
||||
proguard_flags_files: ["proguard.flags"],
|
||||
},
|
||||
|
||||
static_libs: ["org.lineageos.platform.internal"],
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"org.lineageos.platform.internal",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2015 The CyanogenMod 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.
|
||||
#
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
# Register as LineageTS
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_PACKAGE_NAME := CmtsLineageSettingsProviderTests
|
||||
LOCAL_INSTRUMENTATION_FOR := LineageSettingsProvider
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_CERTIFICATE := platform
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
||||
LOCAL_PROGUARD_ENABLED := optimization
|
||||
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
org.lineageos.platform.internal
|
||||
|
||||
include $(BUILD_LineageTS_PACKAGE)
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
<uses-permission android:name="android.permission.MANAGE_USERS" />
|
||||
|
||||
<instrumentation
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
android:targetPackage="org.lineageos.lineagesettings.tests"
|
||||
android:label="Lineage Settings Provider Tests" />
|
||||
android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="org.lineageos.lineagesettings.tests"
|
||||
android:label="Lineage Settings Provider Tests" />
|
||||
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
The tests package contains coverage for the Lineage Settings provider as well as
|
||||
its public interfaces.
|
||||
|
||||
To run the tests (on a live device):
|
||||
To run the tests (on a live device), build and install LineageSettingsProviderTests.apk
|
||||
and then run:
|
||||
|
||||
```adb shell am instrument -w org.lineageos.lineagesettings.tests/android.test.InstrumentationTestRunner```
|
||||
```adb shell am instrument org.lineageos.lineagesettings.tests/androidx.test.runner.AndroidJUnitRunner```
|
||||
|
||||
Note: we don't use -w to wait for the results because some of the tests involve creating
|
||||
and removing a guest account which causes adb connections to get reset.
|
||||
|
||||
View the results with:
|
||||
|
||||
```adb logcat | grep TestRunner```
|
||||
|
||||
End of the output should read something like:
|
||||
|
||||
```09-20 16:40:52.879 4146 4165 I TestRunner: run finished: 30 tests, 0 failed, 0 ignored```
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
-keep interface org.junit.** { *; }
|
||||
|
||||
# Keep compiled java classes from declared aidl's within the test package
|
||||
-keep public class * extends android.os.IInterface { *; }
|
||||
-keep public class * implements android.os.IInterface { *; }
|
||||
|
||||
# Don't warn about the Android Support Test JUnit Runner
|
||||
-dontwarn androidx.**
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
|
||||
public class LineageSettingsGlobalTests extends AndroidTestCase {
|
||||
|
||||
@@ -23,15 +23,15 @@ import android.content.res.Resources;
|
||||
import android.os.UserHandle;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
import org.lineageos.lineagesettings.LineageDatabaseHelper;
|
||||
import org.lineageos.lineagesettings.LineageSettingsProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by adnan on 1/25/16.
|
||||
*/
|
||||
@@ -87,9 +87,6 @@ public class LineageSettingsProviderDefaultsTest extends AndroidTestCase {
|
||||
SECURE_SETTINGS_DEFAULTS.add(new Setting(
|
||||
LineageSettings.Secure.ADVANCED_MODE,
|
||||
"R.bool.def_advanced_mode"));
|
||||
SECURE_SETTINGS_DEFAULTS.add(new Setting(
|
||||
LineageSettings.Secure.QS_USE_MAIN_TILES,
|
||||
"R.bool.def_sysui_qs_main_tiles"));
|
||||
SECURE_SETTINGS_DEFAULTS.add(new Setting(
|
||||
LineageSettings.Secure.STATS_COLLECTION,
|
||||
"R.bool.def_stats_collection"));
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -76,45 +77,6 @@ import java.util.Map;
|
||||
testMigrateSettingsForUser(mGuest.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* make sure that queries to SettingsProvider are forwarded to LineageSettingsProvider as needed
|
||||
* See {@link lineageos.providers.LineageSettings.System#shouldInterceptSystemProvider(String)}
|
||||
*
|
||||
* Currently this test only checks that
|
||||
* {@link lineageos.providers.LineageSettings.System#SYSTEM_PROFILES_ENABLED} is expected to
|
||||
* be forwarded, and is forwarded.
|
||||
*/
|
||||
@SmallTest
|
||||
public void testSettingsProviderKeyForwarding() {
|
||||
String forwardedKey = LineageSettings.System.SYSTEM_PROFILES_ENABLED;
|
||||
|
||||
// make sure the key should be forwarded
|
||||
assertTrue(LineageSettings.System.shouldInterceptSystemProvider(forwardedKey));
|
||||
|
||||
// put value 1 into Settings provider:
|
||||
// let's try to disable the profiles via the Settings provider
|
||||
Settings.System.putStringForUser(mContentResolver,
|
||||
forwardedKey, "0", UserHandle.USER_CURRENT);
|
||||
|
||||
// assert this is what we just put in there
|
||||
assertEquals("0", Settings.System.getStringForUser(getContext().getContentResolver(),
|
||||
forwardedKey, UserHandle.USER_CURRENT));
|
||||
|
||||
// put value 2 into LineageSettings provider
|
||||
LineageSettings.System.putStringForUser(mContentResolver,
|
||||
forwardedKey, "1", UserHandle.USER_CURRENT);
|
||||
|
||||
assertEquals("1", LineageSettings.System.getStringForUser(getContext().getContentResolver(),
|
||||
forwardedKey, UserHandle.USER_CURRENT));
|
||||
|
||||
// assert reading from both returns value 2
|
||||
final String lineageProviderValue = LineageSettings.System.getStringForUser(
|
||||
getContext().getContentResolver(), forwardedKey, UserHandle.USER_CURRENT);
|
||||
final String settingsProviderValue = Settings.System.getStringForUser(
|
||||
getContext().getContentResolver(), forwardedKey, UserHandle.USER_CURRENT);
|
||||
assertEquals(lineageProviderValue, settingsProviderValue);
|
||||
}
|
||||
|
||||
private void testMigrateSettingsForUser(int userId) {
|
||||
// Setup values in Settings
|
||||
/*final String expectedPullDownValue = "testQuickPullDownValue";
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
|
||||
public class LineageSettingsSecureTests extends AndroidTestCase {
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import lineageos.providers.LineageSettings;
|
||||
|
||||
public class LineageSettingsSystemTests extends AndroidTestCase {
|
||||
|
||||
@@ -2174,18 +2174,6 @@ public final class LineageSettings {
|
||||
return ArrayUtils.contains(LEGACY_SYSTEM_SETTINGS, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static boolean shouldInterceptSystemProvider(String key) {
|
||||
switch (key) {
|
||||
case System.SYSTEM_PROFILES_ENABLED:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping of validators for all system settings. This map is used to validate both valid
|
||||
* keys as well as validating the values for those keys.
|
||||
@@ -3240,16 +3228,6 @@ public final class LineageSettings {
|
||||
VALIDATORS.put(TRUST_WARNINGS, TRUST_WARNINGS_VALIDATOR);
|
||||
VALIDATORS.put(VOLUME_PANEL_ON_LEFT, VOLUME_PANEL_ON_LEFT_VALIDATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static boolean shouldInterceptSystemProvider(String key) {
|
||||
switch (key) {
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3710,12 +3688,5 @@ public final class LineageSettings {
|
||||
public static boolean isLegacySetting(String key) {
|
||||
return ArrayUtils.contains(LEGACY_GLOBAL_SETTINGS, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public static boolean shouldInterceptSystemProvider(String key) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user