#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;
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) { … }
class TestLocationBar : public LocationBar { … };
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 { … };
TEST_F(OmniboxViewViewsTest, UpdatePopupCall) { … }
TEST_F(OmniboxViewViewsTest, EditTextfield) { … }
TEST_F(OmniboxViewViewsTest, ScheduledTextEditCommand) { … }
TEST_F(OmniboxViewViewsTest, SelectWithShift_863543) { … }
TEST_F(OmniboxViewViewsTest, AccessibleTextSelectBoundTest) { … }
TEST_F(OmniboxViewViewsTest, OnBlur) { … }
TEST_F(OmniboxViewViewsTest,
RendererInitiatedFocusSelectsAllWhenStartingBlurred) { … }
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) { … }
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);
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
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) { … }