cmsdk: Provide remainder test coverage for CMStatusbarManager.

Change-Id: I4cfa89ac3d9e27b234c3209c203f2a3f2bf9c46b
TICKET: CYNGNOS-3050
This commit is contained in:
Adnan Begovic 2016-06-14 17:36:57 -07:00
parent 5d5e556c49
commit afa47a7973
3 changed files with 66 additions and 5 deletions

View File

@ -105,6 +105,7 @@ public class CMStatusBarManagerTest extends AndroidTestCase {
@MediumTest @MediumTest
public void testCustomTileListenerServiceOnCustomTilePosted() { public void testCustomTileListenerServiceOnCustomTilePosted() {
final CustomTile expectedCustomTile = createSampleCustomTile(); final CustomTile expectedCustomTile = createSampleCustomTile();
final UserHandle expectedUserHandle = new UserHandle(UserHandle.myUserId());
final CountDownLatch signal = new CountDownLatch(COUNTDOWN); final CountDownLatch signal = new CountDownLatch(COUNTDOWN);
CustomTileListenerService customTileListenerService = CustomTileListenerService customTileListenerService =
@ -114,7 +115,8 @@ public class CMStatusBarManagerTest extends AndroidTestCase {
super.onListenerConnected(); super.onListenerConnected();
Log.d(TAG, "Connected"); Log.d(TAG, "Connected");
// publish // publish
mCMStatusBarManager.publishTile(1337, expectedCustomTile); mCMStatusBarManager.publishTileAsUser(null, 1337, expectedCustomTile,
expectedUserHandle);
} }
@Override @Override
@ -122,7 +124,6 @@ public class CMStatusBarManagerTest extends AndroidTestCase {
super.onCustomTilePosted(sbc); super.onCustomTilePosted(sbc);
Log.d(TAG, "Posted " + sbc.getCustomTile()); Log.d(TAG, "Posted " + sbc.getCustomTile());
if (TextUtils.equals(expectedCustomTile.label, sbc.getCustomTile().label)) { if (TextUtils.equals(expectedCustomTile.label, sbc.getCustomTile().label)) {
removeCustomTile(mContext.getPackageName(), null, 1337);
signal.countDown(); signal.countDown();
} }
} }
@ -137,6 +138,8 @@ public class CMStatusBarManagerTest extends AndroidTestCase {
throw new AssertionError(e); throw new AssertionError(e);
} }
mCMStatusBarManager.removeTileAsUser(null, 1337, expectedUserHandle);
unregisterCustomTileListenerService(customTileListenerService); unregisterCustomTileListenerService(customTileListenerService);
} }
@ -151,7 +154,7 @@ public class CMStatusBarManagerTest extends AndroidTestCase {
public void onListenerConnected() { public void onListenerConnected() {
super.onListenerConnected(); super.onListenerConnected();
Log.d(TAG, "Connected"); Log.d(TAG, "Connected");
// publish // publish as user
mCMStatusBarManager.publishTile(1338, expectedCustomTile); mCMStatusBarManager.publishTile(1338, expectedCustomTile);
} }

View File

@ -113,6 +113,15 @@ public class CustomTileBuilderTest extends AndroidTestCase {
assertEquals(message, customTile.label); assertEquals(message, customTile.label);
} }
@SmallTest
public void testCustomTileBuilderLabelAsRes() {
String message = mContext.getString(R.string.app_name);
CustomTile customTile = new CustomTile.Builder(mContext)
.setLabel(R.string.app_name).build();
assertNotNull(customTile);
assertEquals(message, customTile.label);
}
@SmallTest @SmallTest
public void testCustomTileBuilderContentDescription() { public void testCustomTileBuilderContentDescription() {
String message = "Test content description"; String message = "Test content description";
@ -123,6 +132,16 @@ public class CustomTileBuilderTest extends AndroidTestCase {
assertEquals(message, customTile.contentDescription); assertEquals(message, customTile.contentDescription);
} }
@SmallTest
public void testCustomTileBuilderContentDescriptionAsRes() {
String message = mContext.getString(R.string.app_name);
CustomTile customTile = new CustomTile.Builder(mContext)
.setContentDescription(R.string.app_name)
.build();
assertNotNull(customTile);
assertEquals(message, customTile.contentDescription);
}
@SmallTest @SmallTest
public void testCustomTileBuilderIconSet() { public void testCustomTileBuilderIconSet() {
int resourceInt = R.drawable.ic_launcher; int resourceInt = R.drawable.ic_launcher;

View File

@ -56,13 +56,15 @@ public class StatusBarPanelCustomTileTest extends AndroidTestCase {
int expectedPid = Binder.getCallingPid(); int expectedPid = Binder.getCallingPid();
CustomTile expectedCustomTile = createSampleCustomTile(); CustomTile expectedCustomTile = createSampleCustomTile();
UserHandle expectedUserHandle = new UserHandle(mContext.getUserId()); UserHandle expectedUserHandle = new UserHandle(mContext.getUserId());
long expectedPostTime = System.currentTimeMillis();
// public StatusBarPanelCustomTile(String pkg, String resPkg, String opPkg, // public StatusBarPanelCustomTile(String pkg, String resPkg, String opPkg,
// int id, String tag, int uid, int initialPid, CustomTile customTile, UserHandle user) // int id, String tag, int uid, int initialPid, CustomTile customTile, UserHandle user,
// long postTime)
StatusBarPanelCustomTile statusBarPanelCustomTile = StatusBarPanelCustomTile statusBarPanelCustomTile =
new StatusBarPanelCustomTile(expectedPackage, expectedOpresPackage, new StatusBarPanelCustomTile(expectedPackage, expectedOpresPackage,
expectedOpPackage, expectedId, expectedTag, expectedUid, expectedPid, expectedOpPackage, expectedId, expectedTag, expectedUid, expectedPid,
expectedCustomTile, expectedUserHandle); expectedCustomTile, expectedUserHandle, expectedPostTime);
// Write to parcel // Write to parcel
Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain();
@ -77,16 +79,53 @@ public class StatusBarPanelCustomTileTest extends AndroidTestCase {
assertNotNull(fromParcel); assertNotNull(fromParcel);
assertEquals(expectedPackage, fromParcel.getPackage()); assertEquals(expectedPackage, fromParcel.getPackage());
assertEquals(expectedPostTime, fromParcel.getPostTime());
assertEquals(expectedOpresPackage, fromParcel.getResPkg()); assertEquals(expectedOpresPackage, fromParcel.getResPkg());
assertEquals(expectedOpPackage, fromParcel.getOpPkg()); assertEquals(expectedOpPackage, fromParcel.getOpPkg());
assertEquals(expectedId, fromParcel.getId()); assertEquals(expectedId, fromParcel.getId());
assertNotNull(fromParcel.getKey());
assertEquals(expectedTag, fromParcel.getTag()); assertEquals(expectedTag, fromParcel.getTag());
assertEquals(expectedUid, fromParcel.getUid()); assertEquals(expectedUid, fromParcel.getUid());
assertEquals(expectedPid, fromParcel.getInitialPid()); assertEquals(expectedPid, fromParcel.getInitialPid());
//CustomTile validation is excessive //CustomTile validation is excessive
assertEquals(expectedUserHandle.getIdentifier(), fromParcel.getUser().getIdentifier()); assertEquals(expectedUserHandle.getIdentifier(), fromParcel.getUser().getIdentifier());
assertEquals(expectedUserHandle.getIdentifier(), fromParcel.getUserId());
} }
@SmallTest
public void testDefaultConstructor() {
String expectedPackage = "expectedPackage";
String expectedOpresPackage = "resPackage";
String expectedOpPackage = "opPackage";
int expectedId = 1337;
String expectedTag = "TAG";
int expectedUid = mContext.getUserId();
int expectedPid = Binder.getCallingPid();
CustomTile expectedCustomTile = createSampleCustomTile();
UserHandle expectedUserHandle = new UserHandle(mContext.getUserId());
// public StatusBarPanelCustomTile(String pkg, String resPkg, String opPkg,
// int id, String tag, int uid, int initialPid, CustomTile customTile, UserHandle user)
StatusBarPanelCustomTile statusBarPanelCustomTile =
new StatusBarPanelCustomTile(expectedPackage, expectedOpresPackage,
expectedOpPackage, expectedId, expectedTag, expectedUid, expectedPid,
expectedCustomTile, expectedUserHandle);
assertNotNull(statusBarPanelCustomTile);
assertEquals(expectedPackage, statusBarPanelCustomTile.getPackage());
assertEquals(expectedOpresPackage, statusBarPanelCustomTile.getResPkg());
assertEquals(expectedOpPackage, statusBarPanelCustomTile.getOpPkg());
assertEquals(expectedId, statusBarPanelCustomTile.getId());
assertNotNull(statusBarPanelCustomTile.getKey());
assertEquals(expectedTag, statusBarPanelCustomTile.getTag());
assertEquals(expectedUid, statusBarPanelCustomTile.getUid());
assertEquals(expectedPid, statusBarPanelCustomTile.getInitialPid());
//CustomTile validation is excessive
assertEquals(expectedUserHandle.getIdentifier(),
statusBarPanelCustomTile.getUser().getIdentifier());
assertEquals(expectedUserHandle.getIdentifier(),
statusBarPanelCustomTile.getUserId());
}
private CustomTile createSampleCustomTile() { private CustomTile createSampleCustomTile() {
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);