use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
the class ResourcesManagerTest method testMultipleResourcesForOneActivityGetUpdatedWhenActivityBaseUpdates.
@SmallTest
public void testMultipleResourcesForOneActivityGetUpdatedWhenActivityBaseUpdates() {
Binder activity1 = new Binder();
// Create a Resources for the Activity.
Configuration config1 = new Configuration();
config1.densityDpi = 280;
Resources resources1 = mResourcesManager.createBaseActivityResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, config1, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources1);
// Create a Resources based on the Activity.
Configuration config2 = new Configuration();
config2.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
Resources resources2 = mResourcesManager.getResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, config2, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources2);
assertNotSame(resources1, resources2);
assertNotSame(resources1.getImpl(), resources2.getImpl());
final Configuration expectedConfig1 = new Configuration();
expectedConfig1.setLocales(LocaleList.getAdjustedDefault());
expectedConfig1.densityDpi = 280;
assertEquals(expectedConfig1, resources1.getConfiguration());
// resources2 should be based on the Activity's override config, so the density should
// be the same as resources1.
final Configuration expectedConfig2 = new Configuration();
expectedConfig2.setLocales(LocaleList.getAdjustedDefault());
expectedConfig2.densityDpi = 280;
expectedConfig2.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
assertEquals(expectedConfig2, resources2.getConfiguration());
// Now update the Activity base override, and both resources should update.
config1.orientation = Configuration.ORIENTATION_LANDSCAPE;
mResourcesManager.updateResourcesForActivity(activity1, config1);
expectedConfig1.orientation = Configuration.ORIENTATION_LANDSCAPE;
assertEquals(expectedConfig1, resources1.getConfiguration());
expectedConfig2.orientation = Configuration.ORIENTATION_LANDSCAPE;
assertEquals(expectedConfig2, resources2.getConfiguration());
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
the class ResourcesManagerTest method testThemesGetUpdatedWithNewImpl.
@SmallTest
public void testThemesGetUpdatedWithNewImpl() {
Binder activity1 = new Binder();
Resources resources1 = mResourcesManager.createBaseActivityResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources1);
Resources.Theme theme = resources1.newTheme();
assertSame(resources1, theme.getResources());
theme.applyStyle(android.R.style.Theme_NoTitleBar, false);
TypedValue value = new TypedValue();
assertTrue(theme.resolveAttribute(android.R.attr.windowNoTitle, value, true));
assertEquals(TypedValue.TYPE_INT_BOOLEAN, value.type);
assertTrue(value.data != 0);
final Configuration overrideConfig = new Configuration();
overrideConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
mResourcesManager.updateResourcesForActivity(activity1, overrideConfig);
assertSame(resources1, theme.getResources());
// Make sure we can still access the data.
assertTrue(theme.resolveAttribute(android.R.attr.windowNoTitle, value, true));
assertEquals(TypedValue.TYPE_INT_BOOLEAN, value.type);
assertTrue(value.data != 0);
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
the class ResourcesManagerTest method testUpdateConfigurationUpdatesAllAssetManagers.
@SmallTest
public void testUpdateConfigurationUpdatesAllAssetManagers() {
Resources resources1 = mResourcesManager.getResources(null, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources1);
Resources resources2 = mResourcesManager.getResources(null, APP_TWO_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources2);
Binder activity = new Binder();
final Configuration overrideConfig = new Configuration();
overrideConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
Resources resources3 = mResourcesManager.getResources(activity, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, overrideConfig, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources3);
// No Resources object should be the same.
assertNotSame(resources1, resources2);
assertNotSame(resources1, resources3);
assertNotSame(resources2, resources3);
// Each ResourcesImpl should be different.
assertNotSame(resources1.getImpl(), resources2.getImpl());
assertNotSame(resources1.getImpl(), resources3.getImpl());
assertNotSame(resources2.getImpl(), resources3.getImpl());
Configuration newConfig = new Configuration();
newConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null);
final Configuration expectedConfig = new Configuration();
expectedConfig.setLocales(LocaleList.getAdjustedDefault());
expectedConfig.densityDpi = mDisplayMetrics.densityDpi;
expectedConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
assertEquals(expectedConfig, resources1.getConfiguration());
assertEquals(expectedConfig, resources2.getConfiguration());
assertEquals(expectedConfig, resources3.getConfiguration());
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
the class ResourcesLocaleTest method testEnglishIsAlwaysConsideredSupported.
@SmallTest
public void testEnglishIsAlwaysConsideredSupported() throws Exception {
final Resources resources = createResourcesWithApk(R.raw.locales);
ensureNoLanguage(resources, "en");
final LocaleList preferredLocales = LocaleList.forLanguageTags("en-US,pl-PL");
final Configuration config = new Configuration();
config.setLocales(preferredLocales);
resources.updateConfiguration(config, null);
// The APK we loaded has default and Polish languages. If English is first in the list,
// always take it the default (assumed to be English).
assertEquals(Locale.forLanguageTag("en-US"), resources.getConfiguration().getLocales().get(0));
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
the class BatteryStatsDurationTimerTest method testParceling.
@SmallTest
public void testParceling() throws Exception {
final MockClocks clocks = new MockClocks();
final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase();
timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime());
final BatteryStatsImpl.DurationTimer timer = new BatteryStatsImpl.DurationTimer(clocks, null, BatteryStats.WAKE_TYPE_PARTIAL, null, timeBase);
// Start running on battery.
clocks.realtime = 100;
clocks.uptime = 10;
timeBase.setRunning(true, clocks.uptimeMillis() * 1000, clocks.elapsedRealtime() * 1000);
timer.startRunningLocked(300);
// Check that it did start running
assertEquals(400, timer.getMaxDurationMsLocked(700));
assertEquals(401, timer.getCurrentDurationMsLocked(701));
// Write summary
final Parcel summaryParcel = Parcel.obtain();
timer.writeSummaryFromParcelLocked(summaryParcel, 1500 * 1000);
summaryParcel.setDataPosition(0);
// Read summary
final BatteryStatsImpl.DurationTimer summary = new BatteryStatsImpl.DurationTimer(clocks, null, BatteryStats.WAKE_TYPE_PARTIAL, null, timeBase);
summary.startRunningLocked(3100);
summary.readSummaryFromParcelLocked(summaryParcel);
// The new one shouldn't be running, and therefore 0 for current time
assertFalse(summary.isRunningLocked());
assertEquals(0, summary.getCurrentDurationMsLocked(6300));
// The new one should have the max duration that we had when we wrote it
assertEquals(1200, summary.getMaxDurationMsLocked(6301));
// Write full
final Parcel fullParcel = Parcel.obtain();
timer.writeToParcel(fullParcel, 1500 * 1000);
fullParcel.setDataPosition(0);
// Read full - Should be the same as the summary as far as DurationTimer is concerned.
final BatteryStatsImpl.DurationTimer full = new BatteryStatsImpl.DurationTimer(clocks, null, BatteryStats.WAKE_TYPE_PARTIAL, null, timeBase, fullParcel);
// The new one shouldn't be running, and therefore 0 for current time
assertFalse(full.isRunningLocked());
assertEquals(0, full.getCurrentDurationMsLocked(6300));
// The new one should have the max duration that we had when we wrote it
assertEquals(1200, full.getMaxDurationMsLocked(6301));
}
Aggregations