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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/BindingManagerImplTest.java

Issue 1214193006: Delay cleanup of moderate bindings when the app goes to background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply Yaron's comments Created 5 years, 5 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 | « content/public/android/java/src/org/chromium/content/browser/BindingManagerImpl.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c7d0ce2ccfcb6da73ee494bb14abc572d1758df7..66ac30ec655b55155d80be46dad829a182649bcb 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
@@ -10,6 +10,7 @@ import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE;
import android.app.Application;
import android.os.Bundle;
+import android.os.SystemClock;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Pair;
@@ -458,7 +459,7 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
}
/**
- * Verifies that onSentToBackground() drops all the moderate bindings, and
+ * Verifies that onSentToBackground() drops all the moderate bindings after some delay, and
* onBroughtToForeground() doesn't recover them.
*/
@SmallTest
@@ -467,7 +468,7 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
// This test applies only to the moderate-binding manager.
final BindingManagerImpl manager = mModerateBindingManager;
- MockChildProcessConnection[] connections = new MockChildProcessConnection[4];
+ MockChildProcessConnection[] connections = new MockChildProcessConnection[3];
for (int i = 0; i < connections.length; i++) {
connections[i] = new MockChildProcessConnection(i + 1);
manager.addNewConnection(connections[i].getPid(), connections[i]);
@@ -482,9 +483,37 @@ public class BindingManagerImplTest extends InstrumentationTestCase {
assertTrue(connection.isModerateBindingBound());
}
- // Call onSentToBackground() and verify that all the moderate bindings drop.
+ // Exclude lastInForeground because it will be kept in foreground when onSentToBackground()
+ // is called as |mLastInForeground|.
+ MockChildProcessConnection lastInForeground = new MockChildProcessConnection(0);
+ manager.addNewConnection(lastInForeground.getPid(), lastInForeground);
+ manager.setInForeground(lastInForeground.getPid(), true);
+ manager.setInForeground(lastInForeground.getPid(), false);
+ getInstrumentation().waitForIdleSync();
+
+ // Verify that leaving the application for a short time doesn't clear the moderate bindings.
manager.onSentToBackground();
for (MockChildProcessConnection connection : connections) {
+ assertTrue(connection.isModerateBindingBound());
+ }
+ assertTrue(lastInForeground.isStrongBindingBound());
+ assertFalse(lastInForeground.isModerateBindingBound());
+ manager.onBroughtToForeground();
+ SystemClock.sleep(500);
+ for (MockChildProcessConnection connection : connections) {
+ assertTrue(connection.isModerateBindingBound());
+ }
+
+ // Call onSentToBackground() and verify that all the moderate bindings drop after some
+ // delay.
+ manager.onSentToBackground();
+ for (MockChildProcessConnection connection : connections) {
+ assertTrue(connection.isModerateBindingBound());
+ }
+ assertTrue(lastInForeground.isStrongBindingBound());
+ assertFalse(lastInForeground.isModerateBindingBound());
+ SystemClock.sleep(500);
+ for (MockChildProcessConnection connection : connections) {
assertFalse(connection.isModerateBindingBound());
}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/BindingManagerImpl.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698