chromium/chrome/browser/ui/autofill/autofill_suggestion_controller_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "base/memory/weak_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/accessibility/accessibility_state_utils.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include "chrome/browser/ui/autofill/autofill_popup_view.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller_test_base.h"
#include "chrome/browser/ui/autofill/popup_controller_common.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/content/browser/content_autofill_driver_factory_test_api.h"
#include "components/autofill/content/browser/test_autofill_client_injector.h"
#include "components/autofill/content/browser/test_autofill_driver_injector.h"
#include "components/autofill/content/browser/test_autofill_manager_injector.h"
#include "components/autofill/content/browser/test_content_autofill_client.h"
#include "components/autofill/core/browser/autofill_driver_router.h"
#include "components/autofill/core/browser/autofill_external_delegate.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/browser_autofill_manager_test_api.h"
#include "components/autofill/core/browser/ui/autofill_suggestion_delegate.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_hiding_reason.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/unique_ids.h"
#include "components/input/native_web_keyboard_event.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/video_picture_in_picture_window_controller.h"
#include "content/public/browser/weak_document_ptr.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/text_utils.h"

#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/autofill/test_autofill_keyboard_accessory_controller_autofill_client.h"
#else
#include "chrome/browser/ui/autofill/test_autofill_popup_controller_autofill_client.h"
#endif

namespace autofill {
namespace {

ASCIIToUTF16;
WeakPtr;
_;
AtLeast;
Field;
Invoke;
Mock;
Optional;
Return;

TestAutofillSuggestionControllerAutofillClient;
#endif

content::RenderFrameHost* CreateAndNavigateChildFrame(
    content::RenderFrameHost* parent,
    const GURL& url,
    std::string_view name) {}

content::RenderFrameHost* NavigateAndCommitFrame(content::RenderFrameHost* rfh,
                                                 const GURL& url) {}

}  // namespace

AutofillSuggestionControllerTest;

// Regression test for (crbug.com/1513574): Showing an Autofill Compose
// suggestion twice does not crash.
TEST_F(AutofillSuggestionControllerTest, ShowTwice) {}

// Tests that the AED is informed when suggestions were shown.
TEST_F(AutofillSuggestionControllerTest, ShowInformsDelegate) {}

TEST_F(AutofillSuggestionControllerTest, UpdateDataListValues) {}

TEST_F(AutofillSuggestionControllerTest, PopupsWithOnlyDataLists) {}

TEST_F(AutofillSuggestionControllerTest, GetOrCreate) {}

TEST_F(AutofillSuggestionControllerTest, ProperlyResetController) {}

TEST_F(AutofillSuggestionControllerTest, HidingClearsPreview) {}

TEST_F(AutofillSuggestionControllerTest, DontHideWhenWaitingForData) {}

TEST_F(AutofillSuggestionControllerTest, ShouldReportHidingPopupReason) {}

// This is a regression test for crbug.com/521133 to ensure that we don't crash
// when suggestions updates race with user selections.
TEST_F(AutofillSuggestionControllerTest, SelectInvalidSuggestion) {}

// Tests that when a picture-in-picture window is initialized, there is a call
// to the popup view to check if the autofill popup bounds overlap with the
// picture-in-picture window.
// TODO(crbug.com/40280362): Implement PIP overlap checks on Android.
#if !BUILDFLAG(IS_ANDROID)
TEST_F(AutofillSuggestionControllerTest, CheckBoundsOverlapWithPictureInPicture) {}
#endif

// Tests that a change to a text field does not hide a popup with an
// Autocomplete suggestion.
TEST_F(AutofillSuggestionControllerTest,
       DoeNotHideOnFieldChangeForNonComposeEntries) {}

class AutofillSuggestionControllerTestHidingLogic
    : public AutofillSuggestionControllerTest {};

// Tests that if the popup is shown in the *main frame*, destruction of the
// *sub frame* does not hide the popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic,
       KeepOpenInMainFrameOnSubFrameDestruction) {}

// Tests that if the popup is shown in the *main frame*, a navigation in the
// *sub frame* does not hide the popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic,
       KeepOpenInMainFrameOnSubFrameNavigation) {}

// Tests that if the popup is shown, destruction of the WebContents hides the
// popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic, HideOnWebContentsDestroyed) {}

// Tests that if the popup is shown in the *main frame*, destruction of the
// *main frame* hides the popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic, HideInMainFrameOnDestruction) {}

// Tests that if the popup is shown in the *sub frame*, destruction of the
// *sub frame* hides the popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic, HideInSubFrameOnDestruction) {}

// Tests that if the popup is shown in the *main frame*, a navigation in the
// *main frame* hides the popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic,
       HideInMainFrameOnMainFrameNavigation) {}

// Tests that if the popup is shown in the *sub frame*, a navigation in the
// *sub frame* hides the popup.
TEST_F(AutofillSuggestionControllerTestHidingLogic,
       HideInSubFrameOnSubFrameNavigation) {}

// Tests that if the popup is shown in the *sub frame*, a navigation in the
// *main frame* hides the popup.
//
// TODO(crbug.com/41492848): This test only makes little sense: with BFcache,
// the navigation doesn't destroy the `sub_frame()` and thus we wouldn't hide
// the popup. What hides the popup in reality is
// AutofillExternalDelegate::DidEndTextFieldEditing().
TEST_F(AutofillSuggestionControllerTestHidingLogic,
       HideInSubFrameOnMainFrameNavigation) {}

}  // namespace autofill