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..1480ba9cc6bf55a06c54aa7e3369e67c4cae65a3 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. |
@@ -14,16 +14,25 @@ import org.chromium.base.ThreadUtils; |
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 java.util.concurrent.Callable; |
import java.util.concurrent.ExecutionException; |
+import org.junit.Rule; |
+import org.junit.Test; |
+import org.chromium.base.test.BaseJUnit4ClassRunner; |
+import org.junit.runner.RunWith; |
+import org.junit.Assert; |
+import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
/** |
* 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 +45,22 @@ 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", |
+ 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 +69,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,7 +88,7 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure they're equal. |
- assertEquals("Deserialized object does not match", |
+ Assert.assertEquals("Deserialized object does not match", |
webContents, deserializedWebContents); |
} finally { |
parcel.recycle(); |
@@ -88,13 +99,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,7 +130,7 @@ public class WebContentsTest extends ContentShellTestBase { |
deserializedBundle.getParcelable(WEB_CONTENTS_KEY); |
// Make sure they're equal. |
- assertEquals("Deserialized object does not match", |
+ Assert.assertEquals("Deserialized object does not match", |
webContents, deserializedWebContents); |
} finally { |
parcel.recycle(); |
@@ -129,13 +141,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,7 +172,7 @@ public class WebContentsTest extends ContentShellTestBase { |
(WebContents) deserializedIntent.getParcelableExtra(WEB_CONTENTS_KEY); |
// Make sure they're equal. |
- assertEquals("Deserialized object does not match", |
+ Assert.assertEquals("Deserialized object does not match", |
webContents, deserializedWebContents); |
} finally { |
parcel.recycle(); |
@@ -171,12 +184,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 +207,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 +219,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,7 +242,7 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure we weren't able to deserialize the WebContents. |
- assertNull("Unexpectedly deserialized a destroyed WebContents", |
+ Assert.assertNull("Unexpectedly deserialized a destroyed WebContents", |
deserializedWebContents); |
} finally { |
parcel.recycle(); |
@@ -240,11 +255,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 +270,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,7 +279,7 @@ public class WebContentsTest extends ContentShellTestBase { |
WebContents.class.getClassLoader()); |
// Make sure we weren't able to deserialize the WebContents. |
- assertNull("Unexpectedly deserialized a destroyed WebContents", |
+ Assert.assertNull("Unexpectedly deserialized a destroyed WebContents", |
deserializedWebContents); |
} finally { |
parcel.recycle(); |
@@ -275,12 +291,13 @@ public class WebContentsTest extends ContentShellTestBase { |
* Parcel. |
* @throws InterruptedException |
*/ |
+ @Test |
@SmallTest |
public void testFailedDeserializationDoesntCorruptParcel() |
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(); |
@@ -300,10 +317,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(); |