diff options
Diffstat (limited to 'chromium/base/android/junit/src/org/chromium/base/util/GarbageCollectionTestUtilsUnitTest.java')
-rw-r--r-- | chromium/base/android/junit/src/org/chromium/base/util/GarbageCollectionTestUtilsUnitTest.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/chromium/base/android/junit/src/org/chromium/base/util/GarbageCollectionTestUtilsUnitTest.java b/chromium/base/android/junit/src/org/chromium/base/util/GarbageCollectionTestUtilsUnitTest.java new file mode 100644 index 00000000000..29e1f831bfc --- /dev/null +++ b/chromium/base/android/junit/src/org/chromium/base/util/GarbageCollectionTestUtilsUnitTest.java @@ -0,0 +1,40 @@ +// Copyright 2019 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.base.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import static org.chromium.base.GarbageCollectionTestUtils.canBeGarbageCollected; + +import android.graphics.Bitmap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; + +import org.chromium.base.GarbageCollectionTestUtils; +import org.chromium.base.test.BaseRobolectricTestRunner; + +import java.lang.ref.WeakReference; + +/** + * Tests for {@link GarbageCollectionTestUtils}. + */ +@RunWith(BaseRobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class GarbageCollectionTestUtilsUnitTest { + @Test + public void testCanBeGarbageCollected() { + Bitmap bitmap = Bitmap.createBitmap(1, 2, Bitmap.Config.ARGB_8888); + WeakReference<Bitmap> bitmapWeakReference = new WeakReference<>(bitmap); + assertNotNull(bitmapWeakReference.get()); + assertFalse(canBeGarbageCollected(bitmapWeakReference)); + + bitmap = null; + assertTrue(canBeGarbageCollected(bitmapWeakReference)); + } +} |