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

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

Issue 1000793002: [Android] Incorporate findbugs into android builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address cjhopman's comment + rebase Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.common; 5 package org.chromium.content.common;
6 6
7 import android.test.InstrumentationTestCase; 7 import android.test.InstrumentationTestCase;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.annotations.SuppressFBWarnings;
10 import org.chromium.base.test.util.Feature; 11 import org.chromium.base.test.util.Feature;
11 import org.chromium.content.browser.test.util.Criteria; 12 import org.chromium.content.browser.test.util.Criteria;
12 import org.chromium.content.browser.test.util.CriteriaHelper; 13 import org.chromium.content.browser.test.util.CriteriaHelper;
13 14
14 import java.util.concurrent.atomic.AtomicInteger; 15 import java.util.concurrent.atomic.AtomicInteger;
15 16
16 public class CleanupReferenceTest extends InstrumentationTestCase { 17 public class CleanupReferenceTest extends InstrumentationTestCase {
17 18
18 private static AtomicInteger sObjectCount = new AtomicInteger(); 19 private static AtomicInteger sObjectCount = new AtomicInteger();
19 20
20 private static class ReferredObject { 21 private static class ReferredObject {
21 22
22 private CleanupReference mRef; 23 private CleanupReference mRef;
23 24
24 // Remember: this MUST be a static class, to avoid an implicit ref back to the 25 // Remember: this MUST be a static class, to avoid an implicit ref back to the
25 // owning ReferredObject instance which would defeat GC of that object. 26 // owning ReferredObject instance which would defeat GC of that object.
26 private static class DestroyRunnable implements Runnable { 27 private static class DestroyRunnable implements Runnable {
27 @Override 28 @Override
28 public void run() { 29 public void run() {
29 sObjectCount.decrementAndGet(); 30 sObjectCount.decrementAndGet();
30 } 31 }
31 }; 32 };
32 33
34 @SuppressFBWarnings("URF_UNREAD_FIELD")
33 public ReferredObject() { 35 public ReferredObject() {
34 sObjectCount.incrementAndGet(); 36 sObjectCount.incrementAndGet();
35 mRef = new CleanupReference(this, new DestroyRunnable()); 37 mRef = new CleanupReference(this, new DestroyRunnable());
36 } 38 }
37 } 39 }
38 40
39 @Override 41 @Override
40 public void setUp() throws Exception { 42 public void setUp() throws Exception {
41 super.setUp(); 43 super.setUp();
42 sObjectCount.set(0); 44 sObjectCount.set(0);
43 } 45 }
44 46
47 @SuppressFBWarnings("DM_GC")
45 private void collectGarbage() { 48 private void collectGarbage() {
46 // While this is only a 'hint' to the VM, it's generally effective and s ufficient on 49 // While this is only a 'hint' to the VM, it's generally effective and s ufficient on
47 // dalvik. If this changes in future, maybe try allocating a few gargant uan objects 50 // dalvik. If this changes in future, maybe try allocating a few gargant uan objects
48 // too, to force the GC to work. 51 // too, to force the GC to work.
49 System.gc(); 52 System.gc();
50 } 53 }
51 54
55 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
52 @SmallTest 56 @SmallTest
53 @Feature({"AndroidWebView"}) 57 @Feature({"AndroidWebView"})
54 public void testCreateSingle() throws Throwable { 58 public void testCreateSingle() throws Throwable {
55 assertEquals(0, sObjectCount.get()); 59 assertEquals(0, sObjectCount.get());
56 60
57 ReferredObject instance = new ReferredObject(); 61 ReferredObject instance = new ReferredObject();
58 assertEquals(1, sObjectCount.get()); 62 assertEquals(1, sObjectCount.get());
59 63
60 instance = null; 64 instance = null;
61 // Ensure compiler / instrumentation does not strip out the assignment. 65 // Ensure compiler / instrumentation does not strip out the assignment.
(...skipping 26 matching lines...) Expand all
88 collectGarbage(); 92 collectGarbage();
89 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { 93 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
90 @Override 94 @Override
91 public boolean isSatisfied() { 95 public boolean isSatisfied() {
92 return sObjectCount.get() == 0; 96 return sObjectCount.get() == 0;
93 } 97 }
94 })); 98 }));
95 } 99 }
96 100
97 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698