This source file includes following definitions.
- getTestCallbackHelperContainer
- evaluateStringValue
- evaluateFloatValue
- evaluateIntegerValue
- testDefaultViewportSize
package org.chromium.content.browser;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
public class ViewportTest extends ContentViewTestBase {
private TestCallbackHelperContainer mCallbackHelper;
protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
if (mCallbackHelper == null) {
mCallbackHelper = new TestCallbackHelperContainer(getContentView());
}
return mCallbackHelper;
}
protected String evaluateStringValue(String expression) throws Throwable {
return JavaScriptUtils.executeJavaScriptAndWaitForResult(getContentView(),
getTestCallbackHelperContainer(), expression);
}
protected float evaluateFloatValue(String expression) throws Throwable {
return Float.valueOf(evaluateStringValue(expression));
}
protected int evaluateIntegerValue(String expression) throws Throwable {
return Integer.valueOf(evaluateStringValue(expression));
}
@DisabledTest
public void testDefaultViewportSize() throws Throwable {
launchContentShellWithUrl("about:blank");
waitForActiveShellToBeDoneLoading();
Context context = getInstrumentation().getTargetContext();
WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
winManager.getDefaultDisplay().getMetrics(metrics);
assertEquals(metrics.density, evaluateFloatValue("window.devicePixelRatio"), 0.1);
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));
}
}