From afa47a7973cceaf9cffc6ad67cc728cd7d22e97b Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Tue, 14 Jun 2016 17:36:57 -0700 Subject: [PATCH] cmsdk: Provide remainder test coverage for CMStatusbarManager. Change-Id: I4cfa89ac3d9e27b234c3209c203f2a3f2bf9c46b TICKET: CYNGNOS-3050 --- .../unit/CMStatusBarManagerTest.java | 9 ++-- .../unit/CustomTileBuilderTest.java | 19 ++++++++ .../unit/StatusBarPanelCustomTileTest.java | 43 ++++++++++++++++++- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/tests/src/org/cyanogenmod/tests/customtiles/unit/CMStatusBarManagerTest.java b/tests/src/org/cyanogenmod/tests/customtiles/unit/CMStatusBarManagerTest.java index 09c636d..e894462 100644 --- a/tests/src/org/cyanogenmod/tests/customtiles/unit/CMStatusBarManagerTest.java +++ b/tests/src/org/cyanogenmod/tests/customtiles/unit/CMStatusBarManagerTest.java @@ -105,6 +105,7 @@ public class CMStatusBarManagerTest extends AndroidTestCase { @MediumTest public void testCustomTileListenerServiceOnCustomTilePosted() { final CustomTile expectedCustomTile = createSampleCustomTile(); + final UserHandle expectedUserHandle = new UserHandle(UserHandle.myUserId()); final CountDownLatch signal = new CountDownLatch(COUNTDOWN); CustomTileListenerService customTileListenerService = @@ -114,7 +115,8 @@ public class CMStatusBarManagerTest extends AndroidTestCase { super.onListenerConnected(); Log.d(TAG, "Connected"); // publish - mCMStatusBarManager.publishTile(1337, expectedCustomTile); + mCMStatusBarManager.publishTileAsUser(null, 1337, expectedCustomTile, + expectedUserHandle); } @Override @@ -122,7 +124,6 @@ public class CMStatusBarManagerTest extends AndroidTestCase { super.onCustomTilePosted(sbc); Log.d(TAG, "Posted " + sbc.getCustomTile()); if (TextUtils.equals(expectedCustomTile.label, sbc.getCustomTile().label)) { - removeCustomTile(mContext.getPackageName(), null, 1337); signal.countDown(); } } @@ -137,6 +138,8 @@ public class CMStatusBarManagerTest extends AndroidTestCase { throw new AssertionError(e); } + mCMStatusBarManager.removeTileAsUser(null, 1337, expectedUserHandle); + unregisterCustomTileListenerService(customTileListenerService); } @@ -151,7 +154,7 @@ public class CMStatusBarManagerTest extends AndroidTestCase { public void onListenerConnected() { super.onListenerConnected(); Log.d(TAG, "Connected"); - // publish + // publish as user mCMStatusBarManager.publishTile(1338, expectedCustomTile); } diff --git a/tests/src/org/cyanogenmod/tests/customtiles/unit/CustomTileBuilderTest.java b/tests/src/org/cyanogenmod/tests/customtiles/unit/CustomTileBuilderTest.java index 544089d..1368af5 100644 --- a/tests/src/org/cyanogenmod/tests/customtiles/unit/CustomTileBuilderTest.java +++ b/tests/src/org/cyanogenmod/tests/customtiles/unit/CustomTileBuilderTest.java @@ -113,6 +113,15 @@ public class CustomTileBuilderTest extends AndroidTestCase { 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 public void testCustomTileBuilderContentDescription() { String message = "Test content description"; @@ -123,6 +132,16 @@ public class CustomTileBuilderTest extends AndroidTestCase { 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 public void testCustomTileBuilderIconSet() { int resourceInt = R.drawable.ic_launcher; diff --git a/tests/src/org/cyanogenmod/tests/customtiles/unit/StatusBarPanelCustomTileTest.java b/tests/src/org/cyanogenmod/tests/customtiles/unit/StatusBarPanelCustomTileTest.java index 6b22f38..dd11e9b 100644 --- a/tests/src/org/cyanogenmod/tests/customtiles/unit/StatusBarPanelCustomTileTest.java +++ b/tests/src/org/cyanogenmod/tests/customtiles/unit/StatusBarPanelCustomTileTest.java @@ -56,13 +56,15 @@ public class StatusBarPanelCustomTileTest extends AndroidTestCase { int expectedPid = Binder.getCallingPid(); CustomTile expectedCustomTile = createSampleCustomTile(); UserHandle expectedUserHandle = new UserHandle(mContext.getUserId()); + long expectedPostTime = System.currentTimeMillis(); // 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 = new StatusBarPanelCustomTile(expectedPackage, expectedOpresPackage, expectedOpPackage, expectedId, expectedTag, expectedUid, expectedPid, - expectedCustomTile, expectedUserHandle); + expectedCustomTile, expectedUserHandle, expectedPostTime); // Write to parcel Parcel parcel = Parcel.obtain(); @@ -77,16 +79,53 @@ public class StatusBarPanelCustomTileTest extends AndroidTestCase { assertNotNull(fromParcel); assertEquals(expectedPackage, fromParcel.getPackage()); + assertEquals(expectedPostTime, fromParcel.getPostTime()); assertEquals(expectedOpresPackage, fromParcel.getResPkg()); assertEquals(expectedOpPackage, fromParcel.getOpPkg()); assertEquals(expectedId, fromParcel.getId()); + assertNotNull(fromParcel.getKey()); assertEquals(expectedTag, fromParcel.getTag()); assertEquals(expectedUid, fromParcel.getUid()); assertEquals(expectedPid, fromParcel.getInitialPid()); //CustomTile validation is excessive 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() { Intent intent = new Intent(Intent.ACTION_DIAL);