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

Update weblayer/ to new 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: I921183f206930fd668fd39178bde892b7c309c3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261107Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781914}
parent 6a9b1e84
......@@ -82,6 +82,7 @@ android_library("weblayer_private_java_tests") {
"//third_party/android_deps:androidx_fragment_fragment_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:junit",
"//weblayer/public/java",
"//weblayer/public/javatestutil:test_java",
......@@ -128,6 +129,7 @@ android_library("weblayer_java_private_test_support") {
"//base:base_java",
"//base:base_java_test_support",
"//content/public/test/android:content_java_test_support",
"//third_party/hamcrest:hamcrest_java",
"//third_party/junit:junit",
"//weblayer/public/java",
"//weblayer/public/javatestutil:test_java",
......
......@@ -7,10 +7,12 @@ package org.chromium.weblayer.test;
import android.os.RemoteException;
import android.view.View;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.chromium.base.CommandLine;
import org.chromium.base.test.util.CallbackHelper;
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.TestThreadUtils;
import org.chromium.weblayer.Tab;
......@@ -51,8 +53,8 @@ public final class BrowserControlsHelper {
void waitForBrowserControlsViewToBeVisible(View v) {
CriteriaHelper.pollUiThread(() -> {
Assert.assertTrue(v.getHeight() > 0);
Assert.assertEquals(View.VISIBLE, v.getVisibility());
Criteria.checkThat(v.getHeight(), Matchers.greaterThan(0));
Criteria.checkThat(v.getVisibility(), Matchers.is(View.VISIBLE));
});
}
......
......@@ -13,6 +13,7 @@ import android.widget.TextView;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -72,8 +73,8 @@ public class BrowserControlsTest {
});
}
private boolean canBrowserControlsScroll() throws Exception {
return TestThreadUtils.runOnUiThreadBlocking(() -> {
private boolean canBrowserControlsScroll() {
return TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
try {
return getTestWebLayer().canBrowserControlsScroll(getActiveTab());
} catch (RemoteException e) {
......@@ -123,8 +124,9 @@ public class BrowserControlsTest {
mTopViewHeight, bottomViewHeight);
// Adding a bottom view should change the page height.
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertNotEquals(getVisiblePageHeight(), mPageHeightWithTopView));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.not(mPageHeightWithTopView));
});
int pageHeightWithTopAndBottomViews = getVisiblePageHeight();
Assert.assertTrue(pageHeightWithTopAndBottomViews < mPageHeightWithTopView);
......@@ -133,18 +135,23 @@ public class BrowserControlsTest {
activity.getWindow().getDecorView(), 0, -maxViewsHeight);
// Moving should hide the bottom View.
CriteriaHelper.pollUiThread(
Criteria.equals(View.INVISIBLE, () -> bottomView.getVisibility()));
CriteriaHelper.pollInstrumentationThread(
Criteria.equals(true, () -> getVisiblePageHeight() > mPageHeightWithTopView));
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(bottomView.getVisibility(), Matchers.is(View.INVISIBLE));
});
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(
getVisiblePageHeight(), Matchers.greaterThan(mPageHeightWithTopView));
});
// Move so top and bottom-controls are shown again.
EventUtils.simulateDragFromCenterOfView(
activity.getWindow().getDecorView(), 0, maxViewsHeight);
mBrowserControlsHelper.waitForBrowserControlsViewToBeVisible(bottomView);
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertEquals(getVisiblePageHeight(), pageHeightWithTopAndBottomViews));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(
getVisiblePageHeight(), Matchers.is(pageHeightWithTopAndBottomViews));
});
}
// Disabled on L bots due to unexplained flakes. See crbug.com/1035894.
......@@ -185,18 +192,21 @@ public class BrowserControlsTest {
activity.getWindow().getDecorView(), 0, -bottomViewHeight);
// Moving should hide the bottom-controls View.
CriteriaHelper.pollUiThread(
Criteria.equals(View.INVISIBLE, () -> bottomView.getVisibility()));
CriteriaHelper.pollInstrumentationThread(
Criteria.equals(pageHeightWithNoTopView, () -> getVisiblePageHeight()));
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(bottomView.getVisibility(), Matchers.is(View.INVISIBLE));
});
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.is(pageHeightWithNoTopView));
});
// Move so bottom-controls are shown again.
EventUtils.simulateDragFromCenterOfView(
activity.getWindow().getDecorView(), 0, bottomViewHeight);
mBrowserControlsHelper.waitForBrowserControlsViewToBeVisible(bottomView);
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertEquals(getVisiblePageHeight(), pageHeightWithBottomView));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.is(pageHeightWithBottomView));
});
}
// Disabled on L bots due to unexplained flakes. See crbug.com/1035894.
......@@ -212,9 +222,11 @@ public class BrowserControlsTest {
activity.getWindow().getDecorView(), 0, -mTopViewHeight);
// Moving should hide the top-controls and change the page height.
CriteriaHelper.pollUiThread(Criteria.equals(View.INVISIBLE, () -> topView.getVisibility()));
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertNotEquals(getVisiblePageHeight(), mPageHeightWithTopView));
CriteriaHelper.pollUiThread(
() -> Criteria.checkThat(topView.getVisibility(), Matchers.is(View.INVISIBLE)));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.not(mPageHeightWithTopView));
});
// Move so top-controls are shown again.
EventUtils.simulateDragFromCenterOfView(
......@@ -222,8 +234,9 @@ public class BrowserControlsTest {
// Wait for the page height to match initial height.
mBrowserControlsHelper.waitForBrowserControlsViewToBeVisible(topView);
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertEquals(getVisiblePageHeight(), mPageHeightWithTopView));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.is(mPageHeightWithTopView));
});
}
/**
......@@ -244,16 +257,20 @@ public class BrowserControlsTest {
activity.getWindow().getDecorView(), 0, -mTopViewHeight);
// Wait till top controls are invisible.
CriteriaHelper.pollUiThread(Criteria.equals(
View.INVISIBLE, () -> activity.getTopContentsContainer().getVisibility()));
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(activity.getTopContentsContainer().getVisibility(),
Matchers.is(View.INVISIBLE));
});
// Trigger an alert dialog.
mActivityTestRule.executeScriptSync(
"window.setTimeout(function() { alert('alert'); }, 1);", false);
// Top controls are shown.
CriteriaHelper.pollUiThread(Criteria.equals(
View.VISIBLE, () -> activity.getTopContentsContainer().getVisibility()));
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(
activity.getTopContentsContainer().getVisibility(), Matchers.is(View.VISIBLE));
});
}
// Tests various assertions when accessibility is enabled.
......@@ -268,16 +285,19 @@ public class BrowserControlsTest {
EventUtils.simulateDragFromCenterOfView(
activity.getWindow().getDecorView(), 0, -mTopViewHeight);
View topView = activity.getTopContentsContainer();
CriteriaHelper.pollUiThread(Criteria.equals(View.INVISIBLE, () -> topView.getVisibility()));
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertNotEquals(getVisiblePageHeight(), mPageHeightWithTopView));
CriteriaHelper.pollUiThread(
() -> Criteria.checkThat(topView.getVisibility(), Matchers.is(View.INVISIBLE)));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.not(mPageHeightWithTopView));
});
// Turn on accessibility, which should force the controls to show.
setAccessibilityEnabled(true);
mBrowserControlsHelper.waitForBrowserControlsViewToBeVisible(
activity.getTopContentsContainer());
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertEquals(getVisiblePageHeight(), mPageHeightWithTopView));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.is(mPageHeightWithTopView));
});
// When accessibility is enabled, the controls are not allowed to scroll.
Assert.assertFalse(canBrowserControlsScroll());
......@@ -286,7 +306,7 @@ public class BrowserControlsTest {
// setAccessibilityEnabled() is async.
setAccessibilityEnabled(false);
CriteriaHelper.pollInstrumentationThread(
Criteria.equals(true, () -> canBrowserControlsScroll()));
() -> Criteria.checkThat(canBrowserControlsScroll(), Matchers.is(true)));
}
@MinAndroidSdkLevel(Build.VERSION_CODES.M)
......@@ -310,7 +330,7 @@ public class BrowserControlsTest {
// Wait till new view is visible.
CriteriaHelper.pollUiThread(
Criteria.equals(View.VISIBLE, () -> newTopView.getVisibility()));
() -> Criteria.checkThat(newTopView.getVisibility(), Matchers.is(View.VISIBLE)));
int newTopViewHeight =
TestThreadUtils.runOnUiThreadBlocking(() -> { return newTopView.getHeight(); });
Assert.assertNotEquals(newTopViewHeight, mTopViewHeight);
......@@ -320,7 +340,8 @@ public class BrowserControlsTest {
// Remove all, and ensure metadata and page-height change.
TestThreadUtils.runOnUiThreadBlocking(() -> { newTopView.removeAllViews(); });
mBrowserControlsHelper.waitForBrowserControlsMetadataState(0, 0);
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertNotEquals(getVisiblePageHeight(), mPageHeightWithTopView));
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getVisiblePageHeight(), Matchers.not(mPageHeightWithTopView));
});
}
}
......@@ -11,12 +11,14 @@ import android.webkit.ValueCallback;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.TestThreadUtils;
import org.chromium.net.test.util.TestWebServer;
......@@ -97,7 +99,8 @@ public class DownloadCallbackTest {
}
public void waitForIntercept() {
CriteriaHelper.pollInstrumentationThread(() -> Assert.assertNotNull(mUrl));
CriteriaHelper.pollInstrumentationThread(
() -> Criteria.checkThat(mUrl, Matchers.notNullValue()));
}
public void waitForStarted() {
......
......@@ -5,9 +5,12 @@
package org.chromium.weblayer.test;
import android.net.Uri;
import android.os.RemoteException;
import androidx.test.filters.MediumTest;
import org.hamcrest.Matchers;
import org.json.JSONException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
......@@ -15,7 +18,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.CriteriaNotSatisfiedException;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.util.TestWebServer;
import org.chromium.weblayer.Browser;
......@@ -163,7 +168,7 @@ public final class GeolocationTest {
private void waitForCountEqual(String variableName, int count) {
CriteriaHelper.pollInstrumentationThread(
() -> { return getCountFromJS(variableName) == count; });
() -> Criteria.checkThat(getCountFromJS(variableName), Matchers.is(count)));
}
private void waitForDialog() throws Exception {
......@@ -173,9 +178,13 @@ public final class GeolocationTest {
+ "function(result) { queryResult = result.state; })",
false);
CriteriaHelper.pollInstrumentationThread(() -> {
return !mActivityTestRule.executeScriptSync("queryResult || ''", false)
.getString(Tab.SCRIPT_RESULT_KEY)
.equals("");
try {
String result = mActivityTestRule.executeScriptSync("queryResult || ''", false)
.getString(Tab.SCRIPT_RESULT_KEY);
Criteria.checkThat(result, Matchers.not(""));
} catch (JSONException ex) {
throw new CriteriaNotSatisfiedException(ex);
}
});
Assert.assertEquals("prompt",
mActivityTestRule.executeScriptSync("queryResult", false)
......@@ -185,13 +194,20 @@ public final class GeolocationTest {
}
private void waitForCountGreaterThan(String variableName, int count) {
CriteriaHelper.pollInstrumentationThread(
() -> { return getCountFromJS(variableName) > count; });
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getCountFromJS(variableName), Matchers.greaterThan(count));
});
}
private void ensureGeolocationIsRunning(boolean running) {
CriteriaHelper.pollInstrumentationThread(
() -> { return mTestWebLayer.isMockLocationProviderRunning() == running; });
CriteriaHelper.pollInstrumentationThread(() -> {
try {
Criteria.checkThat(
mTestWebLayer.isMockLocationProviderRunning(), Matchers.is(running));
} catch (RemoteException ex) {
throw new CriteriaNotSatisfiedException(ex);
}
});
}
private int getCountFromJS(String variableName) {
......
......@@ -9,6 +9,7 @@ import android.view.View;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -130,15 +131,17 @@ public class InfoBarTest {
// Scroll down and check that infobar container view is translated in response.
EventUtils.simulateDragFromCenterOfView(
activity.getWindow().getDecorView(), 0, -infoBarContainerViewHeight);
CriteriaHelper.pollUiThread(()
-> Assert.assertEquals(infoBarContainerViewHeight,
(int) infoBarContainerView.getTranslationY()));
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat((int) infoBarContainerView.getTranslationY(),
Matchers.is(infoBarContainerViewHeight));
});
// Scroll back up and check that infobar container view is translated in response.
EventUtils.simulateDragFromCenterOfView(
activity.getWindow().getDecorView(), 0, infoBarContainerViewHeight);
CriteriaHelper.pollUiThread(
() -> Assert.assertEquals(0, (int) infoBarContainerView.getTranslationY()));
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat((int) infoBarContainerView.getTranslationY(), Matchers.is(0));
});
}
@Test
......
......@@ -21,6 +21,7 @@ import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
......@@ -31,6 +32,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.InMemorySharedPreferencesContext;
import org.chromium.base.test.util.MinAndroidSdkLevel;
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.TestThreadUtils;
import org.chromium.weblayer.shell.InstrumentationActivity;
......@@ -320,9 +322,9 @@ public class InputTypesTest {
private void waitForNumFiles(String id, int num) {
CriteriaHelper.pollInstrumentationThread(() -> {
return num
== mActivityTestRule.executeScriptAndExtractInt(
"document.getElementById('" + id + "').files.length");
int actual = mActivityTestRule.executeScriptAndExtractInt(
"document.getElementById('" + id + "').files.length");
Criteria.checkThat(actual, Matchers.is(num));
});
}
......
......@@ -16,6 +16,7 @@ import android.support.test.rule.ActivityTestRule;
import androidx.fragment.app.Fragment;
import org.hamcrest.Matchers;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Assert;
......@@ -24,6 +25,7 @@ import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.base.test.util.CallbackHelper;
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.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
......@@ -146,8 +148,10 @@ public class InstrumentationActivityTestRule
recreate.run();
CriteriaHelper.pollUiThread(
() -> monitor.getLastActivity() != null && monitor.getLastActivity() != activity);
CriteriaHelper.pollUiThread(() -> {
Criteria.checkThat(monitor.getLastActivity(), Matchers.notNullValue());
Criteria.checkThat(monitor.getLastActivity(), Matchers.not(activity));
});
InstrumentationRegistry.getInstrumentation().removeMonitor(monitor);
// There is no way to rotate the activity using ActivityTestRule or even notify it.
......
......@@ -15,6 +15,7 @@ import android.webkit.ValueCallback;
import androidx.test.filters.MediumTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -23,6 +24,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.MinAndroidSdkLevel;
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.TestThreadUtils;
import org.chromium.weblayer.MediaCaptureCallback;
......@@ -93,15 +95,17 @@ public final class MediaCaptureTest {
Assert.assertTrue(mCaptureCallback.mAudio);
Assert.assertTrue(mCaptureCallback.mVideo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
CriteriaHelper.pollInstrumentationThread(
() -> { return getMediaCaptureNotification() != null; });
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getMediaCaptureNotification(), Matchers.notNullValue());
});
}
stopStream();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
CriteriaHelper.pollInstrumentationThread(
() -> { return getMediaCaptureNotification() == null; });
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getMediaCaptureNotification(), Matchers.nullValue());
});
}
}
......@@ -177,8 +181,9 @@ public final class MediaCaptureTest {
Assert.assertTrue(mCaptureCallback.mAudio);
Assert.assertFalse(mCaptureCallback.mVideo);
CriteriaHelper.pollInstrumentationThread(
() -> { return getMediaCaptureNotification() != null; });
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(getMediaCaptureNotification(), Matchers.notNullValue());
});
Notification audioNotification = getMediaCaptureNotification();
// Video stream.
......@@ -188,9 +193,9 @@ public final class MediaCaptureTest {
CriteriaHelper.pollInstrumentationThread(() -> {
Notification combinedNotification = getMediaCaptureNotification();
return combinedNotification != null
&& combinedNotification.getSmallIcon().getResId()
!= audioNotification.getSmallIcon().getResId();
Criteria.checkThat(combinedNotification, Matchers.notNullValue());
Criteria.checkThat(combinedNotification.getSmallIcon().getResId(),
Matchers.not(audioNotification.getSmallIcon().getResId()));
});
mCaptureCallback.mStateCountDown = new BoundedCountDownLatch(2);
......@@ -201,7 +206,7 @@ public final class MediaCaptureTest {
Assert.assertFalse(mCaptureCallback.mVideo);
CriteriaHelper.pollInstrumentationThread(
() -> { return getMediaCaptureNotification() == null; });
() -> Criteria.checkThat(getMediaCaptureNotification(), Matchers.nullValue()));
}
private void grantPermissionAndWaitForStreamToStart() throws Throwable {
......
......@@ -23,6 +23,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CallbackHelper;
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.TestThreadUtils;
import org.chromium.net.test.util.TestWebServer;
......@@ -139,7 +140,7 @@ public class NavigationTest {
public void waitUntilValueObserved(String expectation) {
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertThat(expectation, Matchers.isIn(mObservedValues)));
() -> Criteria.checkThat(expectation, Matchers.isIn(mObservedValues)));
}
}
......
......@@ -8,12 +8,14 @@ import android.content.Context;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.TestThreadUtils;
import org.chromium.weblayer.TestWebLayer;
......@@ -51,8 +53,9 @@ public final class PopupTest {
// Make sure the infobar shows up and the popup has not been opened.
int buttonId = ResourceUtil.getIdentifier(mRemoteContext, "id/button_primary");
CriteriaHelper.pollInstrumentationThread(
() -> { return mActivity.findViewById(buttonId) != null; });
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(mActivity.findViewById(buttonId), Matchers.notNullValue());
});
TestThreadUtils.runOnUiThreadBlocking(
() -> { Assert.assertEquals(mActivity.getBrowser().getTabs().size(), 1); });
......
......@@ -10,12 +10,15 @@ import android.content.pm.ActivityInfo;
import androidx.fragment.app.Fragment;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.CriteriaNotSatisfiedException;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.shell.InstrumentationActivity;
......@@ -77,9 +80,9 @@ public class SmokeTest {
Reference enqueuedReference = referenceQueue.poll();
if (enqueuedReference == null) {
Runtime.getRuntime().gc();
Assert.fail("No enqueued reference");
throw new CriteriaNotSatisfiedException("No enqueued reference");
}
Assert.assertEquals(reference, enqueuedReference);
Criteria.checkThat(reference, Matchers.is(enqueuedReference));
});
}
......@@ -133,9 +136,9 @@ public class SmokeTest {
Reference enqueuedReference = referenceQueue.poll();
if (enqueuedReference == null) {
Runtime.getRuntime().gc();
Assert.fail("No enqueued reference");
throw new CriteriaNotSatisfiedException("No enqueued reference");
}
Assert.assertEquals(reference, enqueuedReference);
Criteria.checkThat(reference, Matchers.is(enqueuedReference));
});
}
}
......@@ -16,6 +16,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CallbackHelper;
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.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TestTouchUtils;
......@@ -53,7 +54,7 @@ public class TabCallbackTest {
public void waitUntilValueObserved(String expectation) {
CriteriaHelper.pollInstrumentationThread(
() -> Assert.assertThat(expectation, Matchers.isIn(mObservedValues)));
() -> Criteria.checkThat(expectation, Matchers.isIn(mObservedValues)));
}
}
......@@ -309,14 +310,15 @@ public class TabCallbackTest {
String url = mActivityTestRule.getTestDataURL("simple_page.html");
mActivityTestRule.navigateAndWait(url);
// Use polling because title is allowed to go through multiple transitions.
CriteriaHelper.pollUiThread(() -> { return "OK".equals(titles[0]); });
CriteriaHelper.pollUiThread(() -> Criteria.checkThat(titles[0], Matchers.is("OK")));
url = mActivityTestRule.getTestDataURL("shakespeare.html");
mActivityTestRule.navigateAndWait(url);
CriteriaHelper.pollUiThread(() -> { return titles[0].endsWith("shakespeare.html"); });
CriteriaHelper.pollUiThread(
() -> Criteria.checkThat(titles[0], Matchers.endsWith("shakespeare.html")));
mActivityTestRule.executeScriptSync("document.title = \"foobar\";", false);
Assert.assertEquals("foobar", titles[0]);
CriteriaHelper.pollUiThread(() -> { return "foobar".equals(titles[0]); });
CriteriaHelper.pollUiThread(() -> Criteria.checkThat(titles[0], Matchers.is("foobar")));
}
}
......@@ -4,6 +4,8 @@
package org.chromium.weblayer.test;
import org.hamcrest.Matchers;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.weblayer.FullscreenCallback;
......@@ -28,10 +30,11 @@ public class TestFullscreenCallback extends FullscreenCallback {
}
public void waitForFullscreen() {
CriteriaHelper.pollUiThread(Criteria.equals(1, () -> mEnterFullscreenCount));
CriteriaHelper.pollUiThread(
() -> Criteria.checkThat(mEnterFullscreenCount, Matchers.is(1)));
}
public void waitForExitFullscreen() {
CriteriaHelper.pollUiThread(Criteria.equals(1, () -> mExitFullscreenCount));
CriteriaHelper.pollUiThread(() -> Criteria.checkThat(mExitFullscreenCount, Matchers.is(1)));
}
}
......@@ -9,12 +9,14 @@ import android.view.View;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.TestThreadUtils;
import org.chromium.weblayer.TestWebLayer;
......@@ -72,13 +74,15 @@ public class TranslateTest {
private void waitForInfoBarToShow() {
CriteriaHelper.pollInstrumentationThread(() -> {
return findViewByStringId("id/weblayer_translate_infobar_content") != null;
Criteria.checkThat(findViewByStringId("id/weblayer_translate_infobar_content"),
Matchers.notNullValue());
});
}
private void waitForInfoBarToHide() {
CriteriaHelper.pollInstrumentationThread(() -> {
return findViewByStringId("id/weblayer_translate_infobar_content") == null;
Criteria.checkThat(findViewByStringId("id/weblayer_translate_infobar_content"),
Matchers.nullValue());
});
}
}
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