Commit 425c2cb1 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Attempt at fixing flakiness of autofill interactive ui tests

This is an attempt at fixing the flakiness of a number of autofill interactive
ui tests by changing the pattern from

  action();
  wait_for_result();

to

  setup_waiting();
  action();
  wait_for_result();

The former pattern might lose some events in case action() happens to complete
before wait_for_result() is called.

Bug: 967588
Change-Id: I66800ed03fd27d9e6cf4be6ee53cc0f29200f21d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757019Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Commit-Queue: Dominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688227}
parent 0dbc80a7
......@@ -110,20 +110,20 @@ class AutofillCapturedSitesInteractiveTest
// Press the down key to highlight the first choice in the autofill
// suggestion drop down.
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kPreviewFormData},
autofill_wait_for_action_interval);
SendKeyToPopup(frame, ui::DomKey::ARROW_DOWN);
if (!test_delegate()->Wait({ObservedUiEvents::kPreviewFormData},
autofill_wait_for_action_interval)) {
if (!test_delegate()->Wait()) {
LOG(WARNING) << "Failed to select an option from the "
<< "autofill suggestion drop down.";
continue;
}
// Press the enter key to invoke autofill using the first suggestion.
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kFormDataFilled},
autofill_wait_for_action_interval);
SendKeyToPopup(frame, ui::DomKey::ENTER);
if (!test_delegate()->Wait({ObservedUiEvents::kFormDataFilled},
autofill_wait_for_action_interval)) {
if (!test_delegate()->Wait()) {
LOG(WARNING) << "Failed to fill the form.";
continue;
}
......@@ -263,13 +263,13 @@ class AutofillCapturedSitesInteractiveTest
frame, &rect))
return false;
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kSuggestionShown},
autofill_wait_for_action_interval);
if (!captured_sites_test_utils::TestRecipeReplayer::
SimulateLeftMouseClickAt(rect.CenterPoint(), frame))
return false;
return test_delegate()->Wait({ObservedUiEvents::kSuggestionShown},
autofill_wait_for_action_interval);
return test_delegate()->Wait();
}
bool StringToFieldType(const std::string& str, ServerFieldType* type) {
......
......@@ -1104,9 +1104,9 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillViaClick) {
ASSERT_NO_FATAL_FAILURE(FocusFirstNameField());
// Now click it.
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kSuggestionShown});
ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
test_delegate()->Wait({ObservedUiEvents::kSuggestionShown});
EXPECT_TRUE(test_delegate()->Wait());
// Press the down arrow to select the suggestion and preview the autofilled
// form.
......@@ -1157,9 +1157,9 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, Click) {
ui_test_utils::NavigateToURL(browser(), GetTestUrl()));
// This click should activate the autofill popup.
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kSuggestionShown});
ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
test_delegate()->Wait({ObservedUiEvents::kSuggestionShown});
EXPECT_TRUE(test_delegate()->Wait());
// Press the down arrow to select the suggestion and preview the autofilled
// form.
......@@ -1194,9 +1194,9 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DontAutofillForOutsideClick) {
ASSERT_NO_FATAL_FAILURE(ClickElementWithId("disabled-button"));
ASSERT_NO_FATAL_FAILURE(MakeSurePopupDoesntAppear());
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kSuggestionShown});
ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
test_delegate()->Wait({ObservedUiEvents::kSuggestionShown});
EXPECT_TRUE(test_delegate()->Wait());
}
// Test that a field is still autofillable after the previously autofilled
......@@ -2038,11 +2038,11 @@ IN_PROC_BROWSER_TEST_P(AutofillCompanyInteractiveTest,
FocusFieldByName("company");
// Now click it.
test_delegate()->Reset();
test_delegate()->SetExpectations({ObservedUiEvents::kSuggestionShown},
base::TimeDelta::FromSeconds(3));
ASSERT_NO_FATAL_FAILURE(ClickElementWithId("company"));
bool found = test_delegate()->Wait({ObservedUiEvents::kSuggestionShown},
base::TimeDelta::FromSeconds(3));
bool found = test_delegate()->Wait();
if (!company_name_enabled_) {
EXPECT_FALSE(found);
......
......@@ -50,15 +50,14 @@ void AutofillManagerTestDelegateImpl::DidShowSuggestions() {
void AutofillManagerTestDelegateImpl::OnTextFieldChanged() {}
void AutofillManagerTestDelegateImpl::Reset() {
event_waiter_.reset();
}
bool AutofillManagerTestDelegateImpl::Wait(
void AutofillManagerTestDelegateImpl::SetExpectations(
std::list<ObservedUiEvents> expected_events,
base::TimeDelta timeout) {
event_waiter_ =
std::make_unique<EventWaiter<ObservedUiEvents>>(expected_events, timeout);
}
bool AutofillManagerTestDelegateImpl::Wait() {
return event_waiter_->Wait();
}
......@@ -118,10 +117,10 @@ void AutofillUiTest::SendKeyToPageAndWait(
ui::DomCode code,
ui::KeyboardCode key_code,
std::list<ObservedUiEvents> expected_events) {
test_delegate()->Reset();
test_delegate()->SetExpectations(std::move(expected_events));
content::SimulateKeyPress(GetWebContents(), key, code, key_code, false, false,
false, false);
test_delegate()->Wait(std::move(expected_events));
test_delegate()->Wait();
}
void AutofillUiTest::SendKeyToPopup(content::RenderFrameHost* render_frame_host,
......@@ -168,19 +167,19 @@ void AutofillUiTest::SendKeyToPopupAndWait(
event.windows_key_code = key_code;
event.dom_code = static_cast<int>(code);
event.dom_key = key;
test_delegate()->Reset();
test_delegate()->SetExpectations(std::move(expected_events));
// Install the key press event sink to ensure that any events that are not
// handled by the installed callbacks do not end up crashing the test.
widget->AddKeyPressEventCallback(key_press_event_sink_);
widget->ForwardKeyboardEvent(event);
test_delegate()->Wait(std::move(expected_events));
test_delegate()->Wait();
widget->RemoveKeyPressEventCallback(key_press_event_sink_);
}
void AutofillUiTest::DoNothingAndWait(unsigned seconds) {
test_delegate()->Reset();
ASSERT_FALSE(test_delegate()->Wait({ObservedUiEvents::kNoEvent},
base::TimeDelta::FromSeconds(seconds)));
test_delegate()->SetExpectations({ObservedUiEvents::kNoEvent},
base::TimeDelta::FromSeconds(seconds));
ASSERT_FALSE(test_delegate()->Wait());
}
void AutofillUiTest::SendKeyToDataListPopup(ui::DomKey key) {
......
......@@ -41,10 +41,10 @@ class AutofillManagerTestDelegateImpl
void DidShowSuggestions() override;
void OnTextFieldChanged() override;
void Reset();
bool Wait(std::list<ObservedUiEvents> expected_events,
base::TimeDelta timeout = base::TimeDelta::FromSeconds(0));
void SetExpectations(
std::list<ObservedUiEvents> expected_events,
base::TimeDelta timeout = base::TimeDelta::FromSeconds(0));
bool Wait();
void SetIsExpectingDynamicRefill(bool expect_refill) {
is_expecting_dynamic_refill_ = expect_refill;
......
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