chromium/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc

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

#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"

#include <stddef.h>

#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>

#include "base/containers/adapters.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/strcat.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/command_updater_impl.h"
#include "chrome/browser/search_engines/template_url_service_factory_test_util.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/chrome_signin_client_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "components/lookalikes/core/safety_tip_test_utils.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/test_location_bar_model.h"
#include "components/omnibox/common/omnibox_features.h"
#include "content/public/browser/focused_node_details.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_keyboard_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_edit_commands.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/gfx/animation/animation_container_element.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/render_text_test_api.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/textfield/textfield_test_api.h"

Range;
OmniboxEventProto;

class TestingOmniboxView;

// TestingOmniboxView ---------------------------------------------------------

class TestingOmniboxView : public OmniboxViewViews {};

TestingOmniboxView::TestingOmniboxView(std::unique_ptr<OmniboxClient> client,
                                       bool popup_window_mode)
    :{}

void TestingOmniboxView::ResetEmphasisTestState() {}

void TestingOmniboxView::CheckUpdatePopupCallInfo(
    size_t call_count,
    std::u16string_view text,
    const Range& selection_range) {}

void TestingOmniboxView::CheckUpdatePopupNotCalled() {}

std::optional<SkColor> TestingOmniboxView::GetLatestColorForRange(
    const gfx::Range& range) {}

std::optional<std::pair<gfx::TextStyle, bool>>
TestingOmniboxView::GetLatestStyleForRange(const gfx::Range& range) const {}

void TestingOmniboxView::ResetStyles() {}

void TestingOmniboxView::OnThemeChanged() {}

void TestingOmniboxView::UpdateSchemeStyle(const Range& range) {}

void TestingOmniboxView::UpdatePopup() {}

void TestingOmniboxView::SetEmphasis(bool emphasize, const Range& range) {}

void TestingOmniboxView::ApplyColor(SkColor color, const gfx::Range& range) {}

void TestingOmniboxView::ApplyStyle(gfx::TextStyle style,
                                    bool value,
                                    const gfx::Range& range) {}

// TestLocationBar -------------------------------------------------------------

class TestLocationBar : public LocationBar {};

// OmniboxViewViewsTest -------------------------------------------------------

// Base class that ensures ScopedFeatureList is initialized first.
class OmniboxViewViewsTestBase : public ChromeViewsTestBase {};

class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {};

OmniboxViewViewsTest::OmniboxViewViewsTest(
    const std::vector<base::test::FeatureRefAndParams>& enabled_features,
    const std::vector<base::test::FeatureRef>& disabled_features,
    bool is_rtl_ui_test,
    bool is_popup_window_mode)
    :{}

void OmniboxViewViewsTest::SetAndEmphasizeText(const std::string& new_text,
                                               bool accept_input) {}

void OmniboxViewViewsTest::SetUp() {}

void OmniboxViewViewsTest::TearDown() {}

class OmniboxViewViewsTestIsPopupWindowMode : public OmniboxViewViewsTest {};

// Actual tests ---------------------------------------------------------------

// Checks that a single change of the text in the omnibox invokes
// only one call to OmniboxViewViews::UpdatePopup().
TEST_F(OmniboxViewViewsTest, UpdatePopupCall) {}

// Test that text cursor is shown in the omnibox after entering any single
// character in NTP 'Search box'. Test for crbug.com/698172.
TEST_F(OmniboxViewViewsTest, EditTextfield) {}

// Test that the scheduled text edit command is cleared when Textfield receives
// a key press event. This ensures that the scheduled text edit command property
// is always in the correct state. Test for http://crbug.com/613948.
TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) {}

// Test that Shift+Up and Shift+Down are not captured and let selection mode
// take over. Test for crbug.com/863543 and crbug.com/892216.
TEST_F(OmniboxViewViewsTest, SelectWithShift_863543) {}

TEST_F(OmniboxViewViewsTest, AccessibleTextSelectBoundTest) {}

TEST_F(OmniboxViewViewsTest, OnBlur) {}

// Verifies that https://crbug.com/45260 doesn't regress.
TEST_F(OmniboxViewViewsTest,
       RendererInitiatedFocusSelectsAllWhenStartingBlurred) {}

// Verifies that https://crbug.com/924935 doesn't regress.
TEST_F(OmniboxViewViewsTest,
       RendererInitiatedFocusPreservesCursorWhenStartingFocused) {}

TEST_F(OmniboxViewViewsTest, Emphasis) {}

TEST_F(OmniboxViewViewsTest, RevertOnBlur) {}

TEST_F(OmniboxViewViewsTest, RevertOnEscape) {}

TEST_F(OmniboxViewViewsTest, ShiftEscapeDoesNotSkipDefaultProcessing) {}

TEST_F(OmniboxViewViewsTest, EscapeSkipsDefaultProcessing) {}

TEST_F(OmniboxViewViewsTest, BackspaceExitsKeywordMode) {}

TEST_F(OmniboxViewViewsTest, BlurNeverExitsKeywordMode) {}

TEST_F(OmniboxViewViewsTest, PasteAndGoToUrlOrSearchCommand) {}

TEST_F(OmniboxViewViewsTest, SelectAllCommand) {}

// Verifies |OmniboxEditModel::State::needs_revert_and_select_all|, and verifies
// a recent regression in this logic (see https://crbug.com/923290).
TEST_F(OmniboxViewViewsTest, SelectAllOnReactivateTabAfterDeleteAll) {}

TEST_F(OmniboxViewViewsTest, SelectAllDuringMouseDown) {}

TEST_F(OmniboxViewViewsTest, SetWindowTextAndCaretPos) {}

TEST_F(OmniboxViewViewsTest, OnInlineAutocompleteTextMaybeChanged) {}

TEST_F(OmniboxViewViewsTest, OverflowingAutocompleteText) {}

TEST_F(OmniboxViewViewsTest, SchemeStrikethrough) {}

#if BUILDFLAG(SUPPORTS_AX_TEXT_OFFSETS)
TEST_F(OmniboxViewViewsTest,
       AccessibleTextOffsetsUpdatesAfterElideBehaviorChange) {
  base::test::ScopedFeatureList scoped_feature_list;
  scoped_feature_list.InitAndEnableFeature(::features::kUiaProvider);

  // Make the Omnibox very narrow (so it couldn't fit the whole string).
  int kOmniboxWidth = 60;
  gfx::RenderText* render_text = omnibox_view()->GetRenderText();
  render_text->SetDisplayRect(gfx::Rect(0, 0, kOmniboxWidth, 10));
  render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);

  const std::u16string text = u"http://www.example.com/?query=1";
  omnibox_view()->SetWindowTextAndCaretPos(text, 23U, false, false);

  EXPECT_EQ(gfx::ELIDE_TAIL, render_text->elide_behavior());
  ui::AXNodeData node_data;
  omnibox_view()->GetViewAccessibility().GetAccessibleNodeData(&node_data);
  std::vector<int32_t> expected_offsets = {
      0,  6,  10, 14, 21, 24, 29, 33, 42, 52, 52, 52, 52, 52, 52, 52,
      52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52};
  EXPECT_EQ(node_data.GetIntListAttribute(
                ax::mojom::IntListAttribute::kCharacterOffsets),
            expected_offsets);

  omnibox_textfield()->OnFocus();

  EXPECT_EQ(gfx::NO_ELIDE, render_text->elide_behavior());
  ui::AXNodeData node_data_2;
  omnibox_view()->GetViewAccessibility().GetAccessibleNodeData(&node_data_2);
  std::vector<int32_t> expected_offsets_2 = {
      0,   6,   10,  14,  21,  24,  29,  33,  42,  51,  59,
      62,  68,  74,  80,  90,  97,  100, 107, 109, 115, 122,
      132, 137, 142, 149, 156, 162, 166, 172, 180, 188};
  EXPECT_EQ(node_data_2.GetIntListAttribute(
                ax::mojom::IntListAttribute::kCharacterOffsets),
            expected_offsets_2);
}
#endif  // BUILDFLAG(SUPPORTS_AX_TEXT_OFFSETS)

TEST_F(OmniboxViewViewsTest, InitialAccessibilityProperties) {}

TEST_F(OmniboxViewViewsTestIsPopupWindowMode, InitialAccessibilityProperties) {}

TEST_F(OmniboxViewViewsTest, AccessibleValue) {}

class OmniboxViewViewsClipboardTest
    : public OmniboxViewViewsTest,
      public ::testing::WithParamInterface<ui::TextEditCommand> {};

TEST_P(OmniboxViewViewsClipboardTest, ClipboardCopyOrCutURL) {}

TEST_P(OmniboxViewViewsClipboardTest, ClipboardCopyOrCutUserText) {}

INSTANTIATE_TEST_SUITE_P();

class OmniboxViewViewsSteadyStateElisionsTest : public OmniboxViewViewsTest {};

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UrlStartsInElidedState) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideOnArrowKey) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideOnHomeKey) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest,
       UnelideViaEndKeyWorksWithIntranetUrls) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, GestureTaps) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, FirstMouseClickFocusesOnly) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, NegligibleDragKeepsElisions) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, CaretPlacementByMouse) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseDoubleClick) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseSingleThenDoubleClick) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseSingleThenRightClick) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseTripleClick) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseClickDrag) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest,
       MouseClickDragToBeginningSelectingText) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest,
       MouseClickDragToBeginningSelectingURL) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseDoubleClickDrag) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, ReelideOnBlur) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, DontReelideOnBlurIfEdited) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest,
       DontReelideOnBlurIfWidgetDeactivated) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, SaveSelectAllOnBlurAndRefocus) {}

TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideFromModel) {}