Commit d4029987 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Update components/ to use Criteria.checkThat(...)

Replaces Criteria.equals usage as part of the migration.

See https://groups.google.com/a/chromium.org/g/java/c/ZSj5TANUy8Q/m/gFL8BCVmBgAJ
for more details.

BUG=1071247

Change-Id: Id02d0a737b92533ba8abb462a48a20e2c685e58b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264023Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782083}
parent d73492fe
......@@ -45,6 +45,7 @@ android_library("javatests") {
"//content/public/test/android:content_java_test_support",
"//third_party/android_deps:androidx_appcompat_appcompat_java",
"//third_party/android_deps:androidx_core_core_java",
"//third_party/hamcrest:hamcrest_java",
"//third_party/junit",
"//ui/android:ui_java",
"//ui/android:ui_java_test_support",
......
......@@ -18,9 +18,9 @@ import android.os.Environment;
import android.os.Looper;
import android.provider.MediaStore;
import androidx.core.util.ObjectsCompat;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -124,12 +124,9 @@ public class ShareImageFileUtilsTest extends DummyUiActivityTestCase {
getActivity(), TEST_IMAGE_DATA, fileExtension, imageCallback);
imageCallback.waitForCallback(0, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
Clipboard.getInstance().setImageUri(imageCallback.getImageUri());
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return ObjectsCompat.equals(
Clipboard.getInstance().getImageUri(), imageCallback.getImageUri());
}
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(Clipboard.getInstance().getImageUri(),
Matchers.is(imageCallback.getImageUri()));
});
return imageCallback.getImageUri();
}
......
......@@ -240,6 +240,7 @@ android_library("javatests") {
"//third_party/android_deps:androidx_core_core_java",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/hamcrest:hamcrest_java",
"//third_party/junit",
"//ui/android:ui_java",
"//ui/android:ui_java_test_support",
......
......@@ -18,6 +18,7 @@ import android.widget.TextView;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -267,14 +268,11 @@ public class RadioButtonWithEditTextTest extends DummyUiActivityTestCase {
}
private void assertIsKeyboardShowing(boolean isShowing) {
CriteriaHelper.pollUiThread(
new Criteria("Keyboard visibility does not consist with test setting.") {
@Override
public boolean isSatisfied() {
return KeyboardVisibilityDelegate.getInstance().isKeyboardShowing(
mActivity, mEditText)
== isShowing;
}
});
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat("Keyboard visibility does not consist with test setting.",
KeyboardVisibilityDelegate.getInstance().isKeyboardShowing(
mActivity, mEditText),
Matchers.is(isShowing));
});
}
}
......@@ -14,6 +14,7 @@ import android.widget.LinearLayout.LayoutParams;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -33,7 +34,6 @@ import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
import org.chromium.ui.test.util.NightModeTestUtils;
import org.chromium.ui.test.util.RenderTestRule;
import org.chromium.ui.widget.ButtonCompat;
import java.util.List;
......@@ -109,11 +109,12 @@ public class PromoCardViewRenderTest extends DummyUiActivityTestCase {
mModel.set(PromoCardProperties.HAS_SECONDARY_BUTTON, false);
setPromoCard(LayoutStyle.LARGE);
CriteriaHelper.pollUiThread(Criteria.equals(View.GONE, () -> {
ButtonCompat secondaryButton =
mPromoCardCoordinator.getView().findViewById(R.id.promo_secondary_button);
return secondaryButton.getVisibility();
}));
CriteriaHelper.pollUiThread(() -> {
int visibility = mPromoCardCoordinator.getView()
.findViewById(R.id.promo_secondary_button)
.getVisibility();
Criteria.checkThat(visibility, Matchers.is(View.GONE));
});
mRenderTestRule.render(mPromoCardCoordinator.getView(), "promo_card_secondary_hidden");
}
......
......@@ -20,6 +20,7 @@ import android.widget.FrameLayout;
import androidx.annotation.ColorInt;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -30,6 +31,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.Feature;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
......@@ -103,10 +105,10 @@ public class ScrimTest extends DummyUiActivityTestCase {
ThreadUtils.runOnUiThreadBlocking(() -> mScrimCoordinator.hideScrim(false));
CriteriaHelper.pollUiThread(()
-> mScrimCoordinator.getViewForTesting() == null,
"Scrim should be null after being hidden.", CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat("Scrim should be null after being hidden.",
mScrimCoordinator.getViewForTesting(), Matchers.nullValue());
});
}
@Test
......@@ -215,10 +217,10 @@ public class ScrimTest extends DummyUiActivityTestCase {
ThreadUtils.runOnUiThreadBlocking(() -> mScrimCoordinator.hideScrim(false));
CriteriaHelper.pollUiThread(()
-> mScrimCoordinator.getViewForTesting() == null,
"Scrim should be null after being hidden.", CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat("Scrim should be null after being hidden.",
mScrimCoordinator.getViewForTesting(), Matchers.nullValue());
});
}
@Test
......
......@@ -114,6 +114,7 @@ android_library("javatests") {
"//content/public/test/android:content_java_test_support",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/hamcrest:hamcrest_java",
"//third_party/junit",
"//third_party/ub-uiautomator:ub_uiautomator_java",
"//ui/android:ui_java_test_support",
......
......@@ -12,6 +12,7 @@ import android.view.ViewGroup;
import androidx.test.filters.MediumTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
......@@ -23,6 +24,7 @@ import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.ScalableTimeout;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
import org.chromium.url.GURL;
......@@ -88,17 +90,14 @@ public class PaintPreviewPlayerTest extends DummyUiActivityTestCase {
final View activityContentView = getActivity().findViewById(android.R.id.content);
// Assert that the player view has the same dimensions as the content view.
CriteriaHelper.pollUiThread(
() -> {
boolean contentSizeNonZero = activityContentView.getWidth() > 0
&& activityContentView.getHeight() > 0;
boolean viewSizeMatchContent =
activityContentView.getWidth() == playerHostView.getWidth()
&& activityContentView.getHeight() == playerHostView.getHeight();
return contentSizeNonZero && viewSizeMatchContent;
},
"Player size doesn't match R.id.content", TIMEOUT_MS,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(activityContentView.getWidth(), Matchers.greaterThan(0));
Criteria.checkThat(activityContentView.getHeight(), Matchers.greaterThan(0));
Criteria.checkThat(
activityContentView.getWidth(), Matchers.is(playerHostView.getWidth()));
Criteria.checkThat(
activityContentView.getHeight(), Matchers.is(playerHostView.getHeight()));
}, TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
/**
......@@ -224,9 +223,10 @@ public class PaintPreviewPlayerTest extends DummyUiActivityTestCase {
});
// Wait until PlayerManager is initialized.
CriteriaHelper.pollUiThread(() -> mPlayerManager != null,
"PlayerManager was not initialized.", TIMEOUT_MS,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(
"PlayerManager was not initialized.", mPlayerManager, Matchers.notNullValue());
}, TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
try {
viewReady.waitForFirst();
......@@ -235,10 +235,11 @@ public class PaintPreviewPlayerTest extends DummyUiActivityTestCase {
}
// Assert that the player view is added to the player host view.
CriteriaHelper.pollUiThread(
() -> ((ViewGroup) mPlayerManager.getView()).getChildCount() > 0,
"Player view is not added to the host view.", TIMEOUT_MS,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat("Player view is not added to the host view.",
((ViewGroup) mPlayerManager.getView()).getChildCount(),
Matchers.greaterThan(0));
}, TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
/*
......@@ -270,18 +271,11 @@ public class PaintPreviewPlayerTest extends DummyUiActivityTestCase {
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
device.click(scaledX + locationXY[0], scaledY + locationXY[1]);
CriteriaHelper.pollUiThread(
()
-> {
GURL url = mLinkClickHandler.mUrl;
if (url == null) return false;
return url.getSpec().equals(expectedUrl);
},
"Link press on abs (" + x + ", " + y + ") failed. Expected: " + expectedUrl
+ ", found: "
+ (mLinkClickHandler.mUrl == null ? null
: mLinkClickHandler.mUrl.getSpec()),
TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
CriteriaHelper.pollUiThread(() -> {
GURL url = mLinkClickHandler.mUrl;
String msg = "Link press on abs (" + x + ", " + y + ") failed.";
Criteria.checkThat(msg, url, Matchers.notNullValue());
Criteria.checkThat(msg, url.getSpec(), Matchers.is(expectedUrl));
}, TIMEOUT_MS, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment