Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1921)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/BindingManagerIntegrationTest.java

Issue 1874783002: Test FG/BG call order on Android. Base URL: https://chromium.googlesource.com/chromium/src.git@a1_disable_startup_prio_default
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/BindingManagerIntegrationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/BindingManagerIntegrationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/BindingManagerIntegrationTest.java
index d686a4949884ebd1e7bb3579199479d1c4ef9383..d394366c8131ffe84f58ba2de4c81cbb20be4c7f 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/BindingManagerIntegrationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BindingManagerIntegrationTest.java
@@ -46,44 +46,18 @@ import java.util.concurrent.Callable;
public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<ChromeActivity> {
private static class MockBindingManager implements BindingManager {
- // Maps pid to the last received visibility state of the renderer.
- private final SparseBooleanArray mProcessInForegroundMap = new SparseBooleanArray();
+ // Maps pid to a string recording calls to setInForeground().
+ private final SparseBooleanArray mProcessPriorityCalls = new SparseBooleanArray();
// Maps pid to a string recording calls to setInForeground() and visibilityDetermined().
private final SparseArray<String> mVisibilityCallsMap = new SparseArray<String>();
private boolean mIsReleaseAllModerateBindingsCalled;
- void assertIsInForeground(final int pid) {
- try {
- CriteriaHelper.pollInstrumentationThread(new Criteria() {
- @Override
- public boolean isSatisfied() {
- return mProcessInForegroundMap.get(pid);
- }
- });
- } catch (InterruptedException ie) {
- fail();
- }
- }
-
- void assertIsInBackground(final int pid) {
+ void assertIsReleaseAllModerateBindingsCalled() {
try {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
- return !mProcessInForegroundMap.get(pid);
- }
- });
- } catch (InterruptedException ie) {
- fail();
- }
- }
-
- void assertSetInForegroundWasCalled(String message, final int pid) {
- try {
- CriteriaHelper.pollInstrumentationThread(new Criteria(message) {
- @Override
- public boolean isSatisfied() {
- return mProcessInForegroundMap.indexOfKey(pid) >= 0;
+ return mIsReleaseAllModerateBindingsCalled;
}
});
} catch (InterruptedException ie) {
@@ -91,16 +65,9 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
}
}
- void assertIsReleaseAllModerateBindingsCalled() {
- try {
- CriteriaHelper.pollInstrumentationThread(new Criteria() {
- @Override
- public boolean isSatisfied() {
- return mIsReleaseAllModerateBindingsCalled;
- }
- });
- } catch (InterruptedException ie) {
- fail();
+ String getProcessPriorityCalls(int pid) {
+ synchronized (mVisibilityCallsMap) {
+ return mProcessPriorityCalls.get(pid);
}
}
@@ -123,7 +90,13 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
@Override
public void setInForeground(int pid, boolean inForeground) {
- mProcessInForegroundMap.put(pid, inForeground);
+ synchronized (mProcessPriorityCalls) {
+ if (inForeground) {
+ mProcessPriorityCalls.put(pid, mProcessPriorityCalls.get(pid) + "FG;");
+ } else {
+ mProcessPriorityCalls.put(pid, mProcessPriorityCalls.get(pid) + "BG;");
+ }
+ }
synchronized (mVisibilityCallsMap) {
if (inForeground) {
@@ -231,19 +204,21 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
assertTrue(tabs[1].getContentViewCore().getCurrentRenderProcessId() > 0);
// Verify that the renderer of the foreground tab was signalled as visible.
- mBindingManager.assertIsInForeground(
- tabs[0].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[0].getContentViewCore().getCurrentRenderProcessId()));
+
+
// Verify that the renderer of the tab loaded in background was signalled as not
// visible.
- mBindingManager.assertIsInBackground(
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("BG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId()));
+
// Select tabs[1] and verify that the renderer visibility was flipped.
TabModelUtils.setIndex(getActivity().getCurrentTabModel(), indexOf(tabs[1]));
- mBindingManager.assertIsInBackground(
- tabs[0].getContentViewCore().getCurrentRenderProcessId());
- mBindingManager.assertIsInForeground(
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("BG;", mBindingManager.getProcessPriorityCalls(tabs[0].getContentViewCore().getCurrentRenderProcessId()));
+
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId()));
+
+
}
});
}
@@ -302,12 +277,13 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
assertTrue(tabs[1].getContentViewCore().getCurrentRenderProcessId() > 0);
// Verify that the renderer of the foreground tab was signalled as visible.
- mBindingManager.assertIsInForeground(
- tabs[0].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[0].getContentViewCore().getCurrentRenderProcessId()));
+
+
// Verify that the renderer of the tab loaded in background was signalled as not
// visible.
- mBindingManager.assertIsInBackground(
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("BG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId()));
+
}
});
@@ -340,18 +316,17 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
}
});
- mBindingManager.assertSetInForegroundWasCalled(
- "isInForeground() was not called for the process.",
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId();
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
// Verify the visibility of the renderers.
- mBindingManager.assertIsInBackground(
- tabs[0].getContentViewCore().getCurrentRenderProcessId());
- mBindingManager.assertIsInForeground(
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("BG;", mBindingManager.getProcessPriorityCalls(tabs[0].getContentViewCore().getCurrentRenderProcessId()));
+
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId()));
+
+
}
});
}
@@ -406,16 +381,13 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
}
});
- mBindingManager.assertSetInForegroundWasCalled(
- "isInForeground() was not called for the process.",
- tab.getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tab.getContentViewCore().getCurrentRenderProcessId()));
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
// Verify the visibility of the renderer.
- mBindingManager.assertIsInForeground(
- tab.getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(()));
}
});
}
@@ -464,7 +436,8 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
// - DETERMINED - visibilityDetermined() - after the navigation is committed
// Or BG -> DETERMINED -> FG is also possible because setInForeground() and
// visibilityDetermined() are triggered from different threads.
- mBindingManager.assertIsInForeground(secondNavigationPid);
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(secondNavigationPid));
+
String visibilityCalls = mBindingManager.getVisibilityCalls(secondNavigationPid);
assertTrue(visibilityCalls, "BG;FG;DETERMINED;".equals(visibilityCalls)
|| "BG;DETERMINED;FG;".equals(visibilityCalls));
@@ -586,8 +559,9 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
@Override
public void run() {
// Verify the visibility of the renderer.
- mBindingManager.assertIsInForeground(
- tabs[0].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[0].getContentViewCore().getCurrentRenderProcessId()));
+
+
}
});
@@ -618,19 +592,18 @@ public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
}
});
- mBindingManager.assertSetInForegroundWasCalled(
- "setInForeground() was not called for the process.",
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId();
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
// Verify the visibility of the renderer.
- mBindingManager.assertIsInForeground(
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("FG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId()));
+
+
tabs[1].hide();
- mBindingManager.assertIsInBackground(
- tabs[1].getContentViewCore().getCurrentRenderProcessId());
+ assertEquals("BG;", mBindingManager.getProcessPriorityCalls(tabs[1].getContentViewCore().getCurrentRenderProcessId()));
+
}
});
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698