Index: content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java b/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java |
index fa52a8a74a4d752255c60147f1a1ff1c8a3dbc14..9d341bab4baf96ea02a2ead377c56c469f65159b 100644 |
--- a/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java |
@@ -1,4 +1,4 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Copyright 2017 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. |
@@ -10,11 +10,17 @@ import android.os.Bundle; |
import android.os.Parcel; |
import android.support.test.filters.SmallTest; |
+import org.junit.Assert; |
+import org.junit.Rule; |
+import org.junit.Test; |
+import org.junit.runner.RunWith; |
+ |
import org.chromium.base.ThreadUtils; |
+import org.chromium.base.test.BaseJUnit4ClassRunner; |
import org.chromium.content_public.browser.WebContents; |
import org.chromium.content_shell.Shell; |
import org.chromium.content_shell_apk.ContentShellActivity; |
-import org.chromium.content_shell_apk.ContentShellTestBase; |
+import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
import java.util.concurrent.Callable; |
import java.util.concurrent.ExecutionException; |
@@ -23,7 +29,11 @@ import java.util.concurrent.ExecutionException; |
* Test various Java WebContents specific features. |
* TODO(dtrainor): Add more testing for the WebContents methods. |
*/ |
-public class WebContentsTest extends ContentShellTestBase { |
+@RunWith(BaseJUnit4ClassRunner.class) |
+public class WebContentsTest { |
+ @Rule |
+ public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule(); |
+ |
private static final String TEST_URL_1 = "about://blank"; |
private static final String WEB_CONTENTS_KEY = "WEBCONTENTSKEY"; |
private static final String PARCEL_STRING_TEST_DATA = "abcdefghijklmnopqrstuvwxyz"; |
@@ -36,21 +46,23 @@ public class WebContentsTest extends ContentShellTestBase { |
* @throws InterruptedException |
* @throws ExecutionException |
*/ |
+ @Test |
@SmallTest |
public void testWebContentsIsDestroyedMethod() throws InterruptedException, ExecutionException { |
- final ContentShellActivity activity = launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
+ final ContentShellActivity activity = |
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
WebContents webContents = activity.getActiveWebContents(); |
- assertFalse("WebContents incorrectly marked as destroyed", |
- isWebContentsDestroyed(webContents)); |
+ Assert.assertFalse( |
+ "WebContents incorrectly marked as destroyed", isWebContentsDestroyed(webContents)); |
// Launch a new shell. |
Shell originalShell = activity.getActiveShell(); |
- loadNewShell(TEST_URL_1); |
- assertNotSame("New shell not created", activity.getActiveShell(), originalShell); |
+ mActivityTestRule.loadNewShell(TEST_URL_1); |
+ Assert.assertNotSame("New shell not created", activity.getActiveShell(), originalShell); |
- assertTrue("WebContents incorrectly marked as not destroyed", |
+ Assert.assertTrue("WebContents incorrectly marked as not destroyed", |
isWebContentsDestroyed(webContents)); |
} |
@@ -59,11 +71,12 @@ public class WebContentsTest extends ContentShellTestBase { |
* |
* @throws InterruptedException |
*/ |
+ @Test |
@SmallTest |
public void testWebContentsSerializeDeserializeInParcel() throws InterruptedException { |
- launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
- WebContents webContents = getWebContents(); |
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
+ WebContents webContents = mActivityTestRule.getWebContents(); |
Parcel parcel = Parcel.obtain(); |
@@ -77,8 +90,8 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure they're equal. |
- assertEquals("Deserialized object does not match", |
- webContents, deserializedWebContents); |
+ Assert.assertEquals( |
+ "Deserialized object does not match", webContents, deserializedWebContents); |
} finally { |
parcel.recycle(); |
} |
@@ -88,13 +101,14 @@ public class WebContentsTest extends ContentShellTestBase { |
* Check that it is possible to serialize and deserialize a WebContents object through Bundles. |
* @throws InterruptedException |
*/ |
+ @Test |
@SmallTest |
// TODO(crbug.com/635567): Fix this properly. |
@SuppressLint("ParcelClassLoader") |
public void testWebContentsSerializeDeserializeInBundle() throws InterruptedException { |
- launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
- WebContents webContents = getWebContents(); |
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
+ WebContents webContents = mActivityTestRule.getWebContents(); |
// Use a parcel to force the Bundle to actually serialize and deserialize, otherwise it can |
// cache the WebContents object. |
@@ -118,8 +132,8 @@ public class WebContentsTest extends ContentShellTestBase { |
deserializedBundle.getParcelable(WEB_CONTENTS_KEY); |
// Make sure they're equal. |
- assertEquals("Deserialized object does not match", |
- webContents, deserializedWebContents); |
+ Assert.assertEquals( |
+ "Deserialized object does not match", webContents, deserializedWebContents); |
} finally { |
parcel.recycle(); |
} |
@@ -129,13 +143,14 @@ public class WebContentsTest extends ContentShellTestBase { |
* Check that it is possible to serialize and deserialize a WebContents object through Intents. |
* @throws InterruptedException |
*/ |
+ @Test |
@SmallTest |
// TODO(crbug.com/635567): Fix this properly. |
@SuppressLint("ParcelClassLoader") |
public void testWebContentsSerializeDeserializeInIntent() throws InterruptedException { |
- launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
- WebContents webContents = getWebContents(); |
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
+ WebContents webContents = mActivityTestRule.getWebContents(); |
// Use a parcel to force the Intent to actually serialize and deserialize, otherwise it can |
// cache the WebContents object. |
@@ -159,8 +174,8 @@ public class WebContentsTest extends ContentShellTestBase { |
(WebContents) deserializedIntent.getParcelableExtra(WEB_CONTENTS_KEY); |
// Make sure they're equal. |
- assertEquals("Deserialized object does not match", |
- webContents, deserializedWebContents); |
+ Assert.assertEquals( |
+ "Deserialized object does not match", webContents, deserializedWebContents); |
} finally { |
parcel.recycle(); |
} |
@@ -171,12 +186,13 @@ public class WebContentsTest extends ContentShellTestBase { |
* instance fails. |
* @throws InterruptedException |
*/ |
+ @Test |
@SmallTest |
public void testWebContentsFailDeserializationAcrossProcessBoundary() |
throws InterruptedException { |
- launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
- WebContents webContents = getWebContents(); |
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
+ WebContents webContents = mActivityTestRule.getWebContents(); |
Parcel parcel = Parcel.obtain(); |
@@ -193,7 +209,7 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure we weren't able to deserialize the WebContents. |
- assertNull("Unexpectedly deserialized a WebContents", deserializedWebContents); |
+ Assert.assertNull("Unexpectedly deserialized a WebContents", deserializedWebContents); |
} finally { |
parcel.recycle(); |
} |
@@ -205,15 +221,16 @@ public class WebContentsTest extends ContentShellTestBase { |
* @throws InterruptedException |
* @throws ExecutionException |
*/ |
+ @Test |
@SmallTest |
public void testSerializingADestroyedWebContentsDoesNotDeserialize() |
throws InterruptedException, ExecutionException { |
- ContentShellActivity activity = launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
+ ContentShellActivity activity = mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
WebContents webContents = activity.getActiveWebContents(); |
- loadNewShell(TEST_URL_1); |
+ mActivityTestRule.loadNewShell(TEST_URL_1); |
- assertTrue("WebContents not destroyed", isWebContentsDestroyed(webContents)); |
+ Assert.assertTrue("WebContents not destroyed", isWebContentsDestroyed(webContents)); |
Parcel parcel = Parcel.obtain(); |
@@ -227,8 +244,8 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure we weren't able to deserialize the WebContents. |
- assertNull("Unexpectedly deserialized a destroyed WebContents", |
- deserializedWebContents); |
+ Assert.assertNull( |
+ "Unexpectedly deserialized a destroyed WebContents", deserializedWebContents); |
} finally { |
parcel.recycle(); |
} |
@@ -240,11 +257,12 @@ public class WebContentsTest extends ContentShellTestBase { |
* @throws InterruptedException |
* @throws ExecutionException |
*/ |
+ @Test |
@SmallTest |
public void testDestroyingAWebContentsAfterSerializingDoesNotDeserialize() |
throws InterruptedException, ExecutionException { |
- ContentShellActivity activity = launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
+ ContentShellActivity activity = mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
WebContents webContents = activity.getActiveWebContents(); |
Parcel parcel = Parcel.obtain(); |
@@ -254,8 +272,8 @@ public class WebContentsTest extends ContentShellTestBase { |
parcel.writeParcelable(webContents, 0); |
// Destroy the WebContents. |
- loadNewShell(TEST_URL_1); |
- assertTrue("WebContents not destroyed", isWebContentsDestroyed(webContents)); |
+ mActivityTestRule.loadNewShell(TEST_URL_1); |
+ Assert.assertTrue("WebContents not destroyed", isWebContentsDestroyed(webContents)); |
// Try to read back the WebContents. |
parcel.setDataPosition(0); |
@@ -263,8 +281,8 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure we weren't able to deserialize the WebContents. |
- assertNull("Unexpectedly deserialized a destroyed WebContents", |
- deserializedWebContents); |
+ Assert.assertNull( |
+ "Unexpectedly deserialized a destroyed WebContents", deserializedWebContents); |
} finally { |
parcel.recycle(); |
} |
@@ -275,12 +293,12 @@ public class WebContentsTest extends ContentShellTestBase { |
* Parcel. |
* @throws InterruptedException |
*/ |
+ @Test |
@SmallTest |
- public void testFailedDeserializationDoesntCorruptParcel() |
- throws InterruptedException { |
- launchContentShellWithUrl(TEST_URL_1); |
- waitForActiveShellToBeDoneLoading(); |
- WebContents webContents = getWebContents(); |
+ public void testFailedDeserializationDoesntCorruptParcel() throws InterruptedException { |
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1); |
+ mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
+ WebContents webContents = mActivityTestRule.getWebContents(); |
Parcel parcel = Parcel.obtain(); |
@@ -300,10 +318,10 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure we weren't able to deserialize the WebContents. |
- assertNull("Unexpectedly deserialized a WebContents", deserializedWebContents); |
+ Assert.assertNull("Unexpectedly deserialized a WebContents", deserializedWebContents); |
// Make sure we can properly deserialize the String after the WebContents. |
- assertEquals("Failing to read the WebContents corrupted the parcel", |
+ Assert.assertEquals("Failing to read the WebContents corrupted the parcel", |
PARCEL_STRING_TEST_DATA, parcel.readString()); |
} finally { |
parcel.recycle(); |