summaryrefslogtreecommitdiffstats
path: root/library/test
diff options
context:
space:
mode:
Diffstat (limited to 'library/test')
-rw-r--r--library/test/res/values/config.xml2
-rw-r--r--library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java14
-rw-r--r--library/test/src/com/android/setupwizardlib/test/SystemBarHelperTest.java65
3 files changed, 51 insertions, 30 deletions
diff --git a/library/test/res/values/config.xml b/library/test/res/values/config.xml
index bda4f54..35425fc 100644
--- a/library/test/res/values/config.xml
+++ b/library/test/res/values/config.xml
@@ -20,4 +20,6 @@
<!-- Overlay the transition duration for testing partner overlays -->
<integer name="suwTransitionDuration">5000</integer>
+ <item type="id" name="test_view_id" />
+
</resources>
diff --git a/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java b/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java
index f5cd287..cce2f70 100644
--- a/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java
+++ b/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java
@@ -16,11 +16,9 @@
package com.android.setupwizardlib.test;
-import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
-import android.os.Build.VERSION_CODES;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.ContextThemeWrapper;
@@ -56,16 +54,14 @@ public class SetupWizardLayoutTests extends InstrumentationTestCase {
assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText());
}
- @TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
@SmallTest
public void testAddView() {
SetupWizardLayout layout = new SetupWizardLayout(mContext);
TextView tv = new TextView(mContext);
- int id = View.generateViewId();
- tv.setId(id);
+ tv.setId(R.id.test_view_id);
layout.addView(tv);
assertDefaultTemplateInflated(layout);
- View view = layout.findViewById(id);
+ View view = layout.findViewById(R.id.test_view_id);
assertSame("The view added should be the same text view", tv, view);
}
@@ -78,7 +74,6 @@ public class SetupWizardLayoutTests extends InstrumentationTestCase {
assertTrue("@id/test_content should be a TextView", content instanceof TextView);
}
- @TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
@SmallTest
public void testCustomTemplate() {
SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
@@ -86,13 +81,12 @@ public class SetupWizardLayoutTests extends InstrumentationTestCase {
assertNotNull("@id/test_template_view should exist in template", templateView);
TextView tv = new TextView(mContext);
- int id = View.generateViewId();
- tv.setId(id);
+ tv.setId(R.id.test_view_id);
layout.addView(tv);
templateView = layout.findViewById(R.id.test_template_view);
assertNotNull("@id/test_template_view should exist in template", templateView);
- View contentView = layout.findViewById(id);
+ View contentView = layout.findViewById(R.id.test_view_id);
assertSame("The view added should be the same text view", tv, contentView);
// The following methods should be no-ops because the custom template doesn't contain the
diff --git a/library/test/src/com/android/setupwizardlib/test/SystemBarHelperTest.java b/library/test/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
index c364984..98e3f73 100644
--- a/library/test/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
+++ b/library/test/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
@@ -21,6 +21,8 @@ import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -51,71 +53,94 @@ public class SystemBarHelperTest extends AndroidTestCase {
public void testAddVisibilityFlagView() {
final View view = createViewWithSystemUiVisibility(0x456);
SystemBarHelper.addVisibilityFlag(view, 0x1400);
- assertEquals("View visibility should be 0x1456", 0x1456, view.getSystemUiVisibility());
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x1456, because 0x1400 | 0x456 = 0x1456.
+ assertEquals("View visibility should be 0x1456", 0x1456, view.getSystemUiVisibility());
+ }
}
@SmallTest
public void testRemoveVisibilityFlagView() {
final View view = createViewWithSystemUiVisibility(0x456);
SystemBarHelper.removeVisibilityFlag(view, 0x1400);
- assertEquals("View visibility should be 0x56", 0x56, view.getSystemUiVisibility());
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x56, because 0x456 & ~0x1400 = 0x56.
+ assertEquals("View visibility should be 0x56", 0x56, view.getSystemUiVisibility());
+ }
}
@SmallTest
public void testAddVisibilityFlagWindow() {
final Window window = createWindowWithSystemUiVisibility(0x456);
SystemBarHelper.addVisibilityFlag(window, 0x1400);
- assertEquals("View visibility should be 0x1456", 0x1456,
- window.getAttributes().systemUiVisibility);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x1456 = 0x1400 | 0x456.
+ assertEquals("View visibility should be 0x1456", 0x1456,
+ window.getAttributes().systemUiVisibility);
+ }
}
@SmallTest
public void testRemoveVisibilityFlagWindow() {
final Window window = createWindowWithSystemUiVisibility(0x456);
SystemBarHelper.removeVisibilityFlag(window, 0x1400);
- assertEquals("View visibility should be 0x56", 0x56,
- window.getAttributes().systemUiVisibility);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x56 = 0x456 & ~0x1400.
+ assertEquals("View visibility should be 0x56", 0x56,
+ window.getAttributes().systemUiVisibility);
+ }
}
@SmallTest
public void testHideSystemBarsWindow() {
final Window window = createWindowWithSystemUiVisibility(0x456);
SystemBarHelper.hideSystemBars(window);
- assertEquals("DEFAULT_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
- DEFAULT_IMMERSIVE_FLAGS | 0x456,
- window.getAttributes().systemUiVisibility);
- assertEquals("DEFAULT_IMMERSIVE_FLAGS should be added to decorView's systemUiVisibility",
- DEFAULT_IMMERSIVE_FLAGS | 0x456,
- window.getDecorView().getSystemUiVisibility());
+ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ assertEquals("DEFAULT_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
+ DEFAULT_IMMERSIVE_FLAGS | 0x456,
+ window.getAttributes().systemUiVisibility);
+ assertEquals(
+ "DEFAULT_IMMERSIVE_FLAGS should be added to decorView's systemUiVisibility",
+ DEFAULT_IMMERSIVE_FLAGS | 0x456,
+ window.getDecorView().getSystemUiVisibility());
+ }
}
@SmallTest
public void testSetBackButtonVisibleTrue() {
final Window window = createWindowWithSystemUiVisibility(0x456);
SystemBarHelper.setBackButtonVisible(window, true);
- assertEquals("View visibility should be 0x456", 0x456,
- window.getAttributes().systemUiVisibility);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ assertEquals("View visibility should be 0x456", 0x456,
+ window.getAttributes().systemUiVisibility);
+ }
}
@SmallTest
public void testSetBackButtonVisibleFalse() {
final Window window = createWindowWithSystemUiVisibility(0x456);
SystemBarHelper.setBackButtonVisible(window, false);
- assertEquals("STATUS_BAR_DISABLE_BACK should be added to systemUiVisibility",
- 0x456 | STATUS_BAR_DISABLE_BACK, window.getAttributes().systemUiVisibility);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ assertEquals("STATUS_BAR_DISABLE_BACK should be added to systemUiVisibility",
+ 0x456 | STATUS_BAR_DISABLE_BACK, window.getAttributes().systemUiVisibility);
+ }
}
private View createViewWithSystemUiVisibility(int vis) {
final View view = new View(getContext());
- view.setSystemUiVisibility(vis);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ view.setSystemUiVisibility(vis);
+ }
return view;
}
private Window createWindowWithSystemUiVisibility(int vis) {
final Window window = new TestWindow(getContext(), createViewWithSystemUiVisibility(vis));
- WindowManager.LayoutParams attrs = window.getAttributes();
- attrs.systemUiVisibility = vis;
- window.setAttributes(attrs);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ WindowManager.LayoutParams attrs = window.getAttributes();
+ attrs.systemUiVisibility = vis;
+ window.setAttributes(attrs);
+ }
return window;
}