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