forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Add CollectionUtil.strengthen() helper
Abstracts the pattern of looping over weak references and removing stale ones. * Converts UnownedUserDataKey to use WeakSet since order does not matter. TBR=agrieve # Trivial refactor in AutofillManagerWrapper.java Bug: 1131047 Change-Id: Idf226faecb31de69f7b7bbae32d6c795dca3dca2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477050 Commit-Queue: Andrew Grieve <agrieve@chromium.org> Reviewed-by: Tommy Nyquist <nyquist@chromium.org> Cr-Commit-Position: refs/heads/master@{#819407}
- Loading branch information
Showing
8 changed files
with
97 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
base/android/junit/src/org/chromium/base/CollectionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.base; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.annotation.Config; | ||
|
||
import org.chromium.base.test.BaseRobolectricTestRunner; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/** Unit tests for {@link Log}. */ | ||
@RunWith(BaseRobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class CollectionUtilTest { | ||
/** Tests that the computed call origin is the correct one. */ | ||
@Test | ||
public void testStrengthen() { | ||
// Java never GC's small constants, so there's no risk of the weak refs becoming null. | ||
ArrayList<WeakReference<Integer>> weakList = new ArrayList<>(); | ||
weakList.add(new WeakReference<>(0)); | ||
weakList.add(new WeakReference<>(1)); | ||
weakList.add(new WeakReference<>(2)); | ||
|
||
assertEquals(Arrays.asList(0, 1, 2), CollectionUtil.strengthen(weakList)); | ||
|
||
weakList.set(1, new WeakReference<>(null)); | ||
assertEquals(Arrays.asList(0, 2), CollectionUtil.strengthen(weakList)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters