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

Unified Diff: android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutTest.java

Issue 2266353003: [EXAMPLE] Change WebView Layout Test to Android JUnit 4 style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix errors Created 4 years, 4 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: android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutTest.java
diff --git a/android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutTest.java b/android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutTest.java
index 470061c5a47dc3f50e65e8b38f022e72f0acd645..0206880fb3d9fefc6181879e6faf950c72e27182 100644
--- a/android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutTest.java
+++ b/android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutTest.java
@@ -4,16 +4,27 @@
package org.chromium.webview_shell.test;
-import android.test.ActivityInstrumentationTestCase2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import android.test.suitebuilder.annotation.MediumTest;
import junit.framework.ComparisonFailure;
import org.chromium.base.Log;
+import org.chromium.base.test.BaseJUnitClassRunner;
import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.webview_shell.WebViewLayoutTestActivity;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -24,13 +35,12 @@ import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
/**
* Tests running end-to-end layout tests.
*/
-public class WebViewLayoutTest
- extends ActivityInstrumentationTestCase2<WebViewLayoutTestActivity> {
+@RunWith(BaseJUnitClassRunner.class)
+public class WebViewLayoutTest {
private static final String TAG = "WebViewLayoutTest";
@@ -49,36 +59,35 @@ public class WebViewLayoutTest
private WebViewLayoutTestActivity mTestActivity;
- public WebViewLayoutTest() {
- super(WebViewLayoutTestActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mTestActivity = (WebViewLayoutTestActivity) getActivity();
- }
+ @Rule
+ public WebViewLayoutActivityTestRule<WebViewLayoutTestActivity> mActivityRule =
+ new WebViewLayoutActivityTestRule<>(WebViewLayoutTestActivity.class);
- @Override
- protected void tearDown() throws Exception {
- mTestActivity.finish();
- super.tearDown();
+ @Before
+ public void setUp() throws Exception {
+ mTestActivity = mActivityRule.getActivity();
}
- @Override
- public WebViewLayoutTestRunner getInstrumentation() {
- return (WebViewLayoutTestRunner) super.getInstrumentation();
+ @MediumTest
+ @Test
+ public void testSimple() throws Throwable {
+ runWebViewLayoutTest("experimental/basic-logging.html",
+ "experimental/basic-logging-expected.txt");
}
+ @Test
@MediumTest
- public void testSimple() throws Exception {
+ public void testSimple2() throws Throwable {
+ Assume.assumeTrue(1 == 2);
runWebViewLayoutTest("experimental/basic-logging.html",
"experimental/basic-logging-expected.txt");
}
+
// This is a non-failing test because it tends to require frequent rebaselines.
@MediumTest
- public void testGlobalInterfaceNoFail() throws Exception {
+ @Test
+ public void testGlobalInterfaceNoFail() throws Throwable {
runBlinkLayoutTest("webexposed/global-interface-listing.html",
"webexposed/global-interface-listing-expected.txt", true);
}
@@ -86,7 +95,9 @@ public class WebViewLayoutTest
// This is a non-failing test to avoid 'blind' rebaselines by the sheriff
// (see crbug.com/564765).
@MediumTest
- public void testNoUnexpectedInterfaces() throws Exception {
+ @DisableIf.Build(sdk_is_greater_than = 14)
+ @Test
+ public void testNoUnexpectedInterfaces() throws Throwable {
ensureJsTestCopied();
loadUrlWebViewAsync("file://" + PATH_BLINK_PREFIX
+ "webexposed/global-interface-listing.html", mTestActivity);
@@ -113,7 +124,8 @@ public class WebViewLayoutTest
}
@MediumTest
- public void testWebViewExcludedInterfaces() throws Exception {
+ @Test
+ public void testWebViewExcludedInterfaces() throws Throwable {
ensureJsTestCopied();
loadUrlWebViewAsync("file://" + PATH_BLINK_PREFIX
+ "webexposed/global-interface-listing.html", mTestActivity);
@@ -157,7 +169,8 @@ public class WebViewLayoutTest
}
@MediumTest
- public void testWebViewIncludedStableInterfaces() throws Exception {
+ @Test
+ public void testWebViewIncludedStableInterfaces() throws Throwable {
ensureJsTestCopied();
loadUrlWebViewAsync("file://" + PATH_BLINK_PREFIX
+ "webexposed/global-interface-listing.html", mTestActivity);
@@ -202,13 +215,14 @@ public class WebViewLayoutTest
}
@MediumTest
- public void testRequestMIDIAccess() throws Exception {
+ @Test
+ public void testRequestMIDIAccess() throws Throwable {
runWebViewLayoutTest("blink-apis/webmidi/requestmidiaccess.html",
"blink-apis/webmidi/requestmidiaccess-expected.txt");
}
@MediumTest
- public void testRequestMIDIAccessWithSysex() throws Exception {
+ public void testRequestMIDIAccessWithSysex() throws Throwable {
mTestActivity.setGrantPermission(true);
runWebViewLayoutTest("blink-apis/webmidi/requestmidiaccess-with-sysex.html",
"blink-apis/webmidi/requestmidiaccess-with-sysex-expected.txt");
@@ -216,7 +230,8 @@ public class WebViewLayoutTest
}
@MediumTest
- public void testRequestMIDIAccessDenyPermission() throws Exception {
+ @Test
+ public void testRequestMIDIAccessDenyPermission() throws Throwable {
runWebViewLayoutTest("blink-apis/webmidi/requestmidiaccess-permission-denied.html",
"blink-apis/webmidi/requestmidiaccess-permission-denied-expected.txt");
}
@@ -224,19 +239,23 @@ public class WebViewLayoutTest
// Blink platform API tests
@MediumTest
- public void testGeolocationCallbacks() throws Exception {
+ @Test
+ @Ignore
+ public void testGeolocationCallbacks() throws Throwable {
runWebViewLayoutTest("blink-apis/geolocation/geolocation-permission-callbacks.html",
"blink-apis/geolocation/geolocation-permission-callbacks-expected.txt");
}
@MediumTest
- public void testMediaStreamApiDenyPermission() throws Exception {
+ @Test
+ public void testMediaStreamApiDenyPermission() throws Throwable {
runWebViewLayoutTest("blink-apis/webrtc/mediastream-permission-denied-callbacks.html",
"blink-apis/webrtc/mediastream-permission-denied-callbacks-expected.txt");
}
@MediumTest
- public void testMediaStreamApi() throws Exception {
+ @Test
+ public void testMediaStreamApi() throws Throwable {
mTestActivity.setGrantPermission(true);
runWebViewLayoutTest("blink-apis/webrtc/mediastream-callbacks.html",
"blink-apis/webrtc/mediastream-callbacks-expected.txt");
@@ -244,7 +263,8 @@ public class WebViewLayoutTest
}
@MediumTest
- public void testBatteryApi() throws Exception {
+ @Test
+ public void testBatteryApi() throws Throwable {
runWebViewLayoutTest("blink-apis/battery-status/battery-callback.html",
"blink-apis/battery-status/battery-callback-expected.txt");
}
@@ -254,7 +274,8 @@ public class WebViewLayoutTest
*/
@MediumTest
@DisableIf.Build(product_name_includes = "aosp")
- public void testEMEPermission() throws Exception {
+ @Test
+ public void testEMEPermission() throws Throwable {
mTestActivity.setGrantPermission(true);
runWebViewLayoutTest("blink-apis/eme/eme.html", "blink-apis/eme/eme-expected.txt");
mTestActivity.setGrantPermission(false);
@@ -264,21 +285,20 @@ public class WebViewLayoutTest
// test helper methods
private void runWebViewLayoutTest(final String fileName, final String fileNameExpected)
- throws Exception {
+ throws Throwable {
runTest(PATH_WEBVIEW_PREFIX + fileName, PATH_WEBVIEW_PREFIX + fileNameExpected, false);
}
private void runBlinkLayoutTest(final String fileName, final String fileNameExpected,
- boolean noFail) throws Exception {
+ boolean noFail) throws Throwable {
ensureJsTestCopied();
runTest(PATH_BLINK_PREFIX + fileName, PATH_WEBVIEW_PREFIX + fileNameExpected, noFail);
}
private void runTest(final String fileName, final String fileNameExpected, boolean noFail)
- throws FileNotFoundException, IOException, InterruptedException, TimeoutException {
+ throws Throwable {
loadUrlWebViewAsync("file://" + fileName, mTestActivity);
-
- if (getInstrumentation().isRebaseline()) {
+ if (mActivityRule.isRebaseline()) {
// this is the rebaseline process
mTestActivity.waitForFinish(TIMEOUT_SECONDS, TimeUnit.SECONDS);
String result = mTestActivity.getTestResult();
@@ -298,8 +318,8 @@ public class WebViewLayoutTest
}
private void loadUrlWebViewAsync(final String fileUrl,
- final WebViewLayoutTestActivity activity) {
- getInstrumentation().runOnMainSync(new Runnable() {
+ final WebViewLayoutTestActivity activity) throws Throwable {
+ mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.loadUrl(fileUrl);
« no previous file with comments | « android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewLayoutActivityTestRule.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698