Improving tests to fix testBindNormalWidget_withoutConfig, and beyond

1. Make waitXXX methods fail if the condition diesn’t turn true.
2. Waiting for loading to complete in tearDown instead of reloading the
 model
3. Avoiding waiting for load-complete where loading didn’t start
4. Disabling last test in AddConfigWidgetTest
5. Waiting for loading to complete inside setupAndVerifyContents(), not
 outside
6. Unifying how we wait for loader to complete
7. Adding more logging

Bug: 117332845
Test: running all Nexus tests
Change-Id: I3070e1ac2b9161179cc3e0800b0cd8162807389a
This commit is contained in:
Vadim Tryshev
2018-10-09 18:46:45 -07:00
parent 02e900c3c9
commit 14c6c8cee4
10 changed files with 46 additions and 46 deletions

View File

@@ -141,7 +141,6 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
// Since there is no widget to verify, just wait until the workspace is ready.
setupAndVerifyContents(item, Workspace.class, null);
waitUntilLoaderIdle();
// Item deleted from db
mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
null, null, null, null, null);
@@ -187,7 +186,6 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
item.restoreStatus = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID;
setupAndVerifyContents(item, PendingAppWidgetHostView.class, null);
waitUntilLoaderIdle();
// Item deleted from db
mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
null, null, null, null, null);
@@ -216,7 +214,6 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
// The view does not exist
assertFalse(mDevice.findObject(
new UiSelector().className(PendingAppWidgetHostView.class)).exists());
waitUntilLoaderIdle();
// Item deleted from db
mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
null, null, null, null, null);
@@ -234,7 +231,6 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
setupAndVerifyContents(item, PendingAppWidgetHostView.class, null);
// Verify item still exists in db
waitUntilLoaderIdle();
mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
null, null, null, null, null);
assertEquals(1, mCursor.getCount());
@@ -261,7 +257,6 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
setupAndVerifyContents(item, PendingAppWidgetHostView.class, null);
// Verify item still exists in db
waitUntilLoaderIdle();
mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
null, null, null, null, null);
assertEquals(1, mCursor.getCount());
@@ -306,6 +301,8 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
// Launch the home activity
mActivityMonitor.startLauncher();
waitForModelLoaded();
// Verify UI
UiSelector selector = new UiSelector().packageName(mTargetContext.getPackageName())
.className(widgetClass);
@@ -390,15 +387,4 @@ public class BindWidgetTest extends AbstractLauncherUiTest {
item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
return item;
}
/**
* Blocks the current thread until all the jobs in the main worker thread are complete.
*/
private void waitUntilLoaderIdle() throws Exception {
new LooperExecutor(LauncherModel.getWorkerLooper())
.submit(new Runnable() {
@Override
public void run() { }
}).get(DEFAULT_WORKER_TIMEOUT_SECS, TimeUnit.SECONDS);
}
}