Skip to content

Commit

Permalink
[aw] Fix screen portion percentage cast error
Browse files Browse the repository at this point in the history
When passing the screen coverage percentage to
AwContentsJni#updateOpenWebScreenArea(), a float value was cast to an int,
which always produced zero. This change multiplies the float value by 100
to match the expectation for an integer percentage and adds a test that
verifies that the screen portion histogram contains samples for a
non-zero percentage bucket.

Bug: 1122091
Change-Id: I592b2a72d6ceb80108d9dfe73d25d55164709a5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2924108
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: Peter Conn <peconn@chromium.org>
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#893127}
  • Loading branch information
Oksana Zhuravlova authored and Chromium LUCI CQ committed Jun 16, 2021
1 parent 629b5b1 commit f217b4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ private void recalculate() {
(float) openWebPixelCoverage / RectUtils.getRectArea(rootVisibleRect);

AwContentsJni.get().updateOpenWebScreenArea(
openWebPixelCoverage, (int) openWebVisiblePercentage);
openWebPixelCoverage, (int) (openWebVisiblePercentage * 100));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.common.AwFeatures;
import org.chromium.android_webview.common.PlatformServiceBridge;
import org.chromium.android_webview.metrics.AwMetricsServiceClient;
import org.chromium.base.Callback;
Expand Down Expand Up @@ -401,4 +402,32 @@ public void testRendererHistograms() throws Throwable {
embeddedTestServer.stopAndDestroyServer();
}
}

@Test
@MediumTest
@Feature({"AndroidWebView"})
@CommandLineFlags.Add({"enable-features=" + AwFeatures.WEBVIEW_MEASURE_SCREEN_COVERAGE})
public void testScreenCoverageReporting() throws Throwable {
EmbeddedTestServer embeddedTestServer = EmbeddedTestServer.createAndStartServer(
InstrumentationRegistry.getInstrumentation().getContext());
try {
mRule.loadUrlAsync(mAwContents,
embeddedTestServer.getURL("/android_webview/test/data/hello_world.html"));

// We need to wait for log collection because the histogram is recorded during
// MetricsProvider::ProvideCurrentSessionData().
mPlatformServiceBridge.waitForNextMetricsLog();

final String histogramName = "Android.WebView.WebViewOpenWebVisible.ScreenPortion";
int totalSamples = RecordHistogram.getHistogramTotalCountForTesting(histogramName);
Assert.assertNotEquals("There should be at least one sample recorded", 0, totalSamples);

int zeroBucketSamples =
RecordHistogram.getHistogramValueCountForTesting(histogramName, 0);
Assert.assertNotEquals("There should be at least one sample in a non-zero bucket",
zeroBucketSamples, totalSamples);
} finally {
embeddedTestServer.stopAndDestroyServer();
}
}
}

0 comments on commit f217b4c

Please sign in to comment.