| Index: content/public/android/javatests/src/org/chromium/content/browser/BindingManagerImplTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/BindingManagerImplTest.java b/content/public/android/javatests/src/org/chromium/content/browser/BindingManagerImplTest.java
|
| index ebbe6caf0bff01dd3869ad3b5d6efe5675841726..756c00275c7a7e80c851f8dca78d7a4eed585cae 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/BindingManagerImplTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/BindingManagerImplTest.java
|
| @@ -16,6 +16,8 @@ import android.test.suitebuilder.annotation.SmallTest;
|
| import android.util.Pair;
|
|
|
| import org.chromium.base.test.util.Feature;
|
| +import org.chromium.content.browser.test.util.Criteria;
|
| +import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.common.IChildProcessCallback;
|
| import org.chromium.content.common.IChildProcessService;
|
|
|
| @@ -530,13 +532,13 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
|
| */
|
| @SmallTest
|
| @Feature({"ProcessManagement"})
|
| - public void testModerateBindingDropOnLowMemory() {
|
| + public void testModerateBindingDropOnLowMemory() throws InterruptedException {
|
| final Application app =
|
| (Application) getInstrumentation().getTargetContext().getApplicationContext();
|
| // This test applies only to the moderate-binding manager.
|
| final BindingManagerImpl manager = mModerateBindingManager;
|
|
|
| - MockChildProcessConnection[] connections = new MockChildProcessConnection[4];
|
| + final MockChildProcessConnection[] connections = new MockChildProcessConnection[4];
|
| for (int i = 0; i < connections.length; i++) {
|
| connections[i] = new MockChildProcessConnection(i + 1);
|
| manager.addNewConnection(connections[i].getPid(), connections[i]);
|
| @@ -553,9 +555,16 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
|
|
|
| // Call onLowMemory() and verify that all the moderate bindings drop.
|
| app.onLowMemory();
|
| - for (MockChildProcessConnection connection : connections) {
|
| - assertFalse(connection.isModerateBindingBound());
|
| - }
|
| + assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + // Verify that some of moderate bindings drop.
|
| + for (MockChildProcessConnection connection : connections) {
|
| + if (connection.isModerateBindingBound()) return false;
|
| + }
|
| + return true;
|
| + }
|
| + }));
|
| }
|
|
|
| /**
|
| @@ -563,7 +572,7 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
|
| */
|
| @SmallTest
|
| @Feature({"ProcessManagement"})
|
| - public void testModerateBindingDropOnTrimMemory() {
|
| + public void testModerateBindingDropOnTrimMemory() throws InterruptedException {
|
| final Application app =
|
| (Application) getInstrumentation().getTargetContext().getApplicationContext();
|
| // This test applies only to the moderate-binding manager.
|
| @@ -577,13 +586,13 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
|
| levelAndExpectedVictimCountList.add(
|
| new Pair<Integer, Integer>(TRIM_MEMORY_RUNNING_CRITICAL, 4));
|
|
|
| - MockChildProcessConnection[] connections = new MockChildProcessConnection[4];
|
| + final MockChildProcessConnection[] connections = new MockChildProcessConnection[4];
|
| for (int i = 0; i < connections.length; i++) {
|
| connections[i] = new MockChildProcessConnection(i + 1);
|
| manager.addNewConnection(connections[i].getPid(), connections[i]);
|
| }
|
|
|
| - for (Pair<Integer, Integer> pair : levelAndExpectedVictimCountList) {
|
| + for (final Pair<Integer, Integer> pair : levelAndExpectedVictimCountList) {
|
| String message = "Failed for the level=" + pair.first;
|
| // Verify that each connection has a moderate binding after binding and releasing a
|
| // strong binding.
|
| @@ -595,10 +604,18 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
|
| }
|
|
|
| app.onTrimMemory(pair.first);
|
| - // Verify that some of moderate bindings drop.
|
| - for (int i = 0; i < connections.length; i++) {
|
| - assertEquals(message, i >= pair.second, connections[i].isModerateBindingBound());
|
| - }
|
| + assertTrue(message, CriteriaHelper.pollForCriteria(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + // Verify that some of moderate bindings drop.
|
| + for (int i = 0; i < connections.length; i++) {
|
| + if ((i >= pair.second) != connections[i].isModerateBindingBound()) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| + }
|
| + }));
|
| }
|
| }
|
|
|
|
|