Commit 3ea7b110 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

aw: Add test for canvas in software mode

If webview is in software mode, then 2d canvas are created in software
mode. Make sure this works by getting the bitmap of a solid color
canvas.

Bug: 1027161
Change-Id: I99c547eb301f81940ea22ff8388243e3b711312d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1932418Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718791}
parent 5062bb41
...@@ -20,6 +20,8 @@ import org.chromium.android_webview.AwContents; ...@@ -20,6 +20,8 @@ import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContents.VisualStateCallback; import org.chromium.android_webview.AwContents.VisualStateCallback;
import org.chromium.android_webview.test.util.GraphicsTestUtils; import org.chromium.android_webview.test.util.GraphicsTestUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.ContentUrlConstants; import org.chromium.content_public.common.ContentUrlConstants;
...@@ -156,4 +158,23 @@ public class AwContentsRenderTest { ...@@ -156,4 +158,23 @@ public class AwContentsRenderTest {
Assert.assertNotNull(invisibleBitmap); Assert.assertNotNull(invisibleBitmap);
Assert.assertTrue(invisibleBitmap.sameAs(visibleBitmap)); Assert.assertTrue(invisibleBitmap.sameAs(visibleBitmap));
} }
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testSoftwareCanvas() throws Throwable {
TestThreadUtils.runOnUiThreadBlocking(
() -> mAwContents.setLayerType(View.LAYER_TYPE_SOFTWARE, null));
String testFile = "android_webview/test/data/green_canvas.html";
String url = UrlUtils.getIsolatedTestFileUrl(testFile);
AwActivityTestRule.enableJavaScriptOnUiThread(mAwContents);
mActivityTestRule.loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
mActivityTestRule.waitForVisualStateCallback(mAwContents);
CriteriaHelper.pollInstrumentationThread(() -> {
Bitmap bitmap = GraphicsTestUtils.drawAwContentsOnUiThread(mAwContents, 500, 500);
return Color.GREEN == bitmap.getPixel(250, 250);
});
}
} }
<html>
<body>
<canvas id="canvas" width="500" height="500"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(0, 255, 0)';
ctx.fillRect(0, 0, 500, 500);
</script>
</body>
</html>
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