Commit 268dcdac authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Move a test-only method out of production

Removes a TODO by moving a test-only method in WebContentsImpl
to test package.

Change-Id: Ia143ee015b3a68b0ec946a85d042b30cbce07172
Reviewed-on: https://chromium-review.googlesource.com/1168953
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582482}
parent 9619f132
...@@ -860,16 +860,6 @@ bool WebContentsAndroid::IsBeingDestroyed(JNIEnv* env, ...@@ -860,16 +860,6 @@ bool WebContentsAndroid::IsBeingDestroyed(JNIEnv* env,
return web_contents_->IsBeingDestroyed(); return web_contents_->IsBeingDestroyed();
} }
int WebContentsAndroid::GetTopControlsShrinkBlinkHeightPixForTesting(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid();
float scale = web_contents_->GetNativeView()->GetDipScale();
return (rwhva && rwhva->DoBrowserControlsShrinkBlinkSize())
? rwhva->GetTopControlsHeight() * scale
: 0;
}
void WebContentsAndroid::SetDisplayCutoutSafeArea( void WebContentsAndroid::SetDisplayCutoutSafeArea(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
......
...@@ -243,12 +243,6 @@ class CONTENT_EXPORT WebContentsAndroid ...@@ -243,12 +243,6 @@ class CONTENT_EXPORT WebContentsAndroid
bool IsBeingDestroyed(JNIEnv* env, bool IsBeingDestroyed(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
// Returns the amount of the top controls height if controls are in the state
// of shrinking Blink's view size, otherwise 0.
int GetTopControlsShrinkBlinkHeightPixForTesting(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
void SetDisplayCutoutSafeArea(JNIEnv* env, void SetDisplayCutoutSafeArea(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
int top, int top,
......
...@@ -618,18 +618,6 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi ...@@ -618,18 +618,6 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi
} }
} }
/**
* @return The amount of the top controls height if controls are in the state
* of shrinking Blink's view size, otherwise 0.
*/
@VisibleForTesting
public int getTopControlsShrinkBlinkHeightForTesting() {
// TODO(jinsukkim): Let callsites provide with its own top controls height to remove
// the test-only method in content layer.
if (mNativeWebContentsAndroid == 0) return 0;
return nativeGetTopControlsShrinkBlinkHeightPixForTesting(mNativeWebContentsAndroid);
}
@VisibleForTesting @VisibleForTesting
@Override @Override
public boolean isSelectPopupVisibleForTesting() { public boolean isSelectPopupVisibleForTesting() {
...@@ -972,8 +960,6 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi ...@@ -972,8 +960,6 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi
private native int nativeGetWidth(long nativeWebContentsAndroid); private native int nativeGetWidth(long nativeWebContentsAndroid);
private native int nativeGetHeight(long nativeWebContentsAndroid); private native int nativeGetHeight(long nativeWebContentsAndroid);
private native EventForwarder nativeGetOrCreateEventForwarder(long nativeWebContentsAndroid); private native EventForwarder nativeGetOrCreateEventForwarder(long nativeWebContentsAndroid);
private native int nativeGetTopControlsShrinkBlinkHeightPixForTesting(
long nativeWebContentsAndroid);
private native void nativeSetViewAndroidDelegate( private native void nativeSetViewAndroidDelegate(
long nativeWebContentsAndroid, ViewAndroidDelegate viewDelegate); long nativeWebContentsAndroid, ViewAndroidDelegate viewDelegate);
private native void nativeSendOrientationChangeEvent( private native void nativeSendOrientationChangeEvent(
......
...@@ -61,12 +61,14 @@ generate_jni("content_test_jni") { ...@@ -61,12 +61,14 @@ generate_jni("content_test_jni") {
jni_package = "content/public/test" jni_package = "content/public/test"
sources = [ sources = [
"javatests/src/org/chromium/content/browser/test/InterstitialPageDelegateAndroid.java", "javatests/src/org/chromium/content/browser/test/InterstitialPageDelegateAndroid.java",
"javatests/src/org/chromium/content/browser/test/util/DOMUtils.java",
] ]
} }
static_library("content_native_test_support") { static_library("content_native_test_support") {
testonly = true testonly = true
sources = [ sources = [
"dom_utils.cc",
"interstitial_page_delegate_android.cc", "interstitial_page_delegate_android.cc",
"interstitial_page_delegate_android.h", "interstitial_page_delegate_android.h",
] ]
...@@ -76,5 +78,6 @@ static_library("content_native_test_support") { ...@@ -76,5 +78,6 @@ static_library("content_native_test_support") {
"//content/public/browser", "//content/public/browser",
"//device/gamepad", "//device/gamepad",
"//media/midi", "//media/midi",
"//ui/android",
] ]
} }
// Copyright 2018 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.
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "jni/DOMUtils_jni.h"
#include "ui/android/view_android.h"
using base::android::JavaParamRef;
namespace content {
// Returns the amount of the top controls height if controls are in the state
// of shrinking Blink's view size, otherwise 0.
jint JNI_DOMUtils_GetTopControlsShrinkBlinkHeight(
JNIEnv* env,
const JavaParamRef<jclass>& clazz,
const JavaParamRef<jobject>& jweb_contents) {
WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents);
// Android obtains the top control size via WebContentsDelegate.
WebContentsDelegate* delegate = web_contents->GetDelegate();
float scale = web_contents->GetNativeView()->GetDipScale();
return delegate && delegate->DoBrowserControlsShrinkBlinkSize()
? delegate->GetTopControlsHeight() * scale
: 0;
}
} // namespace content
...@@ -13,6 +13,7 @@ import android.view.View; ...@@ -13,6 +13,7 @@ import android.view.View;
import org.junit.Assert; import org.junit.Assert;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.content.browser.RenderCoordinatesImpl; import org.chromium.content.browser.RenderCoordinatesImpl;
import org.chromium.content.browser.webcontents.WebContentsImpl; import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -26,8 +27,8 @@ import java.util.concurrent.TimeoutException; ...@@ -26,8 +27,8 @@ import java.util.concurrent.TimeoutException;
/** /**
* Collection of DOM-based utilities. * Collection of DOM-based utilities.
*/ */
@JNINamespace("content")
public class DOMUtils { public class DOMUtils {
private static final long MEDIA_TIMEOUT_SECONDS = scaleTimeout(10); private static final long MEDIA_TIMEOUT_SECONDS = scaleTimeout(10);
private static final long MEDIA_TIMEOUT_MILLISECONDS = MEDIA_TIMEOUT_SECONDS * 1000; private static final long MEDIA_TIMEOUT_MILLISECONDS = MEDIA_TIMEOUT_SECONDS * 1000;
...@@ -506,9 +507,8 @@ public class DOMUtils { ...@@ -506,9 +507,8 @@ public class DOMUtils {
private static int getMaybeTopControlsHeight(final WebContents webContents) { private static int getMaybeTopControlsHeight(final WebContents webContents) {
try { try {
return ThreadUtils.runOnUiThreadBlocking(() -> { return ThreadUtils.runOnUiThreadBlocking(
return ((WebContentsImpl) webContents).getTopControlsShrinkBlinkHeightForTesting(); () -> nativeGetTopControlsShrinkBlinkHeight(webContents));
});
} catch (ExecutionException e) { } catch (ExecutionException e) {
return 0; return 0;
} }
...@@ -561,4 +561,6 @@ public class DOMUtils { ...@@ -561,4 +561,6 @@ public class DOMUtils {
return new Rect(bounds[0], bounds[1], bounds[0] + bounds[2], bounds[1] + bounds[3]); return new Rect(bounds[0], bounds[1], bounds[0] + bounds[2], bounds[1] + bounds[3]);
} }
private static native int nativeGetTopControlsShrinkBlinkHeight(WebContents webContents);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment