Commit 55863526 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Fix VrShellTransitionTest#testStartActivityTriggersDoff*

Implements two fixes that were causing testStartActivityTriggersDoff* to
fail 100% of the time.

1. Waits until the UI is quiescent after starting the activity, as
previously, clicks were being sent before the DOFF prompt was visible,
causing the test to time out.

2. Applies a small deadzone to the head offset used for repositioning
the VR controller on 6DOF devices. Even on 3DOF devices, the offset
drifted within a very tiny area, which cause the controller to be
perpetually dirty and prevent the UI from reaching quiescence.

Bug: 831589, 848074
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr
Change-Id: Ic912dd3aa92ac2102c34e4acc330447a3ce0ca8d
Reviewed-on: https://chromium-review.googlesource.com/1087723
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564970}
parent 1941afe3
...@@ -29,7 +29,6 @@ import org.junit.runner.RunWith; ...@@ -29,7 +29,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -40,6 +39,7 @@ import org.chromium.chrome.browser.preferences.PreferencesLauncher; ...@@ -40,6 +39,7 @@ import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
import org.chromium.chrome.browser.vr_shell.mock.MockVrDaydreamApi; import org.chromium.chrome.browser.vr_shell.mock.MockVrDaydreamApi;
import org.chromium.chrome.browser.vr_shell.rules.ChromeTabbedActivityVrTestRule; import org.chromium.chrome.browser.vr_shell.rules.ChromeTabbedActivityVrTestRule;
import org.chromium.chrome.browser.vr_shell.util.NativeUiUtils;
import org.chromium.chrome.browser.vr_shell.util.NfcSimUtils; import org.chromium.chrome.browser.vr_shell.util.NfcSimUtils;
import org.chromium.chrome.browser.vr_shell.util.TransitionUtils; import org.chromium.chrome.browser.vr_shell.util.TransitionUtils;
import org.chromium.chrome.browser.vr_shell.util.VrShellDelegateUtils; import org.chromium.chrome.browser.vr_shell.util.VrShellDelegateUtils;
...@@ -370,7 +370,6 @@ public class VrShellTransitionTest { ...@@ -370,7 +370,6 @@ public class VrShellTransitionTest {
* Tests that attempting to start an Activity through the Activity context in VR triggers DOFF. * Tests that attempting to start an Activity through the Activity context in VR triggers DOFF.
*/ */
@Test @Test
@DisabledTest(message = "https://crbug.com/831589")
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM) @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@MediumTest @MediumTest
public void testStartActivityTriggersDoffChromeActivity() public void testStartActivityTriggersDoffChromeActivity()
...@@ -383,7 +382,6 @@ public class VrShellTransitionTest { ...@@ -383,7 +382,6 @@ public class VrShellTransitionTest {
* DOFF. * DOFF.
*/ */
@Test @Test
@DisabledTest(message = "https://crbug.com/831589")
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM) @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@MediumTest @MediumTest
public void testStartActivityTriggersDoffAppContext() public void testStartActivityTriggersDoffAppContext()
...@@ -400,10 +398,15 @@ public class VrShellTransitionTest { ...@@ -400,10 +398,15 @@ public class VrShellTransitionTest {
MockVrDaydreamApi mockApi = new MockVrDaydreamApi(); MockVrDaydreamApi mockApi = new MockVrDaydreamApi();
mockApi.setExitFromVrReturnValue(false); mockApi.setExitFromVrReturnValue(false);
VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi); VrShellDelegateUtils.getDelegateInstance().overrideDaydreamApiForTesting(mockApi);
NativeUiUtils.performActionAndWaitForUiQuiescence(() -> {
ThreadUtils.runOnUiThreadBlocking(() -> {
Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
context.startActivity(preferencesIntent);
});
});
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
context.startActivity(preferencesIntent);
VrShellDelegateUtils.getDelegateInstance().acceptDoffPromptForTesting(); VrShellDelegateUtils.getDelegateInstance().acceptDoffPromptForTesting();
}); });
......
...@@ -49,13 +49,22 @@ public class NativeUiUtils { ...@@ -49,13 +49,22 @@ public class NativeUiUtils {
* @param elementName The UserFriendlyElementName that will be clicked on. * @param elementName The UserFriendlyElementName that will be clicked on.
* @param position The position within the element to click on. * @param position The position within the element to click on.
*/ */
public static void clickElementAndWaitForUiQuiescence(int elementName, PointF position) public static void clickElementAndWaitForUiQuiescence(
final int elementName, final PointF position) throws InterruptedException {
performActionAndWaitForUiQuiescence(() -> { clickElement(elementName, position); });
}
/**
* Runs the given Runnable and waits until the native UI reports that it is quiescent.
* @param action A Runnable containing the action to perform.
*/
public static void performActionAndWaitForUiQuiescence(Runnable action)
throws InterruptedException { throws InterruptedException {
final TestVrShellDelegate instance = TestVrShellDelegate.getInstance(); final TestVrShellDelegate instance = TestVrShellDelegate.getInstance();
final CountDownLatch resultLatch = new CountDownLatch(1); final CountDownLatch resultLatch = new CountDownLatch(1);
instance.setUiExpectingActivityForTesting( instance.setUiExpectingActivityForTesting(
DEFAULT_UI_QUIESCENCE_TIMEOUT_MS, () -> { resultLatch.countDown(); }); DEFAULT_UI_QUIESCENCE_TIMEOUT_MS, () -> { resultLatch.countDown(); });
clickElement(elementName, position); action.run();
// Wait for any outstanding animations to finish. // Wait for any outstanding animations to finish.
resultLatch.await(); resultLatch.await();
......
...@@ -27,6 +27,10 @@ constexpr float kLaserStartDisplacement = 0.045; ...@@ -27,6 +27,10 @@ constexpr float kLaserStartDisplacement = 0.045;
constexpr float kFadeDistanceFromFace = 0.34f; constexpr float kFadeDistanceFromFace = 0.34f;
constexpr float kDeltaAlpha = 3.0f; constexpr float kDeltaAlpha = 3.0f;
// Very small deadzone that should be undetectable to users, but prevents the
// head offset from being updated every frame on 3DOF devices.
constexpr float kHeadOffsetDeadzone = 0.0005f;
void ClampTouchpadPosition(gfx::Vector2dF* position) { void ClampTouchpadPosition(gfx::Vector2dF* position) {
position->set_x(base::ClampToRange(position->x(), 0.0f, 1.0f)); position->set_x(base::ClampToRange(position->x(), 0.0f, 1.0f));
position->set_y(base::ClampToRange(position->y(), 0.0f, 1.0f)); position->set_y(base::ClampToRange(position->y(), 0.0f, 1.0f));
...@@ -297,8 +301,15 @@ bool VrController::IsConnected() { ...@@ -297,8 +301,15 @@ bool VrController::IsConnected() {
void VrController::UpdateState(const gfx::Transform& head_pose) { void VrController::UpdateState(const gfx::Transform& head_pose) {
gfx::Transform inv_pose; gfx::Transform inv_pose;
if (head_pose.GetInverse(&inv_pose)) { if (head_pose.GetInverse(&inv_pose)) {
head_offset_.SetPoint(0, 0, 0); auto current_head_offset = gfx::Point3F();
inv_pose.TransformPoint(&head_offset_); inv_pose.TransformPoint(&current_head_offset);
// The head offset drifts by a very tiny amount even in 3DOF devices, so
// apply a small deadzone to only update the head offset when the head
// actually moves.
if (head_offset_.SquaredDistanceTo(current_head_offset) >
kHeadOffsetDeadzone) {
head_offset_ = current_head_offset;
}
} }
gvr::Mat4f gvr_head_pose; gvr::Mat4f gvr_head_pose;
......
...@@ -554,7 +554,7 @@ void Ui::AcceptDoffPromptForTesting() { ...@@ -554,7 +554,7 @@ void Ui::AcceptDoffPromptForTesting() {
DCHECK(model_->active_modal_prompt_type != kModalPromptTypeNone); DCHECK(model_->active_modal_prompt_type != kModalPromptTypeNone);
auto* prompt = scene_->GetUiElementByName(kExitPrompt); auto* prompt = scene_->GetUiElementByName(kExitPrompt);
DCHECK(prompt); DCHECK(prompt);
auto* button = prompt->GetDescendantByType(kTypePromptSecondaryButton); auto* button = prompt->GetDescendantByType(kTypePromptPrimaryButton);
DCHECK(button); DCHECK(button);
button->OnHoverEnter({0.5f, 0.5f}); button->OnHoverEnter({0.5f, 0.5f});
button->OnButtonDown({0.5f, 0.5f}); button->OnButtonDown({0.5f, 0.5f});
......
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