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