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