Commit 4e484a8f authored by Ian Struiksma's avatar Ian Struiksma Committed by Commit Bot

Give test hooks to allow autofill test to keep popup open

On some test bots, mac dock or external values cause the browser to
make minor resizings of the frame. These are extraneous to our tests
so we would like to ignore those during tests.

This CL provides a test hook by adding test access methods to
ChromeAutofillClient to make the autofill popup more
resistant to hiding from frame resizes, and then has AutofillUiTest
access that hook when running Interactive UI tests.

This re-enables autofill interactive tests on mac bots.


Bug: 967588
Change-Id: Id9e25988f0cf64f0aa0631a48d48eb982b116c34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473802
Commit-Queue: Ian Struiksma <ianstruiksma@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818550}
parent fc2f4ea8
......@@ -3,8 +3,6 @@
// found in the LICENSE file.
#include "build/build_config.h"
// Disable all tests in this file on Mac for flake (crbug.com/1079249)
#if !defined(OS_MAC)
#include <string>
#include <tuple>
......@@ -345,14 +343,6 @@ class AutofillInteractiveTestBase : public AutofillUiTest {
return std::move(response);
}
content::WebContents* GetWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
content::RenderViewHost* GetRenderViewHost() {
return GetWebContents()->GetRenderViewHost();
}
void CreateTestProfile() {
AutofillProfile profile;
test::SetProfileInfo(&profile, "Milton", "C.", "Waddams",
......@@ -3506,5 +3496,3 @@ INSTANTIATE_TEST_SUITE_P(All,
AutofillRestrictUnownedFieldsTest,
testing::Bool());
} // namespace autofill
#endif // !defined(OS_MAC)
......@@ -10,6 +10,7 @@
#include "chrome/browser/autofill/autofill_uitest.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/interactive_test_utils.h"
......@@ -72,7 +73,9 @@ void AutofillUiTest::SetUpOnMainThread() {
LOG(ERROR) << "crbug/967588: AutofillUiTest::SetUpOnMainThread() entered";
// Don't want Keychain coming up on Mac.
test::DisableSystemServices(browser()->profile()->GetPrefs());
// Make autofill popup stay open by ignoring external changes when possible.
ChromeAutofillClient::FromWebContents(GetWebContents())
->KeepPopupOpenForTesting();
// Inject the test delegate into the AutofillManager of the main frame.
RenderFrameHostChanged(/* old_host = */ nullptr,
/* new_host = */ GetWebContents()->GetMainFrame());
......
......@@ -204,6 +204,10 @@ void AutofillPopupControllerImpl::Hide(PopupHidingReason reason) {
reason == PopupHidingReason::kEndEditing)) {
return; // Don't close the popup while waiting for an update.
}
// For tests, keep open when hiding is due to external stimuli.
if (keep_popup_open_for_testing_ &&
reason == PopupHidingReason::kWidgetChanged)
return; // Don't close the popup because the browser window is resized.
if (delegate_) {
delegate_->ClearPreviewedForm();
delegate_->OnPopupHidden();
......
......@@ -67,6 +67,8 @@ class AutofillPopupControllerImpl : public AutofillPopupController {
// view is destroyed.
void PinView();
void KeepPopupOpenForTesting() { keep_popup_open_for_testing_ = true; }
// Returns (not elided) suggestions currently held by the controller.
base::span<const Suggestion> GetUnelidedSuggestions() const;
......@@ -173,6 +175,10 @@ class AutofillPopupControllerImpl : public AutofillPopupController {
// The current Autofill query values.
std::vector<Suggestion> suggestions_;
// If set to true, the popup will stay open regardless of external changes on
// the machine that would normally cause the popup to be hidden.
bool keep_popup_open_for_testing_ = false;
// The line that is currently selected by the user, null indicates that no
// line is currently selected.
base::Optional<int> selected_line_;
......
......@@ -501,6 +501,12 @@ void ChromeAutofillClient::ShowAutofillPopup(
popup_controller_->Show(open_args.suggestions,
open_args.autoselect_first_suggestion.value(),
open_args.popup_type);
// When testing, try to keep popup open when the reason to hide is from an
// external browser frame resize that is extraneous to our testing goals.
if (keep_popup_open_for_testing_ && popup_controller_.get()) {
popup_controller_->KeepPopupOpenForTesting();
}
}
void ChromeAutofillClient::UpdateAutofillPopupDataListValues(
......
......@@ -160,6 +160,7 @@ class ChromeAutofillClient
base::WeakPtr<AutofillPopupControllerImpl> popup_controller_for_testing() {
return popup_controller_;
}
void KeepPopupOpenForTesting() { keep_popup_open_for_testing_ = true; }
#if !defined(OS_ANDROID)
// ZoomObserver implementation.
......@@ -180,6 +181,9 @@ class ChromeAutofillClient
base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
CardUnmaskPromptControllerImpl unmask_controller_;
std::unique_ptr<LogManager> log_manager_;
// If set to true, the popup will stay open regardless of external changes on
// the test machine, that may normally cause the popup to be hidden
bool keep_popup_open_for_testing_ = false;
#if defined(OS_ANDROID)
CardExpirationDateFixFlowControllerImpl
card_expiration_date_fix_flow_controller_;
......
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