| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL; | 7 import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL; |
| 8 import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; | 8 import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; |
| 9 import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE; | 9 import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE; |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 private static class TestChildProcessConnection extends ManagedChildProcessC
onnection { | 61 private static class TestChildProcessConnection extends ManagedChildProcessC
onnection { |
| 62 private final int mPid; | 62 private final int mPid; |
| 63 private boolean mConnected; | 63 private boolean mConnected; |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Creates a mock binding corresponding to real ManagedChildProcessConne
ction after the | 66 * Creates a mock binding corresponding to real ManagedChildProcessConne
ction after the |
| 67 * connection is established: with initial binding bound and no strong b
inding. | 67 * connection is established: with initial binding bound and no strong b
inding. |
| 68 */ | 68 */ |
| 69 private TestChildProcessConnection(int pid) { | 69 private TestChildProcessConnection(int pid) { |
| 70 super(null /* context */, pid /* number */, true /* sandboxed */, | 70 super(null /* context */, true /* sandboxed */, null /* deathCallbac
k */, |
| 71 null /* deathCallback */, null /* serviceClassName */, | 71 "TestService" /* serviceClassName */, null /* childProcessCo
mmonParameters */, |
| 72 null /* childProcessCommonParameters */, | |
| 73 new ChildProcessCreationParams("org.chromium.test", | 72 new ChildProcessCreationParams("org.chromium.test", |
| 74 false /* isExternalService */, 0 /* libraryProcessTy
pe */, | 73 false /* isExternalService */, 0 /* libraryProcessTy
pe */, |
| 75 false /* bindToCallerCheck */)); | 74 false /* bindToCallerCheck */)); |
| 76 mPid = pid; | 75 mPid = pid; |
| 77 } | 76 } |
| 78 | 77 |
| 79 @Override | 78 @Override |
| 80 public int getPid() { | 79 public int getPid() { |
| 81 return mPid; | 80 return mPid; |
| 82 } | 81 } |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // Verify that each connection has a moderate binding after binding
and releasing a | 558 // Verify that each connection has a moderate binding after binding
and releasing a |
| 560 // strong binding. | 559 // strong binding. |
| 561 for (TestChildProcessConnection connection : connections) { | 560 for (TestChildProcessConnection connection : connections) { |
| 562 manager.setInForeground(connection.getPid(), true); | 561 manager.setInForeground(connection.getPid(), true); |
| 563 manager.setInForeground(connection.getPid(), false); | 562 manager.setInForeground(connection.getPid(), false); |
| 564 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); | 563 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 565 Assert.assertTrue(message, connection.isModerateBindingBound()); | 564 Assert.assertTrue(message, connection.isModerateBindingBound()); |
| 566 } | 565 } |
| 567 | 566 |
| 568 app.onTrimMemory(pair.first); | 567 app.onTrimMemory(pair.first); |
| 569 // Verify that some of moderate bindings drop. | 568 // Verify that some of the moderate bindings have been dropped. |
| 570 for (int i = 0; i < connections.length; i++) { | 569 for (int i = 0; i < connections.length; i++) { |
| 571 Assert.assertEquals( | 570 Assert.assertEquals( |
| 572 message, i >= pair.second, connections[i].isModerateBind
ingBound()); | 571 message, i >= pair.second, connections[i].isModerateBind
ingBound()); |
| 573 } | 572 } |
| 574 } | 573 } |
| 575 } | 574 } |
| 576 | 575 |
| 577 /** | 576 /** |
| 578 * Verifies that BindingManager.releaseAllModerateBindings() drops all the m
oderate bindings. | 577 * Verifies that BindingManager.releaseAllModerateBindings() drops all the m
oderate bindings. |
| 579 */ | 578 */ |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 671 |
| 673 manager.onSentToBackground(); | 672 manager.onSentToBackground(); |
| 674 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); | 673 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 675 Assert.assertFalse(connection.isModerateBindingBound()); | 674 Assert.assertFalse(connection.isModerateBindingBound()); |
| 676 | 675 |
| 677 // Bringing Chrome to the foreground should not re-add the moderate bind
ings. | 676 // Bringing Chrome to the foreground should not re-add the moderate bind
ings. |
| 678 manager.onBroughtToForeground(); | 677 manager.onBroughtToForeground(); |
| 679 Assert.assertFalse(connection.isModerateBindingBound()); | 678 Assert.assertFalse(connection.isModerateBindingBound()); |
| 680 } | 679 } |
| 681 } | 680 } |
| OLD | NEW |