diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 17:05:17 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-20 17:05:17 +0000 |
commit | 86adfb7e19f91876e9b491172698decf6f371652 (patch) | |
tree | 2cb898cefaff5ea07a49deb136f3d37091691828 /android_webview/javatests | |
parent | 8b4e6291c402353914728a2619a0b07803d004df (diff) | |
download | chromium_src-86adfb7e19f91876e9b491172698decf6f371652.zip chromium_src-86adfb7e19f91876e9b491172698decf6f371652.tar.gz chromium_src-86adfb7e19f91876e9b491172698decf6f371652.tar.bz2 |
Add Garbage collection test for AwContents
This is to ensure instances do not get leaked after GC, even if
AwContents.destroy() is not called.
This is a resurrection of the test in
https://codereview.chromium.org/12658010/diff/23001/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java
now that crbug.com/197020 is no longer an issue (due to new graphics pipeline)
BUG=197020
Review URL: https://chromiumcodereview.appspot.com/16983009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/javatests')
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java index 8e16a92..455d30b 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java @@ -24,6 +24,7 @@ import org.chromium.net.test.util.TestWebServer; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.Callable; import java.util.concurrent.Semaphore; @@ -154,6 +155,46 @@ public class AwContentsTest extends AwTestBase { } } + public void testCreateAndGcManyTimes() throws Throwable { + final int CONCURRENT_INSTANCES = 4; + final int REPETITIONS = 16; + // The system retains a strong ref to the last focused view (in InputMethodManager) + // so allow for 1 'leaked' instance. + final int MAX_IDLE_INSTANCES = 1; + + System.gc(); + + assertTrue(pollOnUiThread(new Callable<Boolean>() { + @Override + public Boolean call() { + return AwContents.getNativeInstanceCount() <= MAX_IDLE_INSTANCES; + } + })); + for (int i = 0; i < REPETITIONS; ++i) { + for (int j = 0; j < CONCURRENT_INSTANCES; ++j) { + AwTestContainerView view = createAwTestContainerViewOnMainSync(mContentsClient); + loadUrlAsync(view.getAwContents(), "about:blank"); + } + assertTrue(AwContents.getNativeInstanceCount() >= CONCURRENT_INSTANCES); + assertTrue(AwContents.getNativeInstanceCount() <= (i + 1) * CONCURRENT_INSTANCES); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + getActivity().removeAllViews(); + } + }); + } + + System.gc(); + + assertTrue(pollOnUiThread(new Callable<Boolean>() { + @Override + public Boolean call() { + return AwContents.getNativeInstanceCount() <= MAX_IDLE_INSTANCES; + } + })); + } + private int callDocumentHasImagesSync(final AwContents awContents) throws Throwable, InterruptedException { // Set up a container to hold the result object and a semaphore to |