Commit d3270d1c authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Tests for expand/collapse sheet.

This patch adds unit tests and a integration / UI test for the recently
added auto expand/collapse sheet behavior for prompt actions.

Note that there are two sides to this, Prompt has a
disable_force_expand_sheet option now to prevent prompt from auto
expanding when entering that state. The other part is
ConfigureBottomSheet, which now has a oneof (expand, collapse) to
automatically update the bottom sheet to the expected state.

Bug: b/145204744
Change-Id: I857a2be13e090d9e5d663419ead60497102cb897
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007721
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarSandro Maggi <sandromaggi@google.com>
Cr-Commit-Position: refs/heads/master@{#734625}
parent e2b330a7
......@@ -23,4 +23,5 @@ public class AssistantTagsForTesting {
public static final String COLLECT_USER_DATA_TERMS_REQUIRE_REVIEW = "require_review";
public static final String VERTICAL_EXPANDER_CHEVRON = "chevron";
public static final String COLLECT_USER_DATA_CHOICE_LIST = "choicelist";
public static final String RECYCLER_VIEW_TAG = "recycler_view";
}
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.autofill_assistant.carousel;
import static org.chromium.chrome.browser.autofill_assistant.AssistantTagsForTesting.RECYCLER_VIEW_TAG;
import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.OrientationHelper;
......@@ -41,6 +43,7 @@ public class AssistantActionsCarouselCoordinator implements AssistantCarouselCoo
public AssistantActionsCarouselCoordinator(Context context, AssistantCarouselModel model) {
mView = new RecyclerView(context);
mView.setTag(RECYCLER_VIEW_TAG);
CustomLayoutManager layoutManager = new CustomLayoutManager();
// Workaround for b/128679161.
......
......@@ -12,13 +12,18 @@ import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.chromium.chrome.browser.autofill_assistant.AssistantTagsForTesting.RECYCLER_VIEW_TAG;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.getAbsoluteBoundingRect;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.startAutofillAssistant;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewAssertionTrue;
......@@ -99,6 +104,17 @@ public class AutofillAssistantBottomsheetTest {
mTestRule.getActivity().getScrim().disableAnimationForTesting(true);
}
private AutofillAssistantTestScript makeScriptWithActionArray(
ArrayList<ActionProto> actionsList) {
return new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("bottomsheet_behaviour_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Bottomsheet behaviour")))
.build(),
actionsList);
}
private AutofillAssistantTestScript makeScript(
ViewportResizing resizing, PeekMode peekMode, boolean withDetails) {
ArrayList<ActionProto> list = new ArrayList<>();
......@@ -139,13 +155,7 @@ public class AutofillAssistantBottomsheetTest {
.setText("Done"))))
.build());
return new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("bottomsheet_behaviour_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Bottomsheet behaviour")))
.build(),
list);
return makeScriptWithActionArray(list);
}
@Test
......@@ -381,6 +391,80 @@ public class AutofillAssistantBottomsheetTest {
onView(withId(R.id.autofill_assistant)).check(doesNotExist());
}
@Test
@MediumTest
public void testBottomSheetAutoCollapseAndExpand() {
ArrayList<ActionProto> list = new ArrayList<>();
// Prompt.
list.add((ActionProto) ActionProto.newBuilder()
.setPrompt(PromptProto.newBuilder()
.setMessage("Hello world!")
.addChoices(Choice.newBuilder().setChip(
ChipProto.newBuilder()
.setType(ChipType.DONE_ACTION)
.setText("Focus element"))))
.build());
// Focus on the bottom element.
list.add((ActionProto) ActionProto.newBuilder()
.setFocusElement(FocusElementProto.newBuilder().setElement(
ElementReferenceProto.newBuilder().addSelectors("p.bottom")))
.build());
// Set handle and header peek mode and auto collapse to that state.
list.add((ActionProto) ActionProto.newBuilder()
.setConfigureBottomSheet(ConfigureBottomSheetProto.newBuilder()
.setViewportResizing(NO_RESIZE)
.setPeekMode(HANDLE_HEADER)
.setCollapse(true))
.build());
// Add sticky "Next" button. Disable auto expanding the sheet for prompt actions.
list.add((ActionProto) ActionProto.newBuilder()
.setPrompt(PromptProto.newBuilder()
.addChoices(Choice.newBuilder().setChip(
ChipProto.newBuilder()
.setType(ChipType.DONE_ACTION)
.setSticky(true)
.setText("Sticky next")))
.setDisableForceExpandSheet(true))
.build());
// Expand the sheet.
list.add((ActionProto) ActionProto.newBuilder()
.setConfigureBottomSheet(ConfigureBottomSheetProto.newBuilder()
.setViewportResizing(NO_RESIZE)
.setExpand(true))
.build());
// Add "Done" button.
list.add((ActionProto) ActionProto.newBuilder()
.setPrompt(PromptProto.newBuilder().addChoices(
Choice.newBuilder().setChip(ChipProto.newBuilder()
.setType(ChipType.DONE_ACTION)
.setText("Done"))))
.build());
AutofillAssistantTestScript script = makeScriptWithActionArray(list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
waitUntilViewMatchesCondition(withText("Focus element"), isCompletelyDisplayed());
onView(withText("Focus element")).perform(click());
// Check that the sheet is in peek state and has a sticky button. There is
// a second button still in the hidden carousel.
waitUntilViewMatchesCondition(
allOf(withText("Sticky next"), isDescendantOfA(withId(R.id.header))),
isCompletelyDisplayed());
onView(allOf(withText("Sticky next"), isDescendantOfA(withTagValue(is(RECYCLER_VIEW_TAG)))))
.check(matches(not(isDisplayed())));
onView(allOf(withText("Sticky next"), isDescendantOfA(withId(R.id.header))))
.perform(click());
// Check that the sheet is now expanded and the done button is part of the recycler view,
// not the header.
waitUntilViewMatchesCondition(
allOf(withText("Done"), isDescendantOfA(withTagValue(is(RECYCLER_VIEW_TAG)))),
isCompletelyDisplayed());
}
private ViewAction swipeDownToMinimize() {
return actionWithAssertions(
new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER, view -> {
......
......@@ -298,5 +298,25 @@ TEST_F(ConfigureBottomSheetActionTest, WaitIfResizeLayoutAfterVisualViewport) {
ASSERT_TRUE(on_resize_cb_);
}
TEST_F(ConfigureBottomSheetActionTest, ExpandOrCollapseSheetNotSet) {
EXPECT_CALL(mock_action_delegate_, ExpandBottomSheet()).Times(0);
EXPECT_CALL(mock_action_delegate_, CollapseBottomSheet()).Times(0);
Run();
}
TEST_F(ConfigureBottomSheetActionTest, ExpectExpand) {
proto_.set_expand(true);
EXPECT_CALL(mock_action_delegate_, ExpandBottomSheet()).Times(1);
EXPECT_CALL(mock_action_delegate_, CollapseBottomSheet()).Times(0);
Run();
}
TEST_F(ConfigureBottomSheetActionTest, ExpectCollapse) {
proto_.set_collapse(true);
EXPECT_CALL(mock_action_delegate_, ExpandBottomSheet()).Times(0);
EXPECT_CALL(mock_action_delegate_, CollapseBottomSheet()).Times(1);
Run();
}
} // namespace
} // namespace autofill_assistant
......@@ -384,5 +384,28 @@ TEST_F(PromptActionTest, NormalMessageSet) {
action.ProcessAction(callback_.Get());
}
TEST_F(PromptActionTest, ForceExpandSheetDefault) {
auto* ok_proto = prompt_proto_->add_choices();
ok_proto->mutable_chip()->set_text("Ok");
ok_proto->mutable_chip()->set_type(HIGHLIGHTED_ACTION);
ok_proto->set_server_payload("ok");
EXPECT_CALL(mock_action_delegate_, Prompt(_, Eq(false)));
PromptAction action(&mock_action_delegate_, proto_);
action.ProcessAction(callback_.Get());
}
TEST_F(PromptActionTest, ForceExpandSheetDisable) {
auto* ok_proto = prompt_proto_->add_choices();
ok_proto->mutable_chip()->set_text("Ok");
ok_proto->mutable_chip()->set_type(HIGHLIGHTED_ACTION);
ok_proto->set_server_payload("ok");
prompt_proto_->set_disable_force_expand_sheet(true);
EXPECT_CALL(mock_action_delegate_, Prompt(_, Eq(true)));
PromptAction action(&mock_action_delegate_, proto_);
action.ProcessAction(callback_.Get());
}
} // namespace
} // namespace autofill_assistant
......@@ -1749,4 +1749,64 @@ TEST_F(ControllerTest, WriteUserData) {
TermsAndConditionsState::ACCEPTED);
}
TEST_F(ControllerTest, ExpandOrCollapseBottomSheet) {
{
testing::InSequence seq;
EXPECT_CALL(mock_observer_, OnCollapseBottomSheet()).Times(1);
EXPECT_CALL(mock_observer_, OnExpandBottomSheet()).Times(1);
}
controller_->CollapseBottomSheet();
controller_->ExpandBottomSheet();
}
TEST_F(ControllerTest, ShouldPromptActionExpandSheet) {
// Expect this to be true initially.
EXPECT_TRUE(controller_->ShouldPromptActionExpandSheet());
controller_->SetExpandSheetForPromptAction(false);
EXPECT_FALSE(controller_->ShouldPromptActionExpandSheet());
controller_->SetExpandSheetForPromptAction(true);
EXPECT_TRUE(controller_->ShouldPromptActionExpandSheet());
}
TEST_F(ControllerTest, SecondPromptActionShouldDefaultToExpandSheet) {
SupportsScriptResponseProto script_response;
AddRunnableScript(&script_response, "runnable")
->mutable_presentation()
->set_autostart(true);
SetNextScriptResponse(script_response);
ActionsResponseProto runnable_script;
// Prompt action 1 which disables auto expand.
auto* prompt_action = runnable_script.add_actions()->mutable_prompt();
prompt_action->add_choices()->mutable_chip()->set_text("continue");
prompt_action->set_disable_force_expand_sheet(true);
// Prompt action 2 using the default should fall back to auto expand again.
runnable_script.add_actions()
->mutable_prompt()
->add_choices()
->mutable_chip()
->set_text("next");
SetupActionsForScript("runnable", runnable_script);
Start();
// The first prompt should not auto expand.
EXPECT_EQ(AutofillAssistantState::PROMPT, controller_->GetState());
EXPECT_FALSE(controller_->ShouldPromptActionExpandSheet());
ASSERT_THAT(controller_->GetUserActions(), SizeIs(1));
EXPECT_EQ(controller_->GetUserActions()[0].chip().text, "continue");
// Click "continue"
EXPECT_TRUE(controller_->PerformUserAction(0));
// The second prompt should fall back to default auto expand again.
EXPECT_EQ(AutofillAssistantState::PROMPT, controller_->GetState());
EXPECT_TRUE(controller_->ShouldPromptActionExpandSheet());
ASSERT_THAT(controller_->GetUserActions(), SizeIs(1));
EXPECT_EQ(controller_->GetUserActions()[0].chip().text, "next");
}
} // namespace autofill_assistant
......@@ -1679,10 +1679,6 @@ message ConfigureBottomSheetProto {
// Show swipe handle, header, progress bar, suggestions and actions.
HANDLE_HEADER_CAROUSELS = 3;
// Entirely hide the bottom sheet when collapsed.
// TBD:
HIDDEN = 4;
}
// Whether the viewport should be resized. Resizing the viewport is an
......
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