Commit 5a4d7c97 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Automated VR Browser <select> tag test

Automates the manual test for <select> tags/dropdown lists on webpages
while in the VR browser.

Bug: 887513
Change-Id: I5419c6e94bc9d1cb149fb32aff9b7c5cee87732b
Reviewed-on: https://chromium-review.googlesource.com/1241198Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593697}
parent ef3b56e8
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.vr; package org.chromium.chrome.browser.vr;
import static org.chromium.chrome.browser.vr.XrTestFramework.PAGE_LOAD_TIMEOUT_S; import static org.chromium.chrome.browser.vr.XrTestFramework.PAGE_LOAD_TIMEOUT_S;
import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_CHECK_INTERVAL_LONG_MS;
import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_CHECK_INTERVAL_SHORT_MS; import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_CHECK_INTERVAL_SHORT_MS;
import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_TIMEOUT_LONG_MS; import static org.chromium.chrome.browser.vr.XrTestFramework.POLL_TIMEOUT_LONG_MS;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM_OR_STANDALONE; import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM_OR_STANDALONE;
...@@ -27,9 +28,12 @@ import org.chromium.chrome.browser.vr.util.NativeUiUtils; ...@@ -27,9 +28,12 @@ import org.chromium.chrome.browser.vr.util.NativeUiUtils;
import org.chromium.chrome.browser.vr.util.VrBrowserTransitionUtils; import org.chromium.chrome.browser.vr.util.VrBrowserTransitionUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.DOMUtils;
import java.util.concurrent.TimeoutException;
/** /**
* End-to-end tests for Daydream controller input while in the VR browser. * End-to-end tests for interacting with HTML input elements on a webpage.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
...@@ -125,4 +129,43 @@ public class VrBrowserWebInputEditingTest { ...@@ -125,4 +129,43 @@ public class VrBrowserWebInputEditingTest {
"Keyboard did not hide from unfocusing a web input box", POLL_TIMEOUT_LONG_MS, "Keyboard did not hide from unfocusing a web input box", POLL_TIMEOUT_LONG_MS,
POLL_CHECK_INTERVAL_SHORT_MS); POLL_CHECK_INTERVAL_SHORT_MS);
} }
/**
* Tests that interacting with a <code><select></code> tag on a webpage brings up a working
* Android selection dialog.
*/
@Test
@MediumTest
public void testSelectTag() throws TimeoutException, InterruptedException {
mVrTestRule.loadUrl(VrBrowserTestFramework.getFileUrlForHtmlTestFile("test_select_tag"),
PAGE_LOAD_TIMEOUT_S);
VrBrowserTransitionUtils.forceEnterVrBrowserOrFail(POLL_TIMEOUT_LONG_MS);
NativeUiUtils.enableMockedInput();
// Click on the <select> tag and wait for the resulting modal dialog to appear.
DOMUtils.clickNode(mVrBrowserTestFramework.getFirstTabWebContents(), "selectbox",
false /* goThroughRootAndroidView */);
NativeUiUtils.waitForModalDialogStatus(true /* shouldBeShown */, mVrTestRule.getActivity());
// Click on whichever option is near the center of the screen. We don't care which, as long
// as it's not the initial selection, which should be at the top. Clicking in the exact
// center can sometimes click in the area between two options, so offset slightly to prevent
// flakes from that.
// Most of the time, the first click will go through. However, it's possible to send the
// click while the dialog is technically present, but not fully ready, resulting in the
// click not registering. Since there doesn't seem to be a good way to wait for the dialog
// to be ready, try several times.
CriteriaHelper.pollInstrumentationThread(
()
-> {
if (!mVrTestRule.getActivity().getModalDialogManager().isShowing()) return true;
NativeUiUtils.clickElement(
UserFriendlyElementName.CONTENT_QUAD, new PointF(0f, 0.05f));
return false;
},
"Could not click on <select> modal dialog", POLL_TIMEOUT_LONG_MS,
POLL_CHECK_INTERVAL_LONG_MS);
// Wait on JavaScript to verify that a selection was made.
mVrBrowserTestFramework.waitOnJavaScriptStep();
mVrBrowserTestFramework.endTest();
}
} }
...@@ -27,8 +27,6 @@ import org.chromium.chrome.browser.vr.util.NativeUiUtils; ...@@ -27,8 +27,6 @@ import org.chromium.chrome.browser.vr.util.NativeUiUtils;
import org.chromium.chrome.browser.vr.util.VrBrowserTransitionUtils; import org.chromium.chrome.browser.vr.util.VrBrowserTransitionUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.RenderTestRule; import org.chromium.chrome.test.util.RenderTestRule;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.JavaScriptUtils; import org.chromium.content_public.browser.test.util.JavaScriptUtils;
import java.io.IOException; import java.io.IOException;
...@@ -105,7 +103,7 @@ public class VrBrowserJavaScriptModalDialogTest { ...@@ -105,7 +103,7 @@ public class VrBrowserJavaScriptModalDialogTest {
*/ */
private void executeJavaScriptAndWaitForDialog(String script) { private void executeJavaScriptAndWaitForDialog(String script) {
JavaScriptUtils.executeJavaScript(mActivity.getCurrentWebContents(), script); JavaScriptUtils.executeJavaScript(mActivity.getCurrentWebContents(), script);
checkDialogShowing("Could not spawn or locate a modal dialog.", true); NativeUiUtils.waitForModalDialogStatus(true /* shouldBeShown */, mActivity);
} }
/** /**
...@@ -116,17 +114,4 @@ public class VrBrowserJavaScriptModalDialogTest { ...@@ -116,17 +114,4 @@ public class VrBrowserJavaScriptModalDialogTest {
return (JavascriptTabModalDialog) ThreadUtils.runOnUiThreadBlocking( return (JavascriptTabModalDialog) ThreadUtils.runOnUiThreadBlocking(
() -> mActivity.getModalDialogManager().getCurrentDialogForTest().getController()); () -> mActivity.getModalDialogManager().getCurrentDialogForTest().getController());
} }
/**
* Check whether dialog is showing as expected.
*/
private void checkDialogShowing(final String errorMessage, final boolean shouldBeShown) {
CriteriaHelper.pollUiThread(new Criteria(errorMessage) {
@Override
public boolean isSatisfied() {
final boolean isShown = mActivity.getModalDialogManager().isShowing();
return shouldBeShown == isShown;
}
});
}
} }
...@@ -13,6 +13,7 @@ import org.junit.Assert; ...@@ -13,6 +13,7 @@ import org.junit.Assert;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.vr.TestVrShellDelegate; import org.chromium.chrome.browser.vr.TestVrShellDelegate;
import org.chromium.chrome.browser.vr.UiTestOperationType; import org.chromium.chrome.browser.vr.UiTestOperationType;
import org.chromium.chrome.browser.vr.UserFriendlyElementName; import org.chromium.chrome.browser.vr.UserFriendlyElementName;
...@@ -21,6 +22,7 @@ import org.chromium.chrome.browser.vr.VrDialog; ...@@ -21,6 +22,7 @@ import org.chromium.chrome.browser.vr.VrDialog;
import org.chromium.chrome.browser.vr.VrShell; import org.chromium.chrome.browser.vr.VrShell;
import org.chromium.chrome.browser.vr.VrUiTestActivityResult; import org.chromium.chrome.browser.vr.VrUiTestActivityResult;
import org.chromium.chrome.browser.vr.VrViewContainer; import org.chromium.chrome.browser.vr.VrViewContainer;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import java.io.File; import java.io.File;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
...@@ -209,6 +211,20 @@ public class NativeUiUtils { ...@@ -209,6 +211,20 @@ public class NativeUiUtils {
return vrShell.getVrViewContainerForTesting(); return vrShell.getVrViewContainerForTesting();
} }
/**
* Waits until a modal dialog is or is not shown.
*/
public static void waitForModalDialogStatus(
final boolean shouldBeShown, final ChromeActivity activity) {
CriteriaHelper.pollUiThread(
()
-> {
return shouldBeShown == activity.getModalDialogManager().isShowing();
},
"Timed out waiting for modal dialog to "
+ (shouldBeShown ? "be shown" : "not be shown"));
}
private static void clickFallbackUiButton(int buttonId) throws InterruptedException { private static void clickFallbackUiButton(int buttonId) throws InterruptedException {
VrShell vrShell = TestVrShellDelegate.getVrShellForTesting(); VrShell vrShell = TestVrShellDelegate.getVrShellForTesting();
VrViewContainer viewContainer = vrShell.getVrViewContainerForTesting(); VrViewContainer viewContainer = vrShell.getVrViewContainerForTesting();
......
<!DOCTYPE hmtl>
<!--
Used to test that interacting with a <select> tag on a webpage brings up a
working Android selection dialog.
-->
<html>
<body>
<script src="../../../../../../third_party/WebKit/LayoutTests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
<script>
var t = async_test("<select> tag works properly in VR browser.");
function onSelectChange(newValue) {
t.step(() => {
assert_not_equals(newValue, "initial_option",
"Newly selected value is the starting value");
assert_true(newValue.startsWith("option"),
"Didn't get initial option, but didn't get valid option either");
});
t.done();
}
</script>
<select id="selectbox" onchange="onSelectChange(this.value)">
<option value="initial_option" selected="true">initial option</option>
<option value="option1">option 1</option>
<option value="option2">option 2</option>
<option value="option3">option 3</option>
<option value="option4">option 4</option>
<option value="option5">option 5</option>
<option value="option6">option 6</option>
<option value="option7">option 7</option>
<option value="option8">option 8</option>
<option value="option9">option 9</option>
</select>
</body>
</html>
\ No newline at end of file
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