Commit a5162b22 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Fix consecutive identical showcasts.

Before this change, consecutive showcasts with identical element areas
did not work unless the user somehow changed the area (e.g., scrolling).
This was because the last showcasted viewport and element was cached and
not properly reset.

Bug: b/161471176
Change-Id: I746cd365c2b1bcdf2fcf7271cbc7666d83bea0c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2306096Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#790288}
parent 57deecbb
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.autofill_assistant;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.MatcherAssert.assertThat;
......@@ -122,6 +123,74 @@ public class AutofillAssistantOverlayIntegrationTest {
assertThat(checkElementExists(mTestRule.getWebContents(), "touch_area_four"), is(true));
}
/**
* Showcasts the same element twice in a row, and taps it the second time. Tests that the second
* showcast works correctly, even though the showcasted area hasn't changed (see b/161471176).
*/
@Test
@MediumTest
public void testRepeatedShowCastOnSameElement() throws Exception {
SelectorProto element =
(SelectorProto) SelectorProto.newBuilder()
.addFilters(
SelectorProto.Filter.newBuilder().setCssSelector("#touch_area_one"))
.build();
ArrayList<ActionProto> list = new ArrayList<>();
list.add(
(ActionProto) ActionProto.newBuilder()
.setFocusElement(FocusElementProto.newBuilder()
.setElement(element)
.setTouchableElementArea(
ElementAreaProto.newBuilder().addTouchable(
Rectangle.newBuilder().addElements(
element))))
.build());
list.add((ActionProto) ActionProto.newBuilder()
.setPrompt(PromptProto.newBuilder()
.setMessage("First Prompt")
.addChoices(PromptProto.Choice.newBuilder().setChip(
ChipProto.newBuilder().setText("Continue"))))
.build());
list.add(
(ActionProto) ActionProto.newBuilder()
.setFocusElement(FocusElementProto.newBuilder()
.setElement(element)
.setTouchableElementArea(
ElementAreaProto.newBuilder().addTouchable(
Rectangle.newBuilder().addElements(
element))))
.build());
list.add((ActionProto) ActionProto.newBuilder()
.setPrompt(PromptProto.newBuilder()
.setMessage("Second Prompt")
.addChoices(PromptProto.Choice.newBuilder().setChip(
ChipProto.newBuilder().setText("Done"))))
.build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("autofill_assistant_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Done")))
.build(),
list);
runScript(script);
waitUntil(() -> checkElementOnScreen(mTestRule, "touch_area_one"));
waitUntilViewMatchesCondition(withText("First Prompt"), isCompletelyDisplayed());
onView(withContentDescription("Continue")).perform(click());
waitUntilViewMatchesCondition(withText("Second Prompt"), isCompletelyDisplayed());
// Tapping on the element should remove it from the DOM.
assertThat(checkElementExists(mTestRule.getWebContents(), "touch_area_one"), is(true));
tapElement(mTestRule, "touch_area_one");
waitUntil(() -> !checkElementExists(mTestRule.getWebContents(), "touch_area_one"));
// Tapping on the element should be blocked by the overlay.
tapElement(mTestRule, "touch_area_four");
assertThat(checkElementExists(mTestRule.getWebContents(), "touch_area_four"), is(true));
}
/**
* Tests that clicking on a document element requiring scrolling works with a showcast.
*/
......
......@@ -50,6 +50,9 @@ void ElementArea::Clear() {
void ElementArea::SetFromProto(const ElementAreaProto& proto) {
rectangles_.clear();
last_visual_viewport_ = RectF();
last_rectangles_.clear();
AddRectangles(proto.touchable(), /* restricted= */ false);
AddRectangles(proto.restricted(), /* restricted= */ true);
......
......@@ -164,6 +164,17 @@ TEST_F(ElementAreaTest, CallOnUpdate) {
EXPECT_THAT(reported_area_, ElementsAre(MatchingRectF(25, 25, 75, 75)));
}
TEST_F(ElementAreaTest, CallOnUpdateAfterSetFromProto) {
EXPECT_CALL(mock_web_controller_,
OnGetElementPosition(Eq(Selector({"#found"}).MustBeVisible()), _))
.WillRepeatedly(RunOnceCallback<1>(true, RectF(25, 25, 75, 75)));
SetElement("#found");
EXPECT_EQ(on_update_call_count_, 1);
SetElement("#found");
EXPECT_EQ(on_update_call_count_, 2);
}
TEST_F(ElementAreaTest, DontCallOnUpdateWhenViewportMissing) {
// Swallowing calls to OnGetVisualViewport guarantees that the viewport
// position will never be known.
......
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