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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: New test added from WebContentsTest Created 3 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 side-by-side diff with in-line comments
Download patch
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 110a099c1bc09040f2942544a35c92c9986de0df..448ba982b3d364c81bb69d53329ffeabb13f7bee 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,12 +10,18 @@ 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.RenderFrameHost;
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;
@@ -24,7 +30,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";
@@ -37,21 +47,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));
}
@@ -60,11 +72,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();
@@ -78,8 +91,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();
}
@@ -89,13 +102,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.
@@ -119,8 +133,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();
}
@@ -130,13 +144,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.
@@ -160,8 +175,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();
}
@@ -172,12 +187,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();
@@ -194,7 +210,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();
}
@@ -206,15 +222,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();
@@ -228,8 +245,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();
}
@@ -241,11 +258,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();
@@ -255,8 +273,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);
@@ -264,8 +282,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();
}
@@ -276,12 +294,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();
@@ -301,10 +319,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();
@@ -317,10 +335,12 @@ public class WebContentsTest extends ContentShellTestBase {
*
* @throws InterruptedException
*/
+ @Test
@SmallTest
public void testWebContentsMainFrame() throws InterruptedException {
boliu 2017/03/10 18:32:32 this needs a rebase.. depending on timing of when
the real yoland 2017/03/10 19:31:58 Will do
boliu 2017/03/10 19:36:10 That CL just got cq-ed again, so guess you have to
- final ContentShellActivity activity = launchContentShellWithUrl(TEST_URL_1);
- waitForActiveShellToBeDoneLoading();
+ final ContentShellActivity activity =
+ mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
+ mActivityTestRule.waitForActiveShellToBeDoneLoading();
final WebContents webContents = activity.getActiveWebContents();
ThreadUtils.postOnUiThread(new Runnable() {
@@ -328,14 +348,14 @@ public class WebContentsTest extends ContentShellTestBase {
public void run() {
RenderFrameHost frameHost = webContents.getMainFrame();
- assertNotNull(frameHost);
+ Assert.assertNotNull(frameHost);
- assertEquals("RenderFrameHost has incorrect last committed URL", "about:blank",
- frameHost.getLastCommittedURL());
+ Assert.assertEquals("RenderFrameHost has incorrect last committed URL",
+ "about:blank", frameHost.getLastCommittedURL());
WebContents associatedWebContents = WebContentsImpl.fromRenderFrameHost(frameHost);
- assertEquals("RenderFrameHost associated with different WebContents", webContents,
- associatedWebContents);
+ Assert.assertEquals("RenderFrameHost associated with different WebContents",
+ webContents, associatedWebContents);
}
});
}

Powered by Google App Engine
This is Rietveld 408576698