| 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 |
| 11 import android.app.Activity; | 11 import android.app.Activity; |
| 12 import android.app.Application; | 12 import android.app.Application; |
| 13 import android.os.Bundle; | 13 import android.os.Bundle; |
| 14 import android.util.Pair; | 14 import android.util.Pair; |
| 15 | 15 |
| 16 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
| 17 import org.chromium.content.common.IChildProcessCallback; | 17 import org.chromium.content.common.IChildProcessCallback; |
| 18 import org.chromium.content.common.IChildProcessService; | 18 import org.chromium.content.common.IChildProcessService; |
| 19 import org.chromium.testing.local.LocalRobolectricTestRunner; | 19 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 20 import org.junit.Assert; | 20 import org.junit.Assert; |
| 21 import org.junit.Before; | 21 import org.junit.Before; |
| 22 import org.junit.Test; | 22 import org.junit.Test; |
| 23 import org.junit.runner.RunWith; | 23 import org.junit.runner.RunWith; |
| 24 import org.robolectric.Robolectric; | 24 import org.robolectric.Robolectric; |
| 25 import org.robolectric.annotation.Config; | 25 import org.robolectric.annotation.Config; |
| 26 import org.robolectric.shadows.ShadowLooper; |
| 26 | 27 |
| 27 import java.util.ArrayList; | 28 import java.util.ArrayList; |
| 28 | 29 |
| 29 /** | 30 /** |
| 30 * Unit tests for BindingManagerImpl. The tests run agains mock ChildProcessConn
ection | 31 * Unit tests for BindingManagerImpl. The tests run agains mock ChildProcessConn
ection |
| 31 * implementation, thus testing only the BindingManagerImpl itself. | 32 * implementation, thus testing only the BindingManagerImpl itself. |
| 32 * | 33 * |
| 33 * Default property of being low-end device is overriden, so that both low-end a
nd high-end policies | 34 * Default property of being low-end device is overriden, so that both low-end a
nd high-end policies |
| 34 * are tested. | 35 * are tested. |
| 35 */ | 36 */ |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 Assert.assertTrue(connection.isInitialBindingBound()); | 272 Assert.assertTrue(connection.isInitialBindingBound()); |
| 272 | 273 |
| 273 // Remove the strong binding, verify that the strong binding is not remo
ved | 274 // Remove the strong binding, verify that the strong binding is not remo
ved |
| 274 // immediately. | 275 // immediately. |
| 275 manager.setInForeground(connection.getPid(), false); | 276 manager.setInForeground(connection.getPid(), false); |
| 276 Assert.assertTrue(connection.isStrongBindingBound()); | 277 Assert.assertTrue(connection.isStrongBindingBound()); |
| 277 Assert.assertTrue(connection.isInitialBindingBound()); | 278 Assert.assertTrue(connection.isInitialBindingBound()); |
| 278 | 279 |
| 279 // Wait until the posted unbinding tasks get executed and verify that th
e strong binding was | 280 // Wait until the posted unbinding tasks get executed and verify that th
e strong binding was |
| 280 // removed while the initial binding is not affected. | 281 // removed while the initial binding is not affected. |
| 281 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 282 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 282 Assert.assertFalse(connection.isStrongBindingBound()); | 283 Assert.assertFalse(connection.isStrongBindingBound()); |
| 283 Assert.assertTrue(connection.isInitialBindingBound()); | 284 Assert.assertTrue(connection.isInitialBindingBound()); |
| 284 } | 285 } |
| 285 | 286 |
| 286 /** | 287 /** |
| 287 * Verifies the strong binding removal policies with moderate binding manage
ment, where the | 288 * Verifies the strong binding removal policies with moderate binding manage
ment, where the |
| 288 * moderate binding should be bound. | 289 * moderate binding should be bound. |
| 289 */ | 290 */ |
| 290 @Test | 291 @Test |
| 291 @Feature({"ProcessManagement"}) | 292 @Feature({"ProcessManagement"}) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 308 | 309 |
| 309 // Remove the strong binding, verify that the strong binding is not remo
ved | 310 // Remove the strong binding, verify that the strong binding is not remo
ved |
| 310 // immediately. | 311 // immediately. |
| 311 manager.setInForeground(connection.getPid(), false); | 312 manager.setInForeground(connection.getPid(), false); |
| 312 Assert.assertTrue(connection.isStrongBindingBound()); | 313 Assert.assertTrue(connection.isStrongBindingBound()); |
| 313 Assert.assertTrue(connection.isInitialBindingBound()); | 314 Assert.assertTrue(connection.isInitialBindingBound()); |
| 314 Assert.assertFalse(connection.isModerateBindingBound()); | 315 Assert.assertFalse(connection.isModerateBindingBound()); |
| 315 | 316 |
| 316 // Wait until the posted unbinding tasks get executed and verify that th
e strong binding was | 317 // Wait until the posted unbinding tasks get executed and verify that th
e strong binding was |
| 317 // removed while the initial binding is not affected, and the moderate b
inding is bound. | 318 // removed while the initial binding is not affected, and the moderate b
inding is bound. |
| 318 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 319 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 319 Assert.assertFalse(connection.isStrongBindingBound()); | 320 Assert.assertFalse(connection.isStrongBindingBound()); |
| 320 Assert.assertTrue(connection.isInitialBindingBound()); | 321 Assert.assertTrue(connection.isInitialBindingBound()); |
| 321 Assert.assertTrue(connection.isModerateBindingBound()); | 322 Assert.assertTrue(connection.isModerateBindingBound()); |
| 322 } | 323 } |
| 323 | 324 |
| 324 /** | 325 /** |
| 325 * Verifies that the initial binding is removed after determinedVisibility()
is called. | 326 * Verifies that the initial binding is removed after determinedVisibility()
is called. |
| 326 */ | 327 */ |
| 327 @Test | 328 @Test |
| 328 @Feature({"ProcessManagement"}) | 329 @Feature({"ProcessManagement"}) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // Add a connection to the manager. | 366 // Add a connection to the manager. |
| 366 MockChildProcessConnection connection = new MockChildProcessConnecti
on(1); | 367 MockChildProcessConnection connection = new MockChildProcessConnecti
on(1); |
| 367 manager.addNewConnection(connection.getPid(), connection); | 368 manager.addNewConnection(connection.getPid(), connection); |
| 368 | 369 |
| 369 // Initial binding is an oom binding. | 370 // Initial binding is an oom binding. |
| 370 Assert.assertTrue(message, manager.isOomProtected(connection.getPid(
))); | 371 Assert.assertTrue(message, manager.isOomProtected(connection.getPid(
))); |
| 371 | 372 |
| 372 // After initial binding is removed, the connection is no longer oom
protected. | 373 // After initial binding is removed, the connection is no longer oom
protected. |
| 373 manager.setInForeground(connection.getPid(), false); | 374 manager.setInForeground(connection.getPid(), false); |
| 374 manager.determinedVisibility(connection.getPid()); | 375 manager.determinedVisibility(connection.getPid()); |
| 375 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 376 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 376 Assert.assertFalse(message, manager.isOomProtected(connection.getPid
())); | 377 Assert.assertFalse(message, manager.isOomProtected(connection.getPid
())); |
| 377 | 378 |
| 378 // Add a strong binding, restoring the oom protection. | 379 // Add a strong binding, restoring the oom protection. |
| 379 manager.setInForeground(connection.getPid(), true); | 380 manager.setInForeground(connection.getPid(), true); |
| 380 Assert.assertTrue(message, manager.isOomProtected(connection.getPid(
))); | 381 Assert.assertTrue(message, manager.isOomProtected(connection.getPid(
))); |
| 381 | 382 |
| 382 // Simulate a process crash - clear a connection in binding manager
and remove the | 383 // Simulate a process crash - clear a connection in binding manager
and remove the |
| 383 // bindings. | 384 // bindings. |
| 384 Assert.assertFalse(manager.isConnectionCleared(connection.getPid()))
; | 385 Assert.assertFalse(manager.isConnectionCleared(connection.getPid()))
; |
| 385 manager.clearConnection(connection.getPid()); | 386 manager.clearConnection(connection.getPid()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 manager.addNewConnection(secondConnection.getPid(), secondConnection
); | 423 manager.addNewConnection(secondConnection.getPid(), secondConnection
); |
| 423 manager.setInForeground(secondConnection.getPid(), true); | 424 manager.setInForeground(secondConnection.getPid(), true); |
| 424 manager.setInForeground(secondConnection.getPid(), false); | 425 manager.setInForeground(secondConnection.getPid(), false); |
| 425 | 426 |
| 426 // Add third connection, do not bind it. | 427 // Add third connection, do not bind it. |
| 427 MockChildProcessConnection thirdConnection = new MockChildProcessCon
nection(3); | 428 MockChildProcessConnection thirdConnection = new MockChildProcessCon
nection(3); |
| 428 manager.addNewConnection(thirdConnection.getPid(), thirdConnection); | 429 manager.addNewConnection(thirdConnection.getPid(), thirdConnection); |
| 429 manager.setInForeground(thirdConnection.getPid(), false); | 430 manager.setInForeground(thirdConnection.getPid(), false); |
| 430 | 431 |
| 431 // Sanity check: verify that no connection has a strong binding. | 432 // Sanity check: verify that no connection has a strong binding. |
| 432 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 433 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 433 Assert.assertFalse(message, firstConnection.isStrongBindingBound()); | 434 Assert.assertFalse(message, firstConnection.isStrongBindingBound()); |
| 434 Assert.assertFalse(message, secondConnection.isStrongBindingBound())
; | 435 Assert.assertFalse(message, secondConnection.isStrongBindingBound())
; |
| 435 Assert.assertFalse(message, thirdConnection.isStrongBindingBound()); | 436 Assert.assertFalse(message, thirdConnection.isStrongBindingBound()); |
| 436 | 437 |
| 437 // Call onSentToBackground() and verify that a strong binding was ad
ded for the second | 438 // Call onSentToBackground() and verify that a strong binding was ad
ded for the second |
| 438 // connection: | 439 // connection: |
| 439 // - not the first one, because it was bound earlier than the second | 440 // - not the first one, because it was bound earlier than the second |
| 440 // - not the thirs one, because it was never bound at all | 441 // - not the thirs one, because it was never bound at all |
| 441 manager.onSentToBackground(); | 442 manager.onSentToBackground(); |
| 442 Assert.assertFalse(message, firstConnection.isStrongBindingBound()); | 443 Assert.assertFalse(message, firstConnection.isStrongBindingBound()); |
| 443 Assert.assertTrue(message, secondConnection.isStrongBindingBound()); | 444 Assert.assertTrue(message, secondConnection.isStrongBindingBound()); |
| 444 Assert.assertFalse(message, thirdConnection.isStrongBindingBound()); | 445 Assert.assertFalse(message, thirdConnection.isStrongBindingBound()); |
| 445 | 446 |
| 446 // Call onBroughtToForeground() and verify that the strong binding w
as removed. | 447 // Call onBroughtToForeground() and verify that the strong binding w
as removed. |
| 447 manager.onBroughtToForeground(); | 448 manager.onBroughtToForeground(); |
| 448 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 449 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 449 Assert.assertFalse(message, firstConnection.isStrongBindingBound()); | 450 Assert.assertFalse(message, firstConnection.isStrongBindingBound()); |
| 450 Assert.assertFalse(message, secondConnection.isStrongBindingBound())
; | 451 Assert.assertFalse(message, secondConnection.isStrongBindingBound())
; |
| 451 Assert.assertFalse(message, thirdConnection.isStrongBindingBound()); | 452 Assert.assertFalse(message, thirdConnection.isStrongBindingBound()); |
| 452 } | 453 } |
| 453 } | 454 } |
| 454 | 455 |
| 455 /** | 456 /** |
| 456 * Verifies that onSentToBackground() drops all the moderate bindings after
some delay, and | 457 * Verifies that onSentToBackground() drops all the moderate bindings after
some delay, and |
| 457 * onBroughtToForeground() doesn't recover them. | 458 * onBroughtToForeground() doesn't recover them. |
| 458 */ | 459 */ |
| 459 @Test | 460 @Test |
| 460 @Feature({"ProcessManagement"}) | 461 @Feature({"ProcessManagement"}) |
| 461 public void testModerateBindingDropOnBackground() { | 462 public void testModerateBindingDropOnBackground() { |
| 462 // This test applies only to the moderate-binding manager. | 463 // This test applies only to the moderate-binding manager. |
| 463 final BindingManagerImpl manager = mModerateBindingManager; | 464 final BindingManagerImpl manager = mModerateBindingManager; |
| 464 | 465 |
| 465 MockChildProcessConnection[] connections = new MockChildProcessConnectio
n[3]; | 466 MockChildProcessConnection[] connections = new MockChildProcessConnectio
n[3]; |
| 466 for (int i = 0; i < connections.length; i++) { | 467 for (int i = 0; i < connections.length; i++) { |
| 467 connections[i] = new MockChildProcessConnection(i + 1); | 468 connections[i] = new MockChildProcessConnection(i + 1); |
| 468 manager.addNewConnection(connections[i].getPid(), connections[i]); | 469 manager.addNewConnection(connections[i].getPid(), connections[i]); |
| 469 } | 470 } |
| 470 | 471 |
| 471 // Verify that each connection has a moderate binding after binding and
releasing a strong | 472 // Verify that each connection has a moderate binding after binding and
releasing a strong |
| 472 // binding. | 473 // binding. |
| 473 for (MockChildProcessConnection connection : connections) { | 474 for (MockChildProcessConnection connection : connections) { |
| 474 manager.setInForeground(connection.getPid(), true); | 475 manager.setInForeground(connection.getPid(), true); |
| 475 manager.setInForeground(connection.getPid(), false); | 476 manager.setInForeground(connection.getPid(), false); |
| 476 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 477 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 477 Assert.assertTrue(connection.isModerateBindingBound()); | 478 Assert.assertTrue(connection.isModerateBindingBound()); |
| 478 } | 479 } |
| 479 | 480 |
| 480 // Exclude lastInForeground because it will be kept in foreground when o
nSentToBackground() | 481 // Exclude lastInForeground because it will be kept in foreground when o
nSentToBackground() |
| 481 // is called as |mLastInForeground|. | 482 // is called as |mLastInForeground|. |
| 482 MockChildProcessConnection lastInForeground = new MockChildProcessConnec
tion(0); | 483 MockChildProcessConnection lastInForeground = new MockChildProcessConnec
tion(0); |
| 483 manager.addNewConnection(lastInForeground.getPid(), lastInForeground); | 484 manager.addNewConnection(lastInForeground.getPid(), lastInForeground); |
| 484 manager.setInForeground(lastInForeground.getPid(), true); | 485 manager.setInForeground(lastInForeground.getPid(), true); |
| 485 manager.setInForeground(lastInForeground.getPid(), false); | 486 manager.setInForeground(lastInForeground.getPid(), false); |
| 486 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 487 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 487 | 488 |
| 488 // Verify that leaving the application for a short time doesn't clear th
e moderate bindings. | 489 // Verify that leaving the application for a short time doesn't clear th
e moderate bindings. |
| 489 manager.onSentToBackground(); | 490 manager.onSentToBackground(); |
| 490 for (MockChildProcessConnection connection : connections) { | 491 for (MockChildProcessConnection connection : connections) { |
| 491 Assert.assertTrue(connection.isModerateBindingBound()); | 492 Assert.assertTrue(connection.isModerateBindingBound()); |
| 492 } | 493 } |
| 493 Assert.assertTrue(lastInForeground.isStrongBindingBound()); | 494 Assert.assertTrue(lastInForeground.isStrongBindingBound()); |
| 494 Assert.assertFalse(lastInForeground.isModerateBindingBound()); | 495 Assert.assertFalse(lastInForeground.isModerateBindingBound()); |
| 495 manager.onBroughtToForeground(); | 496 manager.onBroughtToForeground(); |
| 496 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 497 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 497 for (MockChildProcessConnection connection : connections) { | 498 for (MockChildProcessConnection connection : connections) { |
| 498 Assert.assertTrue(connection.isModerateBindingBound()); | 499 Assert.assertTrue(connection.isModerateBindingBound()); |
| 499 } | 500 } |
| 500 | 501 |
| 501 // Call onSentToBackground() and verify that all the moderate bindings d
rop after some | 502 // Call onSentToBackground() and verify that all the moderate bindings d
rop after some |
| 502 // delay. | 503 // delay. |
| 503 manager.onSentToBackground(); | 504 manager.onSentToBackground(); |
| 504 for (MockChildProcessConnection connection : connections) { | 505 for (MockChildProcessConnection connection : connections) { |
| 505 Assert.assertTrue(connection.isModerateBindingBound()); | 506 Assert.assertTrue(connection.isModerateBindingBound()); |
| 506 } | 507 } |
| 507 Assert.assertTrue(lastInForeground.isStrongBindingBound()); | 508 Assert.assertTrue(lastInForeground.isStrongBindingBound()); |
| 508 Assert.assertFalse(lastInForeground.isModerateBindingBound()); | 509 Assert.assertFalse(lastInForeground.isModerateBindingBound()); |
| 509 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 510 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 510 for (MockChildProcessConnection connection : connections) { | 511 for (MockChildProcessConnection connection : connections) { |
| 511 Assert.assertFalse(connection.isModerateBindingBound()); | 512 Assert.assertFalse(connection.isModerateBindingBound()); |
| 512 } | 513 } |
| 513 | 514 |
| 514 // Call onBroughtToForeground() and verify that the previous moderate bi
ndings aren't | 515 // Call onBroughtToForeground() and verify that the previous moderate bi
ndings aren't |
| 515 // recovered. | 516 // recovered. |
| 516 manager.onBroughtToForeground(); | 517 manager.onBroughtToForeground(); |
| 517 for (MockChildProcessConnection connection : connections) { | 518 for (MockChildProcessConnection connection : connections) { |
| 518 Assert.assertFalse(connection.isModerateBindingBound()); | 519 Assert.assertFalse(connection.isModerateBindingBound()); |
| 519 } | 520 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 532 for (int i = 0; i < connections.length; i++) { | 533 for (int i = 0; i < connections.length; i++) { |
| 533 connections[i] = new MockChildProcessConnection(i + 1); | 534 connections[i] = new MockChildProcessConnection(i + 1); |
| 534 manager.addNewConnection(connections[i].getPid(), connections[i]); | 535 manager.addNewConnection(connections[i].getPid(), connections[i]); |
| 535 } | 536 } |
| 536 | 537 |
| 537 // Verify that each connection has a moderate binding after binding and
releasing a strong | 538 // Verify that each connection has a moderate binding after binding and
releasing a strong |
| 538 // binding. | 539 // binding. |
| 539 for (MockChildProcessConnection connection : connections) { | 540 for (MockChildProcessConnection connection : connections) { |
| 540 manager.setInForeground(connection.getPid(), true); | 541 manager.setInForeground(connection.getPid(), true); |
| 541 manager.setInForeground(connection.getPid(), false); | 542 manager.setInForeground(connection.getPid(), false); |
| 542 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 543 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 543 Assert.assertTrue(connection.isModerateBindingBound()); | 544 Assert.assertTrue(connection.isModerateBindingBound()); |
| 544 } | 545 } |
| 545 | 546 |
| 546 // Call onLowMemory() and verify that all the moderate bindings drop. | 547 // Call onLowMemory() and verify that all the moderate bindings drop. |
| 547 app.onLowMemory(); | 548 app.onLowMemory(); |
| 548 for (MockChildProcessConnection connection : connections) { | 549 for (MockChildProcessConnection connection : connections) { |
| 549 Assert.assertFalse(connection.isModerateBindingBound()); | 550 Assert.assertFalse(connection.isModerateBindingBound()); |
| 550 } | 551 } |
| 551 } | 552 } |
| 552 | 553 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 574 manager.addNewConnection(connections[i].getPid(), connections[i]); | 575 manager.addNewConnection(connections[i].getPid(), connections[i]); |
| 575 } | 576 } |
| 576 | 577 |
| 577 for (Pair<Integer, Integer> pair : levelAndExpectedVictimCountList) { | 578 for (Pair<Integer, Integer> pair : levelAndExpectedVictimCountList) { |
| 578 String message = "Failed for the level=" + pair.first; | 579 String message = "Failed for the level=" + pair.first; |
| 579 // Verify that each connection has a moderate binding after binding
and releasing a | 580 // Verify that each connection has a moderate binding after binding
and releasing a |
| 580 // strong binding. | 581 // strong binding. |
| 581 for (MockChildProcessConnection connection : connections) { | 582 for (MockChildProcessConnection connection : connections) { |
| 582 manager.setInForeground(connection.getPid(), true); | 583 manager.setInForeground(connection.getPid(), true); |
| 583 manager.setInForeground(connection.getPid(), false); | 584 manager.setInForeground(connection.getPid(), false); |
| 584 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 585 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 585 Assert.assertTrue(message, connection.isModerateBindingBound()); | 586 Assert.assertTrue(message, connection.isModerateBindingBound()); |
| 586 } | 587 } |
| 587 | 588 |
| 588 app.onTrimMemory(pair.first); | 589 app.onTrimMemory(pair.first); |
| 589 // Verify that some of moderate bindings drop. | 590 // Verify that some of moderate bindings drop. |
| 590 for (int i = 0; i < connections.length; i++) { | 591 for (int i = 0; i < connections.length; i++) { |
| 591 Assert.assertEquals( | 592 Assert.assertEquals( |
| 592 message, i >= pair.second, connections[i].isModerateBind
ingBound()); | 593 message, i >= pair.second, connections[i].isModerateBind
ingBound()); |
| 593 } | 594 } |
| 594 } | 595 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 607 for (int i = 0; i < connections.length; i++) { | 608 for (int i = 0; i < connections.length; i++) { |
| 608 connections[i] = new MockChildProcessConnection(i + 1); | 609 connections[i] = new MockChildProcessConnection(i + 1); |
| 609 manager.addNewConnection(connections[i].getPid(), connections[i]); | 610 manager.addNewConnection(connections[i].getPid(), connections[i]); |
| 610 } | 611 } |
| 611 | 612 |
| 612 // Verify that each connection has a moderate binding after binding and
releasing a strong | 613 // Verify that each connection has a moderate binding after binding and
releasing a strong |
| 613 // binding. | 614 // binding. |
| 614 for (MockChildProcessConnection connection : connections) { | 615 for (MockChildProcessConnection connection : connections) { |
| 615 manager.setInForeground(connection.getPid(), true); | 616 manager.setInForeground(connection.getPid(), true); |
| 616 manager.setInForeground(connection.getPid(), false); | 617 manager.setInForeground(connection.getPid(), false); |
| 617 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 618 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 618 Assert.assertTrue(connection.isModerateBindingBound()); | 619 Assert.assertTrue(connection.isModerateBindingBound()); |
| 619 } | 620 } |
| 620 | 621 |
| 621 // Call BindingManager.releaseAllModerateBindings() and verify that all
the moderate | 622 // Call BindingManager.releaseAllModerateBindings() and verify that all
the moderate |
| 622 // bindings drop. | 623 // bindings drop. |
| 623 manager.releaseAllModerateBindings(); | 624 manager.releaseAllModerateBindings(); |
| 624 for (MockChildProcessConnection connection : connections) { | 625 for (MockChildProcessConnection connection : connections) { |
| 625 Assert.assertFalse(connection.isModerateBindingBound()); | 626 Assert.assertFalse(connection.isModerateBindingBound()); |
| 626 } | 627 } |
| 627 } | 628 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 BindingManagerImpl manager = BindingManagerImpl.createBindingManagerForT
esting(false); | 704 BindingManagerImpl manager = BindingManagerImpl.createBindingManagerForT
esting(false); |
| 704 manager.startModerateBindingManagement(mActivity, 4, true); | 705 manager.startModerateBindingManagement(mActivity, 4, true); |
| 705 | 706 |
| 706 MockChildProcessConnection connection = new MockChildProcessConnection(0
); | 707 MockChildProcessConnection connection = new MockChildProcessConnection(0
); |
| 707 manager.addNewConnection(connection.getPid(), connection); | 708 manager.addNewConnection(connection.getPid(), connection); |
| 708 manager.setInForeground(connection.getPid(), false); | 709 manager.setInForeground(connection.getPid(), false); |
| 709 manager.determinedVisibility(connection.getPid()); | 710 manager.determinedVisibility(connection.getPid()); |
| 710 Assert.assertTrue(connection.isModerateBindingBound()); | 711 Assert.assertTrue(connection.isModerateBindingBound()); |
| 711 | 712 |
| 712 manager.onSentToBackground(); | 713 manager.onSentToBackground(); |
| 713 Robolectric.runUiThreadTasksIncludingDelayedTasks(); | 714 ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
| 714 Assert.assertFalse(connection.isModerateBindingBound()); | 715 Assert.assertFalse(connection.isModerateBindingBound()); |
| 715 | 716 |
| 716 // Bringing Chrome to the foreground should not re-add the moderate bind
ings. | 717 // Bringing Chrome to the foreground should not re-add the moderate bind
ings. |
| 717 manager.onBroughtToForeground(); | 718 manager.onBroughtToForeground(); |
| 718 Assert.assertFalse(connection.isModerateBindingBound()); | 719 Assert.assertFalse(connection.isModerateBindingBound()); |
| 719 } | 720 } |
| 720 } | 721 } |
| OLD | NEW |