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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.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/ViewportTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java
index dfd6ade311faa4e608240ea35a30b287450e74da..70842f8aad8c9cccc3756d349d0de62e6f0b2d86 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java
@@ -1,26 +1,36 @@
-// Copyright 2012 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.
package org.chromium.content.browser;
import android.content.Context;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.util.DisplayMetrics;
import android.view.WindowManager;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.test.util.JavaScriptUtils;
-import org.chromium.content_shell_apk.ContentShellTestBase;
+import org.chromium.content_shell_apk.ContentShellActivityTestRule;
/**
* Test suite for viewport-related properties.
*/
-public class ViewportTest extends ContentShellTestBase {
+@RunWith(BaseJUnit4ClassRunner.class)
+public class ViewportTest {
+ @Rule
+ public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
protected String evaluateStringValue(String expression) throws Throwable {
- return JavaScriptUtils.executeJavaScriptAndWaitForResult(getWebContents(),
- expression);
+ return JavaScriptUtils.executeJavaScriptAndWaitForResult(
+ mActivityTestRule.getWebContents(), expression);
}
protected float evaluateFloatValue(String expression) throws Throwable {
@@ -31,25 +41,27 @@ public class ViewportTest extends ContentShellTestBase {
return Integer.parseInt(evaluateStringValue(expression));
}
+ @Test
@MediumTest
@Feature({"Viewport", "InitialViewportSize"})
public void testDefaultViewportSize() throws Throwable {
- launchContentShellWithUrl("about:blank");
- waitForActiveShellToBeDoneLoading();
+ mActivityTestRule.launchContentShellWithUrl("about:blank");
+ mActivityTestRule.waitForActiveShellToBeDoneLoading();
- Context context = getInstrumentation().getTargetContext();
+ Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
winManager.getDefaultDisplay().getMetrics(metrics);
// window.devicePixelRatio should match the default display. Only check to 1 decimal place
// to allow for rounding.
- assertEquals(metrics.density, evaluateFloatValue("window.devicePixelRatio"), 0.1);
+ Assert.assertEquals(metrics.density, evaluateFloatValue("window.devicePixelRatio"), 0.1);
// Check that the viewport width is vaguely sensible.
int viewportWidth = evaluateIntegerValue("document.documentElement.clientWidth");
- assertTrue(Math.abs(evaluateIntegerValue("window.innerWidth") - viewportWidth) <= 1);
- assertTrue(viewportWidth >= 979);
- assertTrue(viewportWidth <= Math.max(981, metrics.widthPixels / metrics.density + 1));
+ Assert.assertTrue(Math.abs(evaluateIntegerValue("window.innerWidth") - viewportWidth) <= 1);
+ Assert.assertTrue(viewportWidth >= 979);
+ Assert.assertTrue(
+ viewportWidth <= Math.max(981, metrics.widthPixels / metrics.density + 1));
}
}

Powered by Google App Engine
This is Rietveld 408576698