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

Unified Diff: content/public/android/javatests/src/org/chromium/content/common/CleanupReferenceTest.java

Issue 2282183002: android: Move CleanupReference to android_webview (Closed)
Patch Set: Created 4 years, 4 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/common/CleanupReference.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/common/CleanupReferenceTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/common/CleanupReferenceTest.java b/content/public/android/javatests/src/org/chromium/content/common/CleanupReferenceTest.java
deleted file mode 100644
index b8c3b344bfebe42d1a1b4f98fd287133ad83e35f..0000000000000000000000000000000000000000
--- a/content/public/android/javatests/src/org/chromium/content/common/CleanupReferenceTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright 2013 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.content.common;
-
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import org.chromium.base.annotations.SuppressFBWarnings;
-import org.chromium.base.test.util.Feature;
-import org.chromium.content.browser.test.util.Criteria;
-import org.chromium.content.browser.test.util.CriteriaHelper;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/** Test suite for {@link CleanupReference}. */
-public class CleanupReferenceTest extends InstrumentationTestCase {
-
- private static AtomicInteger sObjectCount = new AtomicInteger();
-
- private static class ReferredObject {
-
- private CleanupReference mRef;
-
- // Remember: this MUST be a static class, to avoid an implicit ref back to the
- // owning ReferredObject instance which would defeat GC of that object.
- private static class DestroyRunnable implements Runnable {
- @Override
- public void run() {
- sObjectCount.decrementAndGet();
- }
- };
-
- @SuppressFBWarnings("URF_UNREAD_FIELD")
- public ReferredObject() {
- sObjectCount.incrementAndGet();
- mRef = new CleanupReference(this, new DestroyRunnable());
- }
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- sObjectCount.set(0);
- }
-
- @SuppressFBWarnings("DM_GC")
- private void collectGarbage() {
- // While this is only a 'hint' to the VM, it's generally effective and sufficient on
- // dalvik. If this changes in future, maybe try allocating a few gargantuan objects
- // too, to force the GC to work.
- Runtime.getRuntime().gc();
- }
-
- @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
- @SmallTest
- @Feature({"AndroidWebView"})
- public void testCreateSingle() throws Throwable {
- assertEquals(0, sObjectCount.get());
-
- ReferredObject instance = new ReferredObject();
- assertEquals(1, sObjectCount.get());
-
- instance = null;
- // Ensure compiler / instrumentation does not strip out the assignment.
- assertTrue(instance == null);
- collectGarbage();
- CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
- @Override
- public Integer call() {
- return sObjectCount.get();
- }
- }));
- }
-
- @SuppressFBWarnings("UC_USELESS_OBJECT")
- @SmallTest
- @Feature({"AndroidWebView"})
- public void testCreateMany() throws Throwable {
- assertEquals(0, sObjectCount.get());
-
- final int instanceCount = 20;
- ReferredObject[] instances = new ReferredObject[instanceCount];
-
- for (int i = 0; i < instanceCount; ++i) {
- instances[i] = new ReferredObject();
- assertEquals(i + 1, sObjectCount.get());
- }
-
- instances = null;
- // Ensure compiler / instrumentation does not strip out the assignment.
- assertTrue(instances == null);
- // Calling sObjectCount.get() before collectGarbage() seems to be required for the objects
- // to be GC'ed only when building using GN.
- assertTrue(sObjectCount.get() != -1);
- collectGarbage();
- CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
- @Override
- public Integer call() {
- return sObjectCount.get();
- }
- }));
- }
-
-}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/common/CleanupReference.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698