Commit 9d3ff4fa authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

android_webview: Refactor MemoryMetricsLoggerTest.

Right now the Java side lives in webview_instrumentation_test_apk
while the C++ side lives in webview_instrumentation_apk. This CL moves
the native method to a new Java class that lives in
webview_instrumentation_apk so that both the Java and C++ sides live
in the same APK. This is necessary for the proxy natives conversion.

Bug: 997199
Change-Id: Ia039cfcde5d18de80479c30086f67eedb531aca1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899196Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713090}
parent 4324de38
...@@ -29,7 +29,7 @@ class MemoryMetricsLogger { ...@@ -29,7 +29,7 @@ class MemoryMetricsLogger {
private: private:
struct State; struct State;
friend jboolean JNI_MemoryMetricsLoggerTest_ForceRecordHistograms( friend jboolean JNI_MemoryMetricsLoggerUtils_ForceRecordHistograms(
JNIEnv* env); JNIEnv* env);
// Returns the single instance, if one was created. // Returns the single instance, if one was created.
......
...@@ -16,6 +16,7 @@ import org.junit.Rule; ...@@ -16,6 +16,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.android_webview.test.util.MemoryMetricsLoggerUtilsJni;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -37,7 +38,7 @@ public class MemoryMetricsLoggerTest { ...@@ -37,7 +38,7 @@ public class MemoryMetricsLoggerTest {
mActivityTestRule.loadUrlSync(testContainerView.getAwContents(), mActivityTestRule.loadUrlSync(testContainerView.getAwContents(),
contentsClient.getOnPageFinishedHelper(), "about:blank"); contentsClient.getOnPageFinishedHelper(), "about:blank");
Assert.assertTrue(nativeForceRecordHistograms()); Assert.assertTrue(MemoryMetricsLoggerUtilsJni.get().forceRecordHistograms());
} }
@After @After
...@@ -75,10 +76,4 @@ public class MemoryMetricsLoggerTest { ...@@ -75,10 +76,4 @@ public class MemoryMetricsLoggerTest {
RecordHistogram.getHistogramTotalCountForTesting( RecordHistogram.getHistogramTotalCountForTesting(
"Memory.Total.PrivateMemoryFootprint")); "Memory.Total.PrivateMemoryFootprint"));
} }
/**
* Calls to MemoryMetricsLogger to force recording histograms, returning true on success.
* A value of false means recording failed (most likely because process metrics not available.
*/
public static native boolean nativeForceRecordHistograms();
} }
...@@ -59,6 +59,7 @@ android_apk("webview_instrumentation_apk") { ...@@ -59,6 +59,7 @@ android_apk("webview_instrumentation_apk") {
deps = [ deps = [
":webview_instrumentation_apk_assets", ":webview_instrumentation_apk_assets",
":webview_instrumentation_apk_resources", ":webview_instrumentation_apk_resources",
":webview_instrumentation_test_utils_java",
"//android_webview:android_webview_java", "//android_webview:android_webview_java",
"//android_webview:android_webview_locale_config_java", "//android_webview:android_webview_locale_config_java",
"//android_webview:common_java", "//android_webview:common_java",
...@@ -166,6 +167,7 @@ instrumentation_test_apk("webview_instrumentation_test_apk") { ...@@ -166,6 +167,7 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
android_manifest = "../javatests/AndroidManifest.xml" android_manifest = "../javatests/AndroidManifest.xml"
min_sdk_version = 21 min_sdk_version = 21
deps = [ deps = [
":webview_instrumentation_test_utils_java",
"//android_webview:android_webview_java", "//android_webview:android_webview_java",
"//android_webview/test/embedded_test_server:aw_net_java_test_support", "//android_webview/test/embedded_test_server:aw_net_java_test_support",
"//base:base_java", "//base:base_java",
...@@ -335,16 +337,26 @@ instrumentation_test_apk("webview_instrumentation_test_apk") { ...@@ -335,16 +337,26 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
] ]
} }
android_library("webview_instrumentation_test_utils_java") {
testonly = true
java_files = [ "shell/src/org/chromium/android_webview/test/util/MemoryMetricsLoggerUtils.java" ]
deps = [
"//base:base_java",
"//base:jni_java",
]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
}
generate_jni("webview_instrumentation_test_native_jni") { generate_jni("webview_instrumentation_test_native_jni") {
testonly = true testonly = true
sources = [ sources = [
"../javatests/src/org/chromium/android_webview/test/MemoryMetricsLoggerTest.java", "shell/src/org/chromium/android_webview/test/util/MemoryMetricsLoggerUtils.java",
] ]
} }
source_set("webview_instrumentation_test_native_jni_impl") { source_set("webview_instrumentation_test_native_jni_impl") {
sources = [ sources = [
"../javatests/src/org/chromium/android_webview/test/memory_metrics_logger_test.cc", "shell/memory_metrics_logger_utils.cc",
] ]
deps = [ deps = [
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "android_webview/test/webview_instrumentation_test_native_jni/MemoryMetricsLoggerTest_jni.h" #include "android_webview/test/webview_instrumentation_test_native_jni/MemoryMetricsLoggerUtils_jni.h"
#include "android_webview/browser/metrics/memory_metrics_logger.h" #include "android_webview/browser/metrics/memory_metrics_logger.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace android_webview { namespace android_webview {
// static // static
jboolean JNI_MemoryMetricsLoggerTest_ForceRecordHistograms(JNIEnv* env) { jboolean JNI_MemoryMetricsLoggerUtils_ForceRecordHistograms(JNIEnv* env) {
auto* memory_metrics_logger = MemoryMetricsLogger::GetInstanceForTesting(); auto* memory_metrics_logger = MemoryMetricsLogger::GetInstanceForTesting();
if (!memory_metrics_logger) if (!memory_metrics_logger)
return false; return false;
......
// Copyright 2019 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.android_webview.test.util;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/**
* Utilities for force recording memory metrics.
*/
@JNINamespace("android_webview")
public class MemoryMetricsLoggerUtils {
@NativeMethods
public interface Natives {
/**
* Calls to MemoryMetricsLogger to force recording histograms, returning true on success.
* A value of false means recording failed (most likely because process metrics not
* available.
*/
boolean forceRecordHistograms();
}
}
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