Delete simplified domain experiment
This experiment didn't move relevant security metrics, so we're not
going to launch it. :(
Bug: 1090393
Change-Id: I1a747165f42739be4cbb1508a3516b5f207d9a15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2922873
Reviewed-by: Justin Donnelly <jdonnelly@chromium.org>
Reviewed-by: Ali Juma <ajuma@chromium.org>
Reviewed-by: Daniel Rubery <drubery@chromium.org>
Commit-Queue: Emily Stark <estark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#889841}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 3b831c777..519eba1 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -1457,8 +1457,6 @@
"reputation/safety_tip_ui.h",
"reputation/safety_tip_ui_helper.cc",
"reputation/safety_tip_ui_helper.h",
- "reputation/url_elision_policy.cc",
- "reputation/url_elision_policy.h",
"resource_coordinator/resource_coordinator_parts.cc",
"resource_coordinator/resource_coordinator_parts.h",
"resource_coordinator/session_restore_policy.cc",
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 20d44cf..460b876 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -4402,28 +4402,6 @@
kOmniboxDefaultTypedNavigationsToHttpsVariations,
"OmniboxDefaultTypedNavigationsToHttps")},
- {"omnibox-ui-sometimes-elide-to-registrable-domain",
- flag_descriptions::kOmniboxUIMaybeElideToRegistrableDomainName,
- flag_descriptions::kOmniboxUIMaybeElideToRegistrableDomainDescription,
- kOsDesktop, FEATURE_VALUE_TYPE(omnibox::kMaybeElideToRegistrableDomain)},
-
- {"omnibox-ui-reveal-steady-state-url-path-query-and-ref-on-hover",
- flag_descriptions::
- kOmniboxUIRevealSteadyStateUrlPathQueryAndRefOnHoverName,
- flag_descriptions::
- kOmniboxUIRevealSteadyStateUrlPathQueryAndRefOnHoverDescription,
- kOsDesktop,
- FEATURE_VALUE_TYPE(omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover)},
-
- {"omnibox-ui-hide-steady-state-url-path-query-and-ref-on-interaction",
- flag_descriptions::
- kOmniboxUIHideSteadyStateUrlPathQueryAndRefOnInteractionName,
- flag_descriptions::
- kOmniboxUIHideSteadyStateUrlPathQueryAndRefOnInteractionDescription,
- kOsDesktop,
- FEATURE_VALUE_TYPE(
- omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction)},
-
{"omnibox-max-zero-suggest-matches",
flag_descriptions::kOmniboxMaxZeroSuggestMatchesName,
flag_descriptions::kOmniboxMaxZeroSuggestMatchesDescription,
diff --git a/chrome/browser/reputation/url_elision_policy.cc b/chrome/browser/reputation/url_elision_policy.cc
deleted file mode 100644
index e3497fdf..0000000
--- a/chrome/browser/reputation/url_elision_policy.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/reputation/url_elision_policy.h"
-
-#include "base/feature_list.h"
-#include "base/metrics/field_trial_params.h"
-#include "chrome/browser/reputation/local_heuristics.h"
-#include "components/lookalikes/core/lookalike_url_util.h"
-#include "components/omnibox/common/omnibox_features.h"
-#include "components/reputation/core/safety_tips_config.h"
-#include "components/url_formatter/spoof_checks/top_domains/top500_domains.h"
-
-#include "url/gurl.h"
-
-namespace {
-
-const base::FeatureParam<int> kMaximumUnelidedHostnameLength{
- &omnibox::kMaybeElideToRegistrableDomain, "max_unelided_host_length", 25};
-const base::FeatureParam<bool> kEnableKeywordBasedElision{
- &omnibox::kMaybeElideToRegistrableDomain, "enable_keyword_elision", true};
-const base::FeatureParam<bool> kSearchE2LDForKeywords{
- &omnibox::kMaybeElideToRegistrableDomain, "search_e2ld_for_keywords", true};
-
-} // namespace
-
-bool ShouldElideToRegistrableDomain(const GURL& url) {
- DCHECK(base::FeatureList::IsEnabled(omnibox::kMaybeElideToRegistrableDomain));
- if (url.HostIsIPAddress()) {
- return false;
- }
-
- auto* proto = reputation::GetSafetyTipsRemoteConfigProto();
- if (!proto || reputation::IsUrlAllowlistedBySafetyTipsComponent(proto, url)) {
- // Not having a proto happens when the component hasn't downloaded yet. This
- // should only happen for a short window following initial Chrome install.
- return false;
- }
-
- auto host = url.host();
- if (static_cast<int>(host.length()) > kMaximumUnelidedHostnameLength.Get()) {
- return true;
- }
-
- // Hostnames using sensitive keywords (typically, brandnames) are often social
- // engineering, and thus should only show the registrable domain.
- auto eTLD_plus_one = GetETLDPlusOne(host);
- if (kEnableKeywordBasedElision.Get() &&
- HostnameContainsKeyword(url, eTLD_plus_one, top500_domains::kTopKeywords,
- top500_domains::kNumTopKeywords,
- kSearchE2LDForKeywords.Get())) {
- return true;
- }
-
- return false;
-}
diff --git a/chrome/browser/reputation/url_elision_policy.h b/chrome/browser/reputation/url_elision_policy.h
deleted file mode 100644
index c2746b6..0000000
--- a/chrome/browser/reputation/url_elision_policy.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_REPUTATION_URL_ELISION_POLICY_H_
-#define CHROME_BROWSER_REPUTATION_URL_ELISION_POLICY_H_
-
-class GURL;
-
-// Called by omnibox code (when enabled) to check whether |url| should be elided
-// to show just the eTLD+1 due to failing any number of heuristics.
-bool ShouldElideToRegistrableDomain(const GURL& url);
-
-#endif // CHROME_BROWSER_REPUTATION_URL_ELISION_POLICY_H_
diff --git a/chrome/browser/reputation/url_elision_policy_unittest.cc b/chrome/browser/reputation/url_elision_policy_unittest.cc
deleted file mode 100644
index e130de59..0000000
--- a/chrome/browser/reputation/url_elision_policy_unittest.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/reputation/url_elision_policy.h"
-
-#include "base/test/scoped_feature_list.h"
-#include "components/omnibox/common/omnibox_features.h"
-#include "components/reputation/core/safety_tip_test_utils.h"
-#include "components/url_formatter/spoof_checks/common_words/common_words_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-namespace test {
-#include "components/url_formatter/spoof_checks/common_words/common_words_test-inc.cc"
-}
-
-namespace {
-
-// Note: This number is arbitrary; we just need to be able to build
-// hostnames that are reliably shorter/longer than the limit.
-const char* kMaxUnelidedHostLengthParam = "20";
-
-enum class KeywordSearchConfig {
- kDisabled,
- kEnabledWithE2LD,
- kEnabledWithoutE2LD
-};
-
-} // namespace
-
-class UrlElisionPolicyTest : public testing::Test {
- public:
- UrlElisionPolicyTest() {
- scoped_feature_list_.InitWithFeaturesAndParameters(
- {{omnibox::kMaybeElideToRegistrableDomain,
- {{"max_unelided_host_length", kMaxUnelidedHostLengthParam}}}},
- {});
- url_formatter::common_words::SetCommonWordDAFSAForTesting(
- test::kDafsa, sizeof(test::kDafsa));
-
- // Ensure that the allowlist exists (as otherwise we'll never elide).
- reputation::InitializeBlankLookalikeAllowlistForTesting();
- }
-
- ~UrlElisionPolicyTest() override = default;
-
- void TearDown() override {
- url_formatter::common_words::ResetCommonWordDAFSAForTesting();
- }
-
- private:
- base::test::ScopedFeatureList scoped_feature_list_;
-
- DISALLOW_COPY_AND_ASSIGN(UrlElisionPolicyTest);
-};
-
-// Ensure that long domains are elided.
-TEST_F(UrlElisionPolicyTest, ElidesLongDomains) {
- GURL kUrl = GURL("http://abcdefghijklmnopqrs.tu/xyz");
- EXPECT_TRUE(ShouldElideToRegistrableDomain(kUrl));
-}
-
-// Ensure that short domains are not elided.
-TEST_F(UrlElisionPolicyTest, DoesntElideShortDomains) {
- GURL kUrl = GURL("http://abc.d/xyz");
- EXPECT_FALSE(ShouldElideToRegistrableDomain(kUrl));
-}
-
-// Ensure that domains are allowlisted are not elided.
-TEST_F(UrlElisionPolicyTest, DoesntElideAllowlistedDomains) {
- GURL kUrl = GURL("http://alongbutstillallowlisteddomain.com/xyz");
-
- // This domain should be elided normally...
- EXPECT_TRUE(ShouldElideToRegistrableDomain(kUrl));
-
- // ...but not when allowlisted.
- reputation::SetSafetyTipAllowlistPatterns(
- {"alongbutstillallowlisteddomain.com/"}, {}, {});
- EXPECT_FALSE(ShouldElideToRegistrableDomain(kUrl));
-}
-
-// Ensure that sensitive keywords cause elision when expected and not otherwise.
-// Note further tests in SafetyTipHeuristicsTest.SensitiveKeywordsTest.
-TEST_F(UrlElisionPolicyTest, ElidesKeywordedDomainsAppropriately) {
- // Note: "google" is a sensitive keyword, taken from top500-domains-inc.cc.
- EXPECT_TRUE(
- ShouldElideToRegistrableDomain(GURL("http://google-evil.com/xyz")));
- EXPECT_TRUE(
- ShouldElideToRegistrableDomain(GURL("http://google.evil.com/xyz")));
-
- // Elision shouldn't happen when the keyword is the e2LD.
- EXPECT_FALSE(
- ShouldElideToRegistrableDomain(GURL("http://www.google.com/xyz")));
- EXPECT_FALSE(ShouldElideToRegistrableDomain(GURL("http://google.com/xyz")));
- // But those domains aren't exempt in other parts of the domain.
- EXPECT_TRUE(
- ShouldElideToRegistrableDomain(GURL("http://google.google.com/xyz")));
-
- // If there are no keywords, there should be no elision.
- EXPECT_FALSE(
- ShouldElideToRegistrableDomain(GURL("http://cupcake-login.com/xyz")));
- EXPECT_FALSE(
- ShouldElideToRegistrableDomain(GURL("http://cupcake.login.com/xyz")));
-
- // We don't elide on invalid/missing TLDs.
- EXPECT_FALSE(ShouldElideToRegistrableDomain(GURL("http://google/xyz")));
- EXPECT_FALSE(
- ShouldElideToRegistrableDomain(GURL("http://google.notreal/xyz")));
- // Nor on non-HTTP(s)
- EXPECT_FALSE(
- ShouldElideToRegistrableDomain(GURL("ftp://google.login.com/xyz")));
-}
-
-class UrlElisionKeywordPolicyTest
- : public UrlElisionPolicyTest,
- public testing::WithParamInterface<KeywordSearchConfig> {
- public:
- UrlElisionKeywordPolicyTest() {
- switch (GetParam()) {
- case KeywordSearchConfig::kDisabled:
- scoped_feature_list_.InitWithFeaturesAndParameters(
- {{omnibox::kMaybeElideToRegistrableDomain,
- {{"max_unelided_host_length", kMaxUnelidedHostLengthParam},
- {"enable_keyword_elision", "false"}}}},
- {});
- break;
- case KeywordSearchConfig::kEnabledWithE2LD:
- scoped_feature_list_.InitWithFeaturesAndParameters(
- {{omnibox::kMaybeElideToRegistrableDomain,
- {{"max_unelided_host_length", kMaxUnelidedHostLengthParam},
- {"enable_keyword_elision", "true"},
- {"search_e2ld_for_keywords", "true"}}}},
- {});
- break;
- case KeywordSearchConfig::kEnabledWithoutE2LD:
- scoped_feature_list_.InitWithFeaturesAndParameters(
- {{omnibox::kMaybeElideToRegistrableDomain,
- {{"max_unelided_host_length", kMaxUnelidedHostLengthParam},
- {"enable_keyword_elision", "true"},
- {"search_e2ld_for_keywords", "false"}}}},
- {});
- break;
- }
- }
-
- ~UrlElisionKeywordPolicyTest() override = default;
-
- bool IsKeywordElisionEnabled() {
- return GetParam() != KeywordSearchConfig::kDisabled;
- }
-
- private:
- base::test::ScopedFeatureList scoped_feature_list_;
-
- DISALLOW_COPY_AND_ASSIGN(UrlElisionKeywordPolicyTest);
-};
-
-INSTANTIATE_TEST_SUITE_P(
- All,
- UrlElisionKeywordPolicyTest,
- ::testing::Values(KeywordSearchConfig::kDisabled,
- KeywordSearchConfig::kEnabledWithE2LD,
- KeywordSearchConfig::kEnabledWithoutE2LD));
-
-// Verify that keyword elision follows the feature parameter.
-TEST_P(UrlElisionKeywordPolicyTest, ElidesOnKeywords) {
- EXPECT_EQ(IsKeywordElisionEnabled(),
- ShouldElideToRegistrableDomain(GURL("http://google.evil.com/xyz")));
-}
-
-// Verify that keyword elision respects the e2LD inclusion parameter.
-TEST_P(UrlElisionKeywordPolicyTest, RespectsE2LDParam) {
- EXPECT_EQ(GetParam() == KeywordSearchConfig::kEnabledWithE2LD,
- ShouldElideToRegistrableDomain(GURL("http://google-evil.com/xyz")));
-}
diff --git a/chrome/browser/safe_browsing/chrome_password_protection_service.cc b/chrome/browser/safe_browsing/chrome_password_protection_service.cc
index 90d14e3..ee0a315f 100644
--- a/chrome/browser/safe_browsing/chrome_password_protection_service.cc
+++ b/chrome/browser/safe_browsing/chrome_password_protection_service.cc
@@ -377,13 +377,6 @@
base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings));
experiment.set_delayed_warnings_mouse_clicks_enabled(
safe_browsing::kDelayedWarningsEnableMouseClicks.Get());
- // Actual URL display experiments:
- experiment.set_reveal_on_hover(base::FeatureList::IsEnabled(
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover));
- experiment.set_hide_on_interaction(base::FeatureList::IsEnabled(
- omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction));
- experiment.set_elide_to_registrable_domain(
- base::FeatureList::IsEnabled(omnibox::kMaybeElideToRegistrableDomain));
return experiment;
}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 1f127e1..5ec77a84 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -27,7 +27,6 @@
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/history_clusters/history_clusters_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/reputation/url_elision_policy.h"
#include "chrome/browser/send_tab_to_self/send_tab_to_self_desktop_util.h"
#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/themes/theme_service.h"
@@ -155,220 +154,8 @@
->IsMarkedByOriginatorAsConfidential();
}
-// Draws a rectangle of dimensions and position |rect| in |canvas|, colored
-// with a gradient from |start_color| to |end_color|.
-void DrawGradientRect(const gfx::Rect& rect,
- SkColor start_color,
- SkColor end_color,
- gfx::Canvas* canvas) {
- SkColor colors[2] = {start_color, end_color};
- SkPoint points[2];
- points[0].iset(rect.origin().x(), rect.origin().y());
- points[1].iset(rect.right(), rect.y());
- cc::PaintFlags flags;
- flags.setShader(cc::PaintShader::MakeLinearGradient(points, colors, nullptr,
- 2, SkTileMode::kClamp));
- canvas->DrawRect(rect, flags);
-}
-
-// Returns true if the substring indicated by |range| overflows
-// |omnibox_view|'s current local bounds.
-bool TextRangeOverflowsView(OmniboxViewViews* omnibox_view,
- gfx::RenderText* render_text,
- const gfx::Range& range) {
- // The RenderText must be in NO_ELIDE mode to attempt to retrieve the bounds
- // of |range| (which could be outside its display area).
- DCHECK_EQ(gfx::NO_ELIDE, render_text->elide_behavior());
-
- gfx::Rect range_rect;
- for (const auto& rect : render_text->GetSubstringBounds(range))
- range_rect.Union(rect);
- return omnibox_view->GetLocalBounds().width() < range_rect.width();
-}
-
} // namespace
-OmniboxViewViews::ElideAnimation::ElideAnimation(OmniboxViewViews* view,
- gfx::RenderText* render_text)
- : AnimationDelegateViews(view), view_(view), render_text_(render_text) {
- DCHECK(view_);
- DCHECK(render_text_);
-}
-
-OmniboxViewViews::ElideAnimation::~ElideAnimation() = default;
-
-// TODO(estark): this code doesn't work for URLs with RTL components. Will need
-// to figure out another animation or just skip the animation entirely on URLs
-// with RTL components.
-void OmniboxViewViews::ElideAnimation::Start(
- const gfx::Range& elide_to_bounds,
- uint32_t delay_ms,
- const std::vector<gfx::Range>& ranges_surrounding_simplified_domain,
- SkColor starting_color,
- SkColor ending_color) {
- DCHECK(ranges_surrounding_simplified_domain.size() == 1 ||
- ranges_surrounding_simplified_domain.size() == 2);
- ranges_surrounding_simplified_domain_ = ranges_surrounding_simplified_domain;
- starting_color_ = starting_color;
- ending_color_ = ending_color;
-
- // simplified_domain_bounds_ will be set to a rectangle surrounding the part
- // of the URL that is never elided, on its original position before any
- // animation runs. If ranges_surrounding_simplified_domain_ only contains one
- // range it means we are not eliding on the right side, so we use the right
- // side of elide_to_bounds as the range as it will always be the right limit
- // of the simplified section.
- gfx::Range simplified_domain_range(
- ranges_surrounding_simplified_domain_[0].end(),
- ranges_surrounding_simplified_domain_.size() == 2
- ? ranges_surrounding_simplified_domain_[1].start()
- : elide_to_bounds.end());
- for (auto rect : render_text_->GetSubstringBounds(simplified_domain_range)) {
- simplified_domain_bounds_.Union(rect - render_text_->GetLineOffset(0));
- }
-
- // After computing |elide_to_rect_| below, |elide_to_bounds| aren't actually
- // need anymore for the animation. However, the bounds provide a convenient
- // way for the animation consumer to check if an animation is currently in
- // progress to a specific range, so that the consumer can avoid starting a
- // duplicate animation (to avoid flicker). So we save the bounds so that
- // consumers can query them.
- elide_to_bounds_ = elide_to_bounds;
-
- animation_ =
- std::make_unique<gfx::MultiAnimation>(gfx::MultiAnimation::Parts({
- gfx::MultiAnimation::Part(base::TimeDelta::FromMilliseconds(delay_ms),
- gfx::Tween::ZERO),
- gfx::MultiAnimation::Part(base::TimeDelta::FromMilliseconds(300),
- gfx::Tween::FAST_OUT_SLOW_IN),
- }));
- animation_->set_delegate(this);
- animation_->set_continuous(false);
-
- elide_from_rect_ = render_text_->display_rect();
- elide_to_rect_ = gfx::Rect();
- for (const auto& rect : render_text_->GetSubstringBounds(elide_to_bounds))
- elide_to_rect_.Union(rect);
- // The URL should never shift vertically while eliding to/from simplified
- // domain.
- elide_to_rect_.set_y(elide_from_rect_.y());
- elide_to_rect_.set_height(elide_from_rect_.height());
-
- // There is nothing to animate in this case, so return without starting.
- if (elide_from_rect_ == elide_to_rect_ && starting_color_ == ending_color_)
- return;
-
- starting_display_offset_ = render_text_->GetUpdatedDisplayOffset().x();
- // Shift the text to where |elide_to_bounds| starts, relative to the current
- // display rect.
- if (base::i18n::IsRTL()) {
- ending_display_offset_ = starting_display_offset_ +
- elide_from_rect_.right() - elide_to_rect_.right();
- } else {
- ending_display_offset_ =
- starting_display_offset_ - (elide_to_rect_.x() - elide_from_rect_.x());
- }
-
- animation_->Start();
-}
-
-void OmniboxViewViews::ElideAnimation::Stop() {
- // Reset the smoothing rectangles whenever the animation stops to prevent
- // stale rectangles from showing at the start of the next animation.
- view_->elide_animation_smoothing_rect_left_ = gfx::Rect();
- view_->elide_animation_smoothing_rect_right_ = gfx::Rect();
- if (animation_)
- animation_->Stop();
-}
-
-bool OmniboxViewViews::ElideAnimation::IsAnimating() {
- return animation_ && animation_->is_animating();
-}
-
-const gfx::Range& OmniboxViewViews::ElideAnimation::GetElideToBounds() const {
- return elide_to_bounds_;
-}
-
-SkColor OmniboxViewViews::ElideAnimation::GetCurrentColor() const {
- return animation_
- ? gfx::Tween::ColorValueBetween(animation_->GetCurrentValue(),
- starting_color_, ending_color_)
- : gfx::kPlaceholderColor;
-}
-
-gfx::MultiAnimation*
-OmniboxViewViews::ElideAnimation::GetAnimationForTesting() {
- return animation_.get();
-}
-
-void OmniboxViewViews::ElideAnimation::AnimationProgressed(
- const gfx::Animation* animation) {
- DCHECK(!view_->model()->user_input_in_progress());
- DCHECK_EQ(animation, animation_.get());
-
- if (animation->GetCurrentValue() == 0)
- return;
-
- // |bounds| contains the interpolated substring to show for this frame. Shift
- // it to line up with the x position of the previous frame (|old_bounds|),
- // because the animation should gradually bring the desired string into view
- // at the leading edge. The y/height values shouldn't change because
- // |elide_to_rect_| is set to have the same y and height values as
- // |elide_to_rect_|.
- gfx::Rect old_bounds = render_text_->display_rect();
- gfx::Rect bounds = gfx::Tween::RectValueBetween(
- animation->GetCurrentValue(), elide_from_rect_, elide_to_rect_);
- DCHECK_EQ(bounds.y(), old_bounds.y());
- DCHECK_EQ(bounds.height(), old_bounds.height());
- gfx::Rect shifted_bounds(base::i18n::IsRTL()
- ? old_bounds.right() - bounds.width()
- : old_bounds.x(),
- old_bounds.y(), bounds.width(), old_bounds.height());
- render_text_->SetDisplayRect(shifted_bounds);
- current_offset_ = gfx::Tween::IntValueBetween(animation->GetCurrentValue(),
- starting_display_offset_,
- ending_display_offset_);
- render_text_->SetDisplayOffset(current_offset_);
-
- for (const auto& range : ranges_surrounding_simplified_domain_) {
- view_->ApplyColor(GetCurrentColor(), range);
- }
-
- // TODO(crbug.com/1101472): The smoothing gradient mask is not yet implemented
- // correctly for RTL UI.
- if (base::i18n::IsRTL()) {
- view_->SchedulePaint();
- return;
- }
-
- // The gradient mask should be a fixed width, except if that width would
- // cause it to mask the unelided section. In that case we set it to the
- // maximum width possible that won't cover the unelided section.
- int unelided_left_bound = simplified_domain_bounds_.x() + current_offset_;
- int unelided_right_bound =
- unelided_left_bound + simplified_domain_bounds_.width();
- // GetSubstringBounds rounds up when calculating unelided_left_bound and
- // unelided_right_bound, we subtract 1 pixel from the gradient widths to make
- // sure they never overlap with the always visible part of the URL.
- // gfx::Rect() switches negative values to 0, so this doesn't affect
- // rectangles that were originally size 0.
- int left_gradient_width = kSmoothingGradientMaxWidth < unelided_left_bound
- ? kSmoothingGradientMaxWidth - 1
- : unelided_left_bound - 1;
- int right_gradient_width =
- shifted_bounds.right() - kSmoothingGradientMaxWidth > unelided_right_bound
- ? kSmoothingGradientMaxWidth - 1
- : shifted_bounds.right() - unelided_right_bound - 1;
-
- view_->elide_animation_smoothing_rect_left_ = gfx::Rect(
- old_bounds.x(), old_bounds.y(), left_gradient_width, old_bounds.height());
- view_->elide_animation_smoothing_rect_right_ =
- gfx::Rect(shifted_bounds.right() - right_gradient_width, old_bounds.y(),
- right_gradient_width, old_bounds.height());
-
- view_->SchedulePaint();
-}
-
// OmniboxViewViews -----------------------------------------------------------
OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller,
@@ -378,7 +165,6 @@
const gfx::FontList& font_list)
: OmniboxView(controller, std::move(client)),
popup_window_mode_(popup_window_mode),
- clock_(base::DefaultClock::GetInstance()),
location_bar_view_(location_bar),
latency_histogram_state_(NOT_ACTIVE),
friendly_suggestion_text_prefix_length_(0) {
@@ -393,8 +179,7 @@
location_bar_view_->browser()->profile()->GetPrefs());
pref_change_registrar_.Add(
omnibox::kPreventUrlElisionsInOmnibox,
- base::BindRepeating(&OmniboxViewViews::OnShouldPreventElisionChanged,
- base::Unretained(this)));
+ base::BindRepeating(&OmniboxViewViews::Update, base::Unretained(this)));
}
// Sometimes there are additional ignored views, such as a View representing
@@ -431,10 +216,6 @@
// Initialize the popup view using the same font.
popup_view_ = std::make_unique<OmniboxPopupContentsView>(
this, model(), location_bar_view_);
- if (OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() &&
- !model()->ShouldPreventElision()) {
- Observe(location_bar_view_->GetWebContents());
- }
// Set whether the text should be used to improve typing suggestions.
SetShouldDoLearning(!location_bar_view_->profile()->IsOffTheRecord());
@@ -496,15 +277,6 @@
// TODO(msw|oshima): Consider saving/restoring edit history.
ClearEditHistory();
-
- // When the tab is changed, unelide the URL in case it had previously been
- // elided to a simplified domain by a user interaction (when certain field
- // trials are enabled).
- ResetToHideOnInteraction();
- if (OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() &&
- !model()->ShouldPreventElision()) {
- Observe(web_contents);
- }
}
void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) {
@@ -528,12 +300,6 @@
}
void OmniboxViewViews::EmphasizeURLComponents() {
- // Cancel any existing simplified URL animations.
- if (hover_elide_or_unelide_animation_)
- hover_elide_or_unelide_animation_->Stop();
- if (elide_after_web_contents_interaction_animation_)
- elide_after_web_contents_interaction_animation_->Stop();
-
// If the current contents is a URL, turn on special URL rendering mode in
// RenderText.
bool text_is_url = model()->CurrentTextIsURL();
@@ -543,56 +309,6 @@
std::u16string text = GetText();
UpdateTextStyle(text, text_is_url, model()->client()->GetSchemeClassifier());
-
- if (model()->ShouldPreventElision())
- return;
-
- // If the text isn't eligible to be elided to a simplified domain, and
- // simplified domain field trials are enabled, then ensure that as much of the
- // text as will fit is visible.
- if (!GetURLEligibleForSimplifiedDomainEliding() &&
- (OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover())) {
- FitToLocalBounds();
- return;
- }
-
- // In the simplified domain field trials, elide or unelide according to the
- // current state and field trial configuration. These elisions are not
- // animated because we often don't want this to be a user-visible
- // transformation; for example, a navigation should just show the URL in the
- // desired state without drawing additional attention from the user.
- if (OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- // In the hide-on-interaction field trial, elide or unelide the URL to the
- // simplified domain depending on whether the user has already interacted
- // with the page or not. This is a best guess at the correct elision state,
- // which we don't really know for sure until a navigation has committed
- // (because the elision behavior depends on whether the navigation is
- // same-document and if it changes the path). We elide here based on the
- // current elision setting; we'll then update the elision state as we get
- // more information about the navigation in DidStartNavigation and
- // DidFinishNavigation.
- if (elide_after_web_contents_interaction_animation_) {
- // This can cause a slight quirk in browser-initiated navigations that
- // occur after the user interacts with the previous page. In this case,
- // the simplified domain will be shown briefly before we show the full URL
- // in DidStartNavigation().
- ElideURL();
- } else {
- // Note that here we are only adjusting the display of the URL, not
- // resetting any state associated with the animations (in particular, we
- // are not calling ResetToHideOnInteraction()). This is, as above, because
- // we don't know exactly how to set state until we know what kind of
- // navigation is happening. Thus here we are only adjusting the display so
- // things look right mid-navigation, and the final state will be set
- // appropriately in DidFinishNavigation().
- ShowFullURLWithoutSchemeAndTrivialSubdomain();
- }
- } else if (OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- // If reveal-on-hover is enabled and hide-on-interaction is disabled, elide
- // to the simplified domain now.
- ElideURL();
- }
}
void OmniboxViewViews::Update() {
@@ -770,22 +486,6 @@
SCOPED_UMA_HISTOGRAM_TIMER("Omnibox.PaintTime");
Textfield::OnPaint(canvas);
}
- if ((hover_elide_or_unelide_animation_ &&
- hover_elide_or_unelide_animation_->IsAnimating()) ||
- (elide_after_web_contents_interaction_animation_ &&
- elide_after_web_contents_interaction_animation_->IsAnimating())) {
- SkColor bg_color = GetBackgroundColor();
- // We can't use the SK_ColorTRANSPARENT constant here because for purposes
- // of the gradient the R,G,B values of the transparent color do matter, and
- // need to be identical to the background color (SK_ColorTRANSPARENT is a
- // transparent black, and results in the gradient looking gray).
- SkColor bg_transparent = SkColorSetARGB(
- 0, SkColorGetR(bg_color), SkColorGetG(bg_color), SkColorGetB(bg_color));
- DrawGradientRect(elide_animation_smoothing_rect_left_, bg_color,
- bg_transparent, canvas);
- DrawGradientRect(elide_animation_smoothing_rect_right_, bg_transparent,
- bg_color, canvas);
- }
}
void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
@@ -857,16 +557,6 @@
scoped_compositor_observation_.Reset();
}
-OmniboxViewViews::ElideAnimation*
-OmniboxViewViews::GetHoverElideOrUnelideAnimationForTesting() {
- return hover_elide_or_unelide_animation_.get();
-}
-
-OmniboxViewViews::ElideAnimation*
-OmniboxViewViews::GetElideAfterInteractionAnimationForTesting() {
- return elide_after_web_contents_interaction_animation_.get();
-}
-
void OmniboxViewViews::OnThemeChanged() {
views::Textfield::OnThemeChanged();
@@ -874,12 +564,6 @@
GetThemeProvider(), OmniboxPart::LOCATION_BAR_TEXT_DIMMED);
set_placeholder_text_color(dimmed_text_color);
- if (!model()->ShouldPreventElision() &&
- OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- hover_elide_or_unelide_animation_ =
- std::make_unique<ElideAnimation>(this, GetRenderText());
- }
-
EmphasizeURLComponents();
}
@@ -1306,161 +990,11 @@
void OmniboxViewViews::OnMouseMoved(const ui::MouseEvent& event) {
if (location_bar_view_)
location_bar_view_->OnOmniboxHovered(true);
-
- if (model()->ShouldPreventElision())
- return;
-
- if (!GetURLEligibleForSimplifiedDomainEliding())
- return;
-
- if (hover_start_time_ == base::Time() &&
- GetURLEligibleForSimplifiedDomainEliding()) {
- hover_start_time_ = clock_->Now();
- }
-
- if (!OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover())
- return;
-
- if (elide_after_web_contents_interaction_animation_)
- elide_after_web_contents_interaction_animation_->Stop();
-
- // When the reveal-on-hover field trial is enabled, we elide the path and
- // optionally subdomains of the URL. We bring back the URL when the user
- // hovers over the omnibox, as is happening now. This is done via an animation
- // that slides both ends of the URL into view while shifting the text so that
- // the visible text is aligned with the leading edge of the display area. The
- // reverse animation occurs when the mouse exits the omnibox area (in
- // OnMouseExited()).
- //
- // The animation shouldn't begin immediately on hover to avoid the URL
- // flickering in and out as the user passes over the omnibox on their way to
- // e.g. the tab strip. Thus we pass a delay threshold (configurable via field
- // trial) to ElideAnimation so that the unelision animation only begins after
- // this delay.
- if (hover_elide_or_unelide_animation_) {
- // There might already be an unelide in progress. If it's animating to the
- // same state as we're targeting, then we don't need to do anything.
- gfx::Range unelide_bounds = gfx::Range(0, GetText().size());
- if (hover_elide_or_unelide_animation_->IsAnimating() &&
- hover_elide_or_unelide_animation_->GetElideToBounds() ==
- unelide_bounds) {
- return;
- }
-
- SkColor starting_color =
- hover_elide_or_unelide_animation_->GetCurrentColor();
- if (starting_color == gfx::kPlaceholderColor)
- starting_color = SK_ColorTRANSPARENT;
- hover_elide_or_unelide_animation_->Stop();
-
- // Figure out where we are uneliding from so that the hover animation can
- // fade in the surrounding text (|ranges_to_fade_in|). If the user has
- // already interacted with the page, then we elided to the simplified domain
- // and that is what we are uneliding from now. Otherwise, only the scheme
- // and possibly a trivial subdomain have been elided and those components
- // now need to be faded in.
- std::vector<gfx::Range> ranges_to_fade_in;
- // |minimum_visible_range| will contain either the simplified domain or the
- // full hostname, depending on which is currently supposed to be showing. If
- // |minimum_visible_range| does not currently fit in the omnibox bounds,
- // then we don't do any hover animation. This is for simplicity, because
- // ElideAnimation doesn't know how to position the text so that the most
- // important part of the hostname is showing if it doesn't all fit.
- // Furthermore, it doesn't seem necessary to do hover animation when the
- // hostname doesn't fit because nothing is being elided beyond what has to
- // be to fit in the local bounds.
- gfx::Range minimum_visible_range;
- if (elide_after_web_contents_interaction_animation_ ||
- !OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- // The URL has been elided to the simplified domain. We want to fade in
- // everything surrounding the simplified domain.
- minimum_visible_range = GetSimplifiedDomainBounds(&ranges_to_fade_in);
- } else {
- // The full URL is showing, except for the scheme and trivial subdomain.
- // We want to fade in the scheme and trivial subdomain.
- url::Component host = GetHostComponentAfterTrivialSubdomain();
- ranges_to_fade_in.emplace_back(0, host.begin);
- minimum_visible_range = gfx::Range(host.begin, host.end());
- }
-
- if (TextRangeOverflowsView(this, GetRenderText(), minimum_visible_range))
- return;
-
- hover_elide_or_unelide_animation_->Start(
- unelide_bounds, OmniboxFieldTrial::UnelideURLOnHoverThresholdMs(),
- ranges_to_fade_in, starting_color,
- GetOmniboxColor(GetThemeProvider(),
- OmniboxPart::LOCATION_BAR_TEXT_DIMMED));
- }
}
void OmniboxViewViews::OnMouseExited(const ui::MouseEvent& event) {
if (location_bar_view_)
location_bar_view_->OnOmniboxHovered(false);
-
- // A histogram records the duration that the user has hovered continuously
- // over the omnibox without focusing it.
- if (hover_start_time_ != base::Time() && !recorded_hover_on_focus_) {
- UmaHistogramTimes("Omnibox.HoverTime", clock_->Now() - hover_start_time_);
- }
- hover_start_time_ = base::Time();
- recorded_hover_on_focus_ = false;
-
- if (!OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover() ||
- model()->ShouldPreventElision()) {
- return;
- }
- if (!GetURLEligibleForSimplifiedDomainEliding())
- return;
-
- // When the reveal-on-hover field trial is enabled, we bring the URL into view
- // when the user hovers over the omnibox and elide back to simplified domain
- // when their mouse exits the omnibox area. The elision animation is the
- // reverse of the unelision animation: we shrink the URL from both sides while
- // shifting the text to the leading edge.
- DCHECK(hover_elide_or_unelide_animation_);
- SkColor starting_color =
- hover_elide_or_unelide_animation_->IsAnimating()
- ? hover_elide_or_unelide_animation_->GetCurrentColor()
- : GetOmniboxColor(GetThemeProvider(),
- OmniboxPart::LOCATION_BAR_TEXT_DIMMED);
- hover_elide_or_unelide_animation_->Stop();
- // Elisions don't take display offset into account (see
- // https://crbug.com/1099078), so the RenderText must be in NO_ELIDE mode to
- // avoid over-eliding when some of the text is not visible due to display
- // offset.
- GetRenderText()->SetElideBehavior(gfx::NO_ELIDE);
-
- // Figure out where to elide to. If the user has already interacted with the
- // page or reveal-on-interaction is disabled, then elide to the simplified
- // domain; otherwise just hide the scheme and trivial subdomain (if any).
- if (elide_after_web_contents_interaction_animation_ ||
- !OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- std::vector<gfx::Range> ranges_surrounding_simplified_domain;
- gfx::Range simplified_domain =
- GetSimplifiedDomainBounds(&ranges_surrounding_simplified_domain);
- // If the simplified domain overflows the local bounds, then hover
- // animations are disabled for simplicity.
- if (TextRangeOverflowsView(this, GetRenderText(), simplified_domain))
- return;
- hover_elide_or_unelide_animation_->Start(
- simplified_domain, 0 /* delay_ms */,
- ranges_surrounding_simplified_domain, starting_color,
- SK_ColorTRANSPARENT);
- } else {
- std::u16string text = GetText();
- url::Component host = GetHostComponentAfterTrivialSubdomain();
- // If the hostname overflows the local bounds, then hover animations are
- // disabled for simplicity.
- if (TextRangeOverflowsView(this, GetRenderText(),
- gfx::Range(host.begin, host.end()))) {
- return;
- }
- hover_elide_or_unelide_animation_->Start(
- gfx::Range(host.begin, text.size()), 0 /* delay_ms */,
- std::vector<gfx::Range>{gfx::Range(0, host.begin)}, starting_color,
- SK_ColorTRANSPARENT);
- }
}
bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const {
@@ -1785,57 +1319,9 @@
return Textfield::HandleAccessibleAction(action_data);
}
-void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
- Textfield::OnBoundsChanged(previous_bounds);
-
- if (!OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover() &&
- !OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- return;
- }
-
- // When simplified domain display field trials are enabled,
- // Textfield::OnBoundsChanged() may have undone the effect of any previous URL
- // elisions, because it expands the Textfield's display rect to the local
- // bounds, which may bring more of the URL into view than intended. Re-apply
- // simplified domain elisions now.
-
- // Cancel any running animations. This could cause some abrupt transitions,
- // but we can't adapt running animations to new bounds.
- if (hover_elide_or_unelide_animation_)
- hover_elide_or_unelide_animation_->Stop();
- if (elide_after_web_contents_interaction_animation_)
- elide_after_web_contents_interaction_animation_->Stop();
-
- // |elide_after_web_contents_interaction_animation_| is created when the user
- // interacts with the page, if hide-on-interaction is enabled. If
- // hide-on-interaction is disabled or the user has already interacted with the
- // page, the simplified domain should have been showing before the bounds
- // changed (or we would have been in the process of animating to the
- // simplified domain).
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- elide_after_web_contents_interaction_animation_) {
- if (GetURLEligibleForSimplifiedDomainEliding() &&
- !model()->ShouldPreventElision()) {
- ElideURL();
- }
- } else {
- // The user hasn't interacted with the page yet. This resets animation state
- // and shows the partially elided URL with scheme and trivial subdomains
- // hidden.
- ResetToHideOnInteraction();
- }
-}
-
void OmniboxViewViews::OnFocus() {
views::Textfield::OnFocus();
- // A histogram records the duration that the user has hovered continuously
- // over the omnibox without focusing it.
- if (hover_start_time_ != base::Time() && !recorded_hover_on_focus_) {
- recorded_hover_on_focus_ = true;
- UmaHistogramTimes("Omnibox.HoverTime", clock_->Now() - hover_start_time_);
- }
-
// TODO(tommycli): This does not seem like it should be necessary.
// Investigate why it's needed and see if we can remove it.
model()->ResetDisplayTexts();
@@ -1850,7 +1336,6 @@
saved_selection_for_focus_change_.clear();
}
- ShowFullURL();
GetRenderText()->SetElideBehavior(gfx::NO_ELIDE);
// Focus changes can affect the visibility of any keyword hint.
@@ -1943,37 +1428,6 @@
}
ClearAccessibilityLabel();
-
- // When the relevant field trial is enabled, reset state so that the URL will
- // be elided/unelided on next user interaction or hover.
- if (!model()->ShouldPreventElision()) {
- if (OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover() &&
- !OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- // When reveal-on-hover is enabled but not hide-on-interaction, blur
- // should unfocus the omnibox and return to the same state as on page
- // load: the URL is elided to a simplified domain until the user hovers
- // over the omnibox. There's no need to animate in this case because the
- // omnibox's appearance already changes quite dramatically on blur
- // (selection clearer, other URL transformations, etc.), so there's no
- // need to make this change gradual.
- hover_elide_or_unelide_animation_ =
- std::make_unique<OmniboxViewViews::ElideAnimation>(this,
- GetRenderText());
- if (GetURLEligibleForSimplifiedDomainEliding()) {
- ElideURL();
- } else {
- // If the text isn't eligible to be elided to a simplified domain, then
- // ensure that as much of it is visible as will fit.
- FitToLocalBounds();
- }
- } else if (OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- // When hide-on-interaction is enabled, this method ensures that, once the
- // omnibox is blurred, the URL is visible and that the animation state is
- // set so that the URL will be animated to the simplified domain the
- // next time the user interacts with the page.
- ResetToHideOnInteraction();
- }
- }
}
bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
@@ -1994,96 +1448,6 @@
location_bar_view_->command_updater()->IsCommandEnabled(command_id);
}
-void OmniboxViewViews::DidStartNavigation(
- content::NavigationHandle* navigation) {
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- model()->ShouldPreventElision()) {
- return;
- }
-
- // If navigating to a different page in a browser-initiated navigation, the
- // new URL should be shown unelided while the navigation is in progress. For
- // renderer-initiated navigations, the URL isn't displayed until the
- // navigation commits, so there's no need to elide/unelide it now.
- if (navigation->IsInMainFrame() && !navigation->IsSameDocument() &&
- !navigation->IsRendererInitiated()) {
- ResetToHideOnInteraction();
- }
-}
-
-void OmniboxViewViews::DidFinishNavigation(
- content::NavigationHandle* navigation) {
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- model()->ShouldPreventElision()) {
- return;
- }
-
- // Non-main-frame navigations don't change the visible URL, so no action is
- // necessary for simplified domain elisions.
- if (!navigation->IsInMainFrame())
- return;
-
- // If the navigation didn't commit, and it was renderer-initiated, then no
- // action is needed, as the URL won't have been updated. But if it was
- // browser-initiated, then the URL would have been updated to show the URL of
- // the in-progress navigation; in this case, reset to show the full URL now
- // that the navigation has finished without committing.
- if (!navigation->HasCommitted()) {
- if (navigation->IsRendererInitiated()) {
- return;
- }
- ResetToHideOnInteraction();
- return;
- }
-
- // Once a navigation finishes that changes the visible URL (besides just the
- // ref), unelide and reset state so that we'll show the simplified domain on
- // interaction. Same-document navigations that only change the ref are treated
- // specially and don't cause the elision/unelision state to be altered. This
- // is to avoid frequent eliding/uneliding within single-page apps that do
- // frequent fragment navigations.
- if (navigation->IsErrorPage() || !navigation->IsSameDocument() ||
- !navigation->GetPreviousMainFrameURL().EqualsIgnoringRef(
- navigation->GetURL())) {
- ResetToHideOnInteraction();
- }
-}
-
-void OmniboxViewViews::DidGetUserInteraction(
- const blink::WebInputEvent& event) {
- // Exclude mouse clicks from triggering the simplified domain elision. Mouse
- // clicks can be done idly and aren't a good signal of real intent to interact
- // with the page. Plus, it can be jarring when the URL elides when the user
- // clicks on a link only to immediately come back as the navigation occurs.
- if (blink::WebInputEvent::IsMouseEventType(event.GetType()))
- return;
-
- // Exclude modifier keys to prevent keyboard shortcuts (such as switching
- // tabs) from eliding the URL. We don't want to count these shortcuts as
- // interactions with the page content.
- if (blink::WebInputEvent::IsKeyboardEventType(event.GetType()) &&
- event.GetModifiers() & blink::WebInputEvent::kKeyModifiers) {
- return;
- }
-
- MaybeElideURLWithAnimationFromInteraction();
-}
-
-void OmniboxViewViews::OnFocusChangedInPage(
- content::FocusedNodeDetails* details) {
- // Elide the URL to the simplified domain (the most security-critical
- // information) when the user focuses a form text field, which is a key moment
- // for making security decisions. Ignore the focus event if it didn't come
- // from a mouse click/tap. Focus via keyboard will trigger elision from
- // DidGetUserInteraction(), and we want to ignore focuses that aren't from an
- // explicit user action (e.g., input fields that are autofocused on page
- // load).
- if (details->is_editable_node &&
- details->focus_type == blink::mojom::FocusType::kMouse) {
- MaybeElideURLWithAnimationFromInteraction();
- }
-}
-
std::u16string OmniboxViewViews::GetSelectionClipboardText() const {
return SanitizeTextForPaste(Textfield::GetSelectionClipboardText());
}
@@ -2545,373 +1909,10 @@
ExternalProtocolHandler::PermitLaunchUrl();
}
-gfx::Range OmniboxViewViews::GetSimplifiedDomainBounds(
- std::vector<gfx::Range>* ranges_surrounding_simplified_domain) {
- DCHECK(ranges_surrounding_simplified_domain);
- DCHECK(ranges_surrounding_simplified_domain->empty());
-
- std::u16string text = GetText();
- url::Component host = GetHostComponentAfterTrivialSubdomain();
-
- GURL url = url_formatter::FixupURL(base::UTF16ToUTF8(text), std::string());
- if (!OmniboxFieldTrial::ShouldMaybeElideToRegistrableDomain() ||
- !ShouldElideToRegistrableDomain(url)) {
- ranges_surrounding_simplified_domain->emplace_back(0, host.begin);
- ranges_surrounding_simplified_domain->emplace_back(host.end(), text.size());
- return gfx::Range(host.begin, host.end());
- }
-
- // TODO(estark): push this inside ParseForEmphasizeComponents()?
- std::u16string simplified_domain = url_formatter::IDNToUnicode(
- net::registry_controlled_domains::GetDomainAndRegistry(
- url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES));
-
- if (simplified_domain.empty()) {
- ranges_surrounding_simplified_domain->emplace_back(0, host.begin);
- ranges_surrounding_simplified_domain->emplace_back(host.end(), text.size());
- return gfx::Range(host.begin, host.end());
- }
-
- size_t simplified_domain_pos = text.rfind(simplified_domain, host.end());
- DCHECK_NE(simplified_domain_pos, std::string::npos);
- ranges_surrounding_simplified_domain->emplace_back(0, simplified_domain_pos);
- ranges_surrounding_simplified_domain->emplace_back(host.end(), text.size());
- return gfx::Range(simplified_domain_pos, host.end());
-}
-
-bool OmniboxViewViews::GetURLEligibleForSimplifiedDomainEliding() const {
- if (HasFocus() || model()->user_input_in_progress())
- return false;
- if (!model()->CurrentTextIsURL())
- return false;
- std::u16string text = GetText();
- url::Parsed parts;
- std::u16string scheme_str;
- // Call Parse() here instead of ParseForEmphasizeComponents() because the
- // latter parses the inner URL for blob:, filesystem:, and view-source: URLs.
- // For those schemes, we want the outer scheme so that we can disable elision
- // for those schemes.
- AutocompleteInput::Parse(text, std::string(),
- model()->client()->GetSchemeClassifier(), &parts,
- &scheme_str, nullptr);
-
- // TODO(crbug.com/1117631): Simplified domain elision can have bugs for some
- // URLs with bidirectional hosts, disable elision for those URLs while the
- // bugs are fixed.
- const std::u16string url_host = text.substr(parts.host.begin, parts.host.len);
- if (base::i18n::GetStringDirection(url_host) ==
- base::i18n::TextDirection::UNKNOWN_DIRECTION) {
- return false;
- }
-
- // Simplified domain display only makes sense for http/https schemes; for now
- // we don't want to mess with the display of other URLs like data:, blob:,
- // chrome:, etc.
- return (scheme_str == base::UTF8ToUTF16(url::kHttpScheme) ||
- scheme_str == base::UTF8ToUTF16(url::kHttpsScheme)) &&
- !url_host.empty() &&
- !net::HostStringIsLocalhost(
- base::UTF16ToUTF8(text.substr(parts.host.begin, parts.host.len)));
-}
-
-void OmniboxViewViews::ResetToHideOnInteraction() {
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- model()->ShouldPreventElision()) {
- return;
- }
- // Delete the interaction animation; it'll get recreated in
- // DidGetUserInteraction(). Recreate the hover animation now because the user
- // can hover over the URL before interacting with the page to reveal the
- // scheme and trivial subdomain (if any).
- elide_after_web_contents_interaction_animation_.reset();
- hover_elide_or_unelide_animation_ =
- std::make_unique<OmniboxViewViews::ElideAnimation>(this, GetRenderText());
- if (GetURLEligibleForSimplifiedDomainEliding()) {
- ShowFullURLWithoutSchemeAndTrivialSubdomain();
- } else {
- if (!HasFocus() && !model()->user_input_in_progress())
- GetRenderText()->SetElideBehavior(gfx::ELIDE_TAIL);
- FitToLocalBounds();
- }
-}
-
-void OmniboxViewViews::OnShouldPreventElisionChanged() {
- Update();
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() &&
- !OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- return;
- }
- if (model()->ShouldPreventElision()) {
- hover_elide_or_unelide_animation_.reset();
- elide_after_web_contents_interaction_animation_.reset();
- if (GetURLEligibleForSimplifiedDomainEliding())
- ShowFullURL();
- return;
- }
- if (OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction()) {
- if (location_bar_view_)
- Observe(location_bar_view_->GetWebContents());
- ResetToHideOnInteraction();
- } else if (OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- if (GetURLEligibleForSimplifiedDomainEliding()) {
- ElideURL();
- }
- hover_elide_or_unelide_animation_ =
- std::make_unique<ElideAnimation>(this, GetRenderText());
- }
-}
-
-void OmniboxViewViews::MaybeElideURLWithAnimationFromInteraction() {
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- model()->ShouldPreventElision()) {
- return;
- }
-
- // If there's already a hover animation running, just let it run as we will
- // end up at the same place.
- if (hover_elide_or_unelide_animation_->IsAnimating())
- return;
-
- // This method runs when the user interacts with the page, such as scrolling
- // or typing. In the hide-on-interaction field trial, the URL is shown until
- // user interaction, at which point it's animated to a simplified version of
- // the domain (hiding the path and, optionally, subdomains). The animation is
- // designed to draw the user's attention and suggest that they can return to
- // the omnibox to uncover the full URL.
-
- // If we've already created and run the animation in an earlier call to this
- // method, we don't need to do so again.
- if (!GetURLEligibleForSimplifiedDomainEliding() ||
- elide_after_web_contents_interaction_animation_) {
- return;
- }
- GetRenderText()->SetElideBehavior(gfx::NO_ELIDE);
- elide_after_web_contents_interaction_animation_ =
- std::make_unique<ElideAnimation>(this, GetRenderText());
- std::vector<gfx::Range> ranges_surrounding_simplified_domain;
- gfx::Range simplified_domain =
- GetSimplifiedDomainBounds(&ranges_surrounding_simplified_domain);
- elide_after_web_contents_interaction_animation_->Start(
- simplified_domain, 0 /* delay_ms */, ranges_surrounding_simplified_domain,
- GetOmniboxColor(GetThemeProvider(),
- OmniboxPart::LOCATION_BAR_TEXT_DIMMED),
- SK_ColorTRANSPARENT);
-}
-
-void OmniboxViewViews::ElideURL() {
- DCHECK(OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover());
- DCHECK(GetURLEligibleForSimplifiedDomainEliding());
-
- std::vector<gfx::Range> ranges_surrounding_simplified_domain;
- gfx::Range simplified_domain_bounds =
- GetSimplifiedDomainBounds(&ranges_surrounding_simplified_domain);
-
- // Setting the elision behavior to anything other than NO_ELIDE would result
- // in the string getting cut off shorter the simplified domain, because
- // display offset isn't taken into account when RenderText elides the string.
- // See https://crbug.com/1099078. It's important to set to NO_ELIDE before
- // starting to calculate simplified domain bounds with GetSubstringBounds(),
- // because GetSubstringBounds() will fail if the simplified domain isn't
- // visible due to RenderText elision.
- GetRenderText()->SetElideBehavior(gfx::NO_ELIDE);
-
- // The simplified domain string must be a substring of the current display
- // text in order to elide to it.
- DCHECK_NE(
- GetRenderText()->GetDisplayText().find(GetText().substr(
- simplified_domain_bounds.start(), simplified_domain_bounds.end())),
- std::string::npos);
-
- SetCursorEnabled(false);
-
- gfx::Rect simplified_domain_rect;
- for (const auto& rect :
- GetRenderText()->GetSubstringBounds(simplified_domain_bounds)) {
- simplified_domain_rect.Union(rect);
- }
-
- // |simplified_domain_rect| gives us the current bounds of the simplified
- // domain substring. We shift it to the leftmost (rightmost if UI is RTL) edge
- // of the omnibox (as determined by the x position of the current display
- // rect), and then scroll to where the simplified domain begins, so that the
- // simplified domain appears at the leftmost/rightmost edge.
- gfx::Rect old_bounds = GetRenderText()->display_rect();
- int shifted_simplified_domain_x_pos;
- // The x position of the elided domain will depend on whether the UI is LTR or
- // RTL.
- if (base::i18n::IsRTL()) {
- shifted_simplified_domain_x_pos =
- old_bounds.right() - simplified_domain_rect.width();
- } else {
- shifted_simplified_domain_x_pos = old_bounds.x();
- }
- // Use |old_bounds| for y and height values because the URL should never shift
- // vertically while eliding to/from simplified domain.
- gfx::Rect shifted_simplified_domain_rect(
- shifted_simplified_domain_x_pos, old_bounds.y(),
- simplified_domain_rect.width(), old_bounds.height());
-
- // Now apply the display rect and offset so that exactly the simplified domain
- // is visible.
-
- // First check if the simplified domain fits in the local bounds. If it
- // doesn't, then we need to scroll so that the rightmost side is visible (e.g.
- // "evil.com" instead of "victim.com" if the full hostname
- // "victim.com.evil.com"). This check is only necessary for LTR mode because
- // in RTL mode, we scroll to the rightmost side of the domain automatically.
- if (shifted_simplified_domain_rect.width() > GetLocalBounds().width() &&
- !base::i18n::IsRTL()) {
- FitToLocalBounds();
- GetRenderText()->SetDisplayOffset(
- GetRenderText()->GetUpdatedDisplayOffset().x() -
- (simplified_domain_rect.right() -
- GetRenderText()->display_rect().width()));
- } else {
- // The simplified domain fits in the local bounds, so we proceed to set the
- // display rect and offset to make the simplified domain visible.
- GetRenderText()->SetDisplayRect(shifted_simplified_domain_rect);
- // Scroll the text to where the simplified domain begins, relative to the
- // leftmost (rightmost if UI is RTL) edge of the current display rect.
- if (base::i18n::IsRTL()) {
- GetRenderText()->SetDisplayOffset(
- GetRenderText()->GetUpdatedDisplayOffset().x() + old_bounds.right() -
- simplified_domain_rect.right());
- } else {
- GetRenderText()->SetDisplayOffset(
- GetRenderText()->GetUpdatedDisplayOffset().x() -
- (simplified_domain_rect.x() - old_bounds.x()));
- }
- }
-
- // GetSubstringBounds() rounds outward internally, so there may be small
- // portions of text still showing. Set the ranges surrounding the simplified
- // domain to transparent so that these artifacts don't show.
- for (const auto& range : ranges_surrounding_simplified_domain)
- ApplyColor(SK_ColorTRANSPARENT, range);
-}
-
-void OmniboxViewViews::ShowFullURL() {
- if (!OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() &&
- !OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- return;
- }
-
- if (hover_elide_or_unelide_animation_)
- hover_elide_or_unelide_animation_->Stop();
- if (elide_after_web_contents_interaction_animation_)
- elide_after_web_contents_interaction_animation_->Stop();
- ApplyCaretVisibility();
- FitToLocalBounds();
-
- // Previous animations or elisions might have faded the path and/or subdomains
- // to transparent, so reset their color now that they should be visible.
- ApplyColor(GetOmniboxColor(GetThemeProvider(),
- OmniboxPart::LOCATION_BAR_TEXT_DIMMED),
- gfx::Range(0, GetText().size()));
- UpdateTextStyle(GetText(), model()->CurrentTextIsURL(),
- model()->client()->GetSchemeClassifier());
-
- GetRenderText()->SetElideBehavior(gfx::ELIDE_TAIL);
-}
-
-void OmniboxViewViews::ShowFullURLWithoutSchemeAndTrivialSubdomain() {
- DCHECK(GetURLEligibleForSimplifiedDomainEliding());
- DCHECK(OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() ||
- OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover());
- DCHECK(!model()->ShouldPreventElision());
-
- // First show the full URL, then figure out what to elide.
- ShowFullURL();
-
- if (!GetURLEligibleForSimplifiedDomainEliding() ||
- model()->ShouldPreventElision()) {
- return;
- }
-
- // TODO(https://crbug.com/1099078): currently, we cannot set the elide
- // behavior to anything other than NO_ELIDE when the display offset is 0, i.e.
- // when we are not hiding the scheme and trivial subdomain. This is because
- // RenderText does not take display offset into account when eliding, so it
- // will over-elide by however much text is scrolled out of the display area.
- GetRenderText()->SetElideBehavior(gfx::NO_ELIDE);
-
- GetRenderText()->SetDisplayOffset(0);
- const gfx::Rect& current_display_rect = GetRenderText()->display_rect();
-
- // If the scheme and trivial subdomain should be elided, then we want to set
- // the display offset to where the hostname after the trivial subdomain (if
- // any) begins, relative to the current display rect.
- std::u16string text = GetText();
- url::Component host = GetHostComponentAfterTrivialSubdomain();
-
- // First check if the full hostname can fit in the local bounds. If not, then
- // show the rightmost portion of the hostname.
- gfx::Rect display_url_bounds;
- gfx::Range host_range(host.begin, host.end());
- if (TextRangeOverflowsView(this, GetRenderText(), host_range)) {
- gfx::Rect host_bounds;
- for (const auto& rect : GetRenderText()->GetSubstringBounds(host_range))
- host_bounds.Union(rect);
- // The full hostname won't fit, so show as much of it as possible starting
- // from the right side.
- display_url_bounds.set_x(
- current_display_rect.x() +
- (host_bounds.right() - current_display_rect.right()));
- display_url_bounds.set_y(current_display_rect.y());
- display_url_bounds.set_width(current_display_rect.width());
- display_url_bounds.set_height(current_display_rect.height());
- } else {
- for (const auto& rect : GetRenderText()->GetSubstringBounds(
- gfx::Range(host.begin, text.size()))) {
- display_url_bounds.Union(rect);
- }
- display_url_bounds.set_height(current_display_rect.height());
- display_url_bounds.set_y(current_display_rect.y());
- }
-
- // Set the scheme and trivial subdomain to transparent. This isn't necessary
- // to hide this portion of the text because it will be scrolled out of
- // visibility anyway when we set the display offset below. However, if the
- // user subsequently hovers over the URL to bring back the scheme and trivial
- // subdomain, the hover animation assumes that the hidden text starts from
- // transparent and fades it back in.
- ApplyColor(SK_ColorTRANSPARENT, gfx::Range(0, host.begin));
-
- // Before setting the display offset, set the display rect to the portion of
- // the URL that won't be elided, or leave it at the local bounds, whichever is
- // smaller. The display offset is capped at 0 if the text doesn't overflow the
- // display rect, so we must fit the display rect to the text so that we can
- // then set the display offset to scroll the scheme and trivial subdomain out
- // of visibility.
- GetRenderText()->SetDisplayRect(
- gfx::Rect(base::i18n::IsRTL()
- ? current_display_rect.right() - display_url_bounds.width()
- : current_display_rect.x(),
- display_url_bounds.y(), display_url_bounds.width(),
- display_url_bounds.height()));
-
- GetRenderText()->SetDisplayOffset(
- -1 * (display_url_bounds.x() - current_display_rect.x()));
-}
-
-url::Component OmniboxViewViews::GetHostComponentAfterTrivialSubdomain() const {
- url::Component host;
- url::Component unused_scheme;
- std::u16string text = GetText();
- AutocompleteInput::ParseForEmphasizeComponents(
- text, model()->client()->GetSchemeClassifier(), &unused_scheme, &host);
- url_formatter::StripWWWFromHostComponent(base::UTF16ToUTF8(text), &host);
- return host;
-}
-
BEGIN_METADATA(OmniboxViewViews, views::Textfield)
ADD_READONLY_PROPERTY_METADATA(bool, SelectionAtEnd)
ADD_READONLY_PROPERTY_METADATA(int, TextWidth)
ADD_READONLY_PROPERTY_METADATA(int, UnelidedTextWidth)
ADD_READONLY_PROPERTY_METADATA(int, Width)
ADD_READONLY_PROPERTY_METADATA(std::u16string, SelectedText)
-ADD_READONLY_PROPERTY_METADATA(bool, URLEligibleForSimplifiedDomainEliding)
-ADD_READONLY_PROPERTY_METADATA(url::Component,
- HostComponentAfterTrivialSubdomain)
END_METADATA
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.h b/chrome/browser/ui/views/omnibox/omnibox_view_views.h
index 796e9e5..c178ede1 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.h
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.h
@@ -20,7 +20,6 @@
#include "components/prefs/pref_change_registrar.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
-#include "content/public/browser/web_contents_observer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/window_open_disposition.h"
@@ -41,7 +40,6 @@
class OmniboxPopupContentsView;
namespace content {
-struct FocusedNodeDetails;
class WebContents;
} // namespace content
@@ -62,8 +60,7 @@
#endif
public views::TextfieldController,
public ui::CompositorObserver,
- public TemplateURLServiceObserver,
- public content::WebContentsObserver {
+ public TemplateURLServiceObserver {
public:
METADATA_HEADER(OmniboxViewViews);
@@ -153,118 +150,12 @@
std::u16string GetLabelForCommandId(int command_id) const override;
bool IsCommandIdEnabled(int command_id) const override;
- // content::WebContentsObserver:
- void DidStartNavigation(content::NavigationHandle* navigation) override;
- void DidFinishNavigation(content::NavigationHandle* navigation) override;
- void DidGetUserInteraction(const blink::WebInputEvent& event) override;
- void OnFocusChangedInPage(content::FocusedNodeDetails* details) override;
-
// For testing only.
OmniboxPopupContentsView* GetPopupContentsViewForTesting() const {
return popup_view_.get();
}
protected:
- // Animates the URL to a given range of text, which could be a substring or
- // superstring of what's currently displayed. An elision animation hides the
- // path (and optionally subdomains) by narrowing the bounds of each side of
- // the URL while also shifting the text to remain aligned with the leading
- // edge of the display area. While the bounds change, the text being elided
- // can be simultaneously faded to transparent to make the transition smoother.
- // An unelision animation is the reverse.
- //
- // Animation is used for elision when the elision is in response to a user
- // interaction and we want to draw attention to where the URL is going and how
- // it can be retrieved. Depending on field trial configurations, this could be
- // after the user interacts with the page (where we want to hide the full URL
- // but hint that it can be brought back by interacting with the omnibox),
- // and/or when the user hovers over the omnibox. In contrast,
- // ElideToSimplifiedDomain() and UnelideFromSimplifiedDomain() instantly
- // elide/unelide and are used when we want to elide/unelide without drawing
- // the user's attention (for example, on a same-document navigation where we
- // want the URL to remain simplified if it was simplified before the
- // navigation).
- //
- // This class is declared here for testing.
- class ElideAnimation : public views::AnimationDelegateViews {
- public:
- ElideAnimation(OmniboxViewViews* view, gfx::RenderText* render_text);
- ~ElideAnimation() override;
-
- // Begin the elision animation targeting |elide_to_bounds|, after a delay of
- // |delay_ms|. |ranges_surrounding_simplified_domain| should contain 1 or 2
- // ranges surrounding the simplified domain part, they should be in order
- // (i.e. the range on the left should be the first element). If only one
- // element is set, it will be assumed we are only eliding from the left
- // side. Those ranges will be faded from |starting_color| to
- // |ending_color|.
- void Start(
- const gfx::Range& elide_to_bounds,
- uint32_t delay_ms,
- const std::vector<gfx::Range>& ranges_surrounding_simplified_domain,
- SkColor starting_color,
- SkColor ending_color);
-
- void Stop();
-
- // Returns true if the animation is currently running.
- bool IsAnimating();
-
- // Returns the bounds to which the animation is eliding, as passed in to
- // Start().
- const gfx::Range& GetElideToBounds() const;
-
- // Returns the current color applied to each of the ranges in
- // |ranges_surrounding_simplified_domain| passed in to Start(), if the
- // animation is running or has completed running.
- // Returns gfx::kPlaceholderColor if the animation has not starting
- // running yet.
- SkColor GetCurrentColor() const;
-
- gfx::MultiAnimation* GetAnimationForTesting();
-
- int GetCurrentOffsetForTesting() { return current_offset_; }
-
- // views::AnimationDelegateViews:
- void AnimationProgressed(const gfx::Animation* animation) override;
-
- private:
- // Non-owning pointers. |view_| and |render_text_| must always outlive this
- // class.
- OmniboxViewViews* view_;
- gfx::RenderText* render_text_;
-
- // The target bounds passed in to Start().
- gfx::Range elide_to_bounds_;
- // The desired end state: the display rect that we are eliding or uneliding
- // to.
- gfx::Rect elide_to_rect_;
- // The starting display rect from which we are eliding or uneliding.
- gfx::Rect elide_from_rect_;
- // The display rect surrounding the simplified domain.
- gfx::Rect simplified_domain_bounds_;
- // The starting and ending display offsets for |render_text_|.
- int starting_display_offset_ = 0;
- int ending_display_offset_ = 0;
-
- // The current offset, exposed for testing.
- int current_offset_;
-
- // Holds the ranges surrounding the simplified domain part. As the animation
- // runs, each range fades from |starting_color_| to |ending_color_|.
- std::vector<gfx::Range> ranges_surrounding_simplified_domain_;
- SkColor starting_color_;
- SkColor ending_color_;
-
- // The underlying animation. We use a MultiAnimation to implement the
- // |delay_ms| delay passed into Start(). When this delay is nonzero, the
- // first part of the animation is a zero tween of |delay_ms| length.
- std::unique_ptr<gfx::MultiAnimation> animation_;
- };
-
- ElideAnimation* GetHoverElideOrUnelideAnimationForTesting();
- ElideAnimation* GetElideAfterInteractionAnimationForTesting();
-
// views::Textfield:
void OnThemeChanged() override;
bool IsDropCursorForInsertion() const override;
@@ -277,78 +168,7 @@
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsTest,
RendererInitiatedFocusPreservesCursorWhenStartingFocused);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExit);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExitIDN);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, PrivateRegistry);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- BrowserInitiatedNavigation);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- UserInteractionAndHover);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- MouseClick);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- FocusingEditableNode);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- BoundsChanged);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, BoundsChanged);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverHistogram);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest,
- CancellingAnimationDoesNotCrash);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- SchemeAndTrivialSubdomainElision);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest,
- SimplifiedDomainElisionWithNarrowOmnibox);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- SimplifiedDomainElisionWithNarrowOmnibox);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- HideOnInteractionAfterFocusAndBlur);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- URLPositionWithHideOnInteraction);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, AfterBlur);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- PathChangeDuringAnimation);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- VerticalAndHorizontalPosition);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- NoStaleGradientMask);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, ModifierKeys);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- ErrorPageNavigation);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- SameDocNavigations);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- SameDocNavigationDuringAnimation);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest, GradientMask);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- GradientMaskResetAfterStop);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- UserInteractionDuringAnimation);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- SubframeNavigations);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest,
- AlwaysShowFullURLs);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
- AlwaysShowFullURLs);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest,
- UnsetAlwaysShowFullURLs);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest,
- RegistrableDomainRepeated);
- FRIEND_TEST_ALL_PREFIXES(
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- TabChangeWhenNotEligibleForEliding);
FRIEND_TEST_ALL_PREFIXES(OmniboxPopupContentsViewTest,
EmitAccessibilityEvents);
// TODO(tommycli): Remove the rest of these friends after porting these
@@ -356,8 +176,6 @@
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, FriendlyAccessibleLabel);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, DoNotNavigateOnDrop);
- FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest,
- ElideAnimationDoesntStartIfNoVisibleChange);
enum class UnelisionGesture {
HOME_KEY_PRESSED,
@@ -434,7 +252,6 @@
bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
bool HandleAccessibleAction(const ui::AXActionData& action_data) override;
- void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnFocus() override;
void OnBlur() override;
std::u16string GetSelectionClipboardText() const override;
@@ -485,127 +302,12 @@
// always be considered "user gesture-triggered", lest it always return BLOCK.
void PermitExternalProtocolHandler();
- // Returns the gfx::Range of the simplified domain of the current URL, if
- // there is one. The simplified domain could be either the registrable domain
- // (if OmniboxFieldTrial::ElideToRegistrableDomain() is enabled) or the full
- // hostname. |ranges_surrounding_simplified_domain| is an optional output
- // parameter; if non-null, it will be populated with the ranges that do not
- // contain the simplified domain.
- gfx::Range GetSimplifiedDomainBounds(
- std::vector<gfx::Range>* ranges_surrounding_simplified_domain);
-
- // Returns true if the currently displayed URL is eligible for elision to a
- // simplified domain. This takes into account the omnibox's current state
- // (e.g. the URL shouldn't be elided if the user is currently editing it) as
- // well as properties of the current text (e.g. extension URLs or non-URLs
- // shouldn't be elided because they may not have simplified domains; localhost
- // URLs shouldn't be elided because they are used in development workflows
- // where the full URL is useful).
- //
- // This method does NOT take field trials into account or the "Always show
- // full URLs" option. Calling code should check field trial state and
- // model()->ShouldPreventElision() if applicable.
- bool GetURLEligibleForSimplifiedDomainEliding() const;
-
- // When certain field trials are enabled, the URL is shown on page load
- // and elided to a simplified domain when the user interacts with the page.
- // This method resets back to the on-page-load state. That is, it unhides the
- // URL (if currently hidden) and resets state so that the URL will show until
- // user interaction. This is used on navigation and blur, when the URL should
- // be shown but hidden on next user interaction.
- void ResetToHideOnInteraction();
-
- // Called when the "Always show full URLs" preference is toggled. Updates the
- // state to elide to a simplified domain on user interaction and/or reveal the
- // URL on hover, depending on field trial configuration.
- //
- // When the preference changes, we immediately elide/unelide instead of
- // animating. Animating might look a little nicer, but this should be a
- // relatively rare event so it's simpler to just immediately update the
- // display.
- void OnShouldPreventElisionChanged();
-
- // Elides the URL to a simplified version of the domain with an animation.
- // This should be called when a user interaction with the web contents
- // triggers elision. Does nothing if the relevant field trial is disabled or
- // the URL is not eligible for eliding.
- void MaybeElideURLWithAnimationFromInteraction();
-
- // The methods below elide to or unelide from a simplified version of the URL.
- // Callers should ensure that the URL is valid before calling.
- //
- // These methods do not animate, but rather immediately elide/unelide. These
- // methods are used when we don't want to draw the user's attention to the URL
- // simplification -- for example, if the URL is already simplified and the
- // user performs a same-document navigation, we want to keep the URL
- // simplified without it appearing to be a change from the user's perspective.
-
- // Elides the URL to a simplified version of the domain. This will be the
- // registrable domain if OmniboxFieldTrial::ShouldElideToRegistrableDomain()
- // is true; otherwise it is the hostname with trivial subdomains ("www.")
- // elided. The scheme, path, and other components of the URL are hidden.
- void ElideURL();
- // Show the full URL, including scheme, all subdomains, and path.
- void ShowFullURL();
- // Shows the full URL and then elides http/https schemes and the
- // "www." subdomain (if present) by setting the display rect to the width of
- // the remaining URL and then setting the display offset to scroll the scheme
- // and trivial subdomain offscreen.
- void ShowFullURLWithoutSchemeAndTrivialSubdomain();
-
- // Parses GetText() as a URL, trims trivial subdomains from it (if any and if
- // applicable), and returns the result.
- url::Component GetHostComponentAfterTrivialSubdomain() const;
-
// When true, the location bar view is read only and also is has a slightly
// different presentation (smaller font size). This is used for popups.
bool popup_window_mode_;
std::unique_ptr<OmniboxPopupContentsView> popup_view_;
- // Animations are used to elide/unelide the path (and subdomains, if
- // OmniboxFieldTrial::ShouldElideToRegistrableDomain() is true) under some
- // field trial settings. These animations are created at different times
- // depending on the field trial configuration, so don't assume they are
- // non-null.
- //
- // These animations are used by different field trials as described below.
-
- // This animation is used to unelide or elide the URL
- // when the mouse hovers or exits the omnibox. The URL will unelide to the
- // full URL or a partially elided version (with scheme and trivial subdomains
- // elided) depending on whether the user has interacted with the page yet
- // (when reveal-on-interaction is enabled).
- std::unique_ptr<ElideAnimation> hover_elide_or_unelide_animation_;
- // When ShouldHidePathQueryRefOnInteraction() is enabled, when a
- // navigation finishes, we unelide the URL if it was a full cross-document
- // navigation. Once the user interacts with the page, we create and run
- // |elide_after_web_contents_interaction_animation_| to elide the URL. After
- // the first user interaction,
- // |elide_after_web_contents_interaction_animation_| doesn't run again until
- // it's re-created after the next navigation. There are 2 separate animations
- // (one for after-interaction and one hovering) so that the state of the
- // after-interaction animation can be queried to know when the user has or has
- // not already interacted with the page.
- std::unique_ptr<ElideAnimation>
- elide_after_web_contents_interaction_animation_;
-
- // If set, rectangles will be drawn as gradient masks over the omnibox text.
- // Used to smooth color transition when an ElideAnimation is animating.
- gfx::Rect elide_animation_smoothing_rect_left_;
- gfx::Rect elide_animation_smoothing_rect_right_;
-
- // The time that the mouse begins hovering over the omnibox, used for
- // recording metrics related to simplified domain field trials. Set in
- // OnMouseMoved() and cleared when the mouse exits the hover.
- base::Time hover_start_time_;
- // A histogram is recorded for each continuous hover over the omnibox, ended
- // by either focusing or exiting the mouse. This is set to true if the
- // histogram was recorded due to the omnibox being focused, so that it won't
- // be recorded again for the same continuous hover when the mouse exits.
- bool recorded_hover_on_focus_ = false;
- base::Clock* clock_;
-
// Selection persisted across temporary text changes, like popup suggestions.
std::vector<gfx::Range> saved_temporary_selection_;
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
index 4d55b1e..fd7c844b 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
@@ -527,10 +527,7 @@
ui_test_utils::NavigateToURL(browser(),
GURL("http://example.com/#%E2%98%83"));
- EXPECT_EQ(view->GetText(),
- OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()
- ? u"http://example.com/#\u2603"
- : u"example.com/#\u2603");
+ EXPECT_EQ(view->GetText(), u"example.com/#\u2603");
}
// Ensure that when the user navigates between suggestions, that the accessible
@@ -721,16 +718,7 @@
ui_test_utils::NavigateToURL(browser(), url);
- // By default, the URL should be elided. Depending on field trial
- // configuration, this will be implemented by pushing the scheme out of the
- // display area or by eliding it from the actual text.
- if (OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- EXPECT_EQ(url_text, omnibox_view_views->GetText());
- EXPECT_GT(
- 0, omnibox_view_views->GetRenderText()->GetUpdatedDisplayOffset().x());
- } else {
- EXPECT_EQ(url_text, u"http://" + omnibox_view_views->GetText());
- }
+ EXPECT_EQ(url_text, u"http://" + omnibox_view_views->GetText());
// After toggling the setting, the full URL should be shown.
chrome::ToggleShowFullURLs(browser());
@@ -740,13 +728,7 @@
// Toggling the setting again should go back to the elided URL.
chrome::ToggleShowFullURLs(browser());
- if (OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover()) {
- EXPECT_EQ(url_text, omnibox_view_views->GetText());
- EXPECT_GT(
- 0, omnibox_view_views->GetRenderText()->GetUpdatedDisplayOffset().x());
- } else {
- EXPECT_EQ(url_text, u"http://" + omnibox_view_views->GetText());
- }
+ EXPECT_EQ(url_text, u"http://" + omnibox_view_views->GetText());
}
// The following set of tests require UIA accessibility support, which only
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
index 7f13620..b503424 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
@@ -70,16 +70,6 @@
class TestingOmniboxView;
-void ExpectElidedToSimplifiedDomain(TestingOmniboxView* view,
- base::StringPiece16 scheme,
- base::StringPiece16 subdomain,
- base::StringPiece16 hostname_and_scheme,
- base::StringPiece16 path,
- bool should_elide_to_registrable_domain);
-
-void ExpectUnelidedFromSimplifiedDomain(gfx::RenderText* render_text,
- const gfx::Range& display_url);
-
// TestingOmniboxView ---------------------------------------------------------
class TestingOmniboxView : public OmniboxViewViews {
@@ -112,34 +102,6 @@
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {}
void OnThemeChanged() override;
- // In the simplified domain field trials, these methods advance through
- // elision/unelision animations (triggered by hovering over the omnibox and
- // interacting with the web contents, respectively) by |step_ms|.
- void StepSimplifiedDomainHoverAnimation(int64_t step_ms);
- void StepSimplifiedDomainInteractionAnimation(int64_t step_ms);
-
- // Simulates a navigation and checks that the URL is elided to the simplified
- // domain afterwards. This simulates a renderer-initiated navigation, in which
- // the display URL is updated between DidStartNavigation() and
- // DidFinishNavigation() calls.
- void NavigateAndExpectElided(const GURL& url,
- bool is_same_document,
- const GURL& previous_url,
- base::StringPiece16 scheme,
- base::StringPiece16 subdomain,
- base::StringPiece16 hostname_and_scheme,
- base::StringPiece16 path,
- bool should_elide_to_registrable_domain);
-
- // Simluates a navigation and checks that the URL is unelided from the
- // simplified domain afterwards. This simulates a renderer-initiated
- // navigation, in which the display URL is updated between
- // DidStartNavigation() and DidFinishNavigation() calls.
- void NavigateAndExpectUnelided(base::StringPiece16 url,
- bool is_same_document,
- const GURL& previous_url,
- base::StringPiece16 scheme);
-
using OmniboxView::OnInlineAutocompleteTextMaybeChanged;
private:
@@ -166,8 +128,6 @@
// order.
std::vector<std::pair<SkColor, gfx::Range>> range_colors_;
- TestLocationBarModel* location_bar_model_;
-
// SetEmphasis() logs whether the base color of the text is emphasized.
bool base_text_emphasis_;
};
@@ -179,8 +139,7 @@
std::move(client),
false,
nullptr,
- gfx::FontList()),
- location_bar_model_(location_bar_model) {}
+ gfx::FontList()) {}
void TestingOmniboxView::ResetEmphasisTestState() {
base_text_emphasis_ = false;
@@ -250,192 +209,6 @@
OmniboxViewViews::ApplyColor(color, range);
}
-void TestingOmniboxView::StepSimplifiedDomainHoverAnimation(int64_t step_ms) {
- OmniboxViewViews::ElideAnimation* hover_animation =
- GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(hover_animation);
- EXPECT_TRUE(hover_animation->IsAnimating());
- gfx::AnimationContainerElement* hover_animation_as_element =
- static_cast<gfx::AnimationContainerElement*>(
- hover_animation->GetAnimationForTesting());
- hover_animation_as_element->SetStartTime(base::TimeTicks());
- hover_animation_as_element->Step(base::TimeTicks() +
- base::TimeDelta::FromMilliseconds(step_ms));
-}
-
-void TestingOmniboxView::StepSimplifiedDomainInteractionAnimation(
- int64_t step_ms) {
- OmniboxViewViews::ElideAnimation* interaction_animation =
- GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(interaction_animation);
- EXPECT_TRUE(interaction_animation->IsAnimating());
- gfx::AnimationContainerElement* interaction_animation_as_element =
- static_cast<gfx::AnimationContainerElement*>(
- interaction_animation->GetAnimationForTesting());
- interaction_animation_as_element->SetStartTime(base::TimeTicks());
- interaction_animation_as_element->Step(
- base::TimeTicks() + base::TimeDelta::FromMilliseconds(step_ms));
-}
-
-void TestingOmniboxView::NavigateAndExpectElided(
- const GURL& url,
- bool is_same_document,
- const GURL& previous_url,
- base::StringPiece16 scheme,
- base::StringPiece16 subdomain,
- base::StringPiece16 hostname_and_scheme,
- base::StringPiece16 path,
- bool should_elide_to_registrable_domain) {
- content::MockNavigationHandle navigation;
- navigation.set_is_same_document(is_same_document);
- navigation.set_url(url);
- navigation.set_previous_main_frame_url(previous_url);
- DidStartNavigation(&navigation);
- location_bar_model_->set_url(url);
- location_bar_model_->set_url_for_display(base::ASCIIToUTF16(url.spec()));
- model()->ResetDisplayTexts();
- RevertAll();
- navigation.set_has_committed(true);
- DidFinishNavigation(&navigation);
- ExpectElidedToSimplifiedDomain(this, scheme, subdomain, hostname_and_scheme,
- path, should_elide_to_registrable_domain);
-}
-
-void TestingOmniboxView::NavigateAndExpectUnelided(base::StringPiece16 url,
- bool is_same_document,
- const GURL& previous_url,
- base::StringPiece16 scheme) {
- content::MockNavigationHandle navigation;
- navigation.set_is_same_document(is_same_document);
- navigation.set_url(GURL(url));
- navigation.set_previous_main_frame_url(previous_url);
- DidStartNavigation(&navigation);
- location_bar_model_->set_url(GURL(url));
- location_bar_model_->set_url_for_display(std::u16string(url));
- model()->ResetDisplayTexts();
- RevertAll();
- navigation.set_has_committed(true);
- DidFinishNavigation(&navigation);
- ExpectUnelidedFromSimplifiedDomain(this->GetRenderText(),
- gfx::Range(scheme.size(), url.size()));
-}
-
-// TODO(crbug.com/1112536): With RTL UI, the URL is sometimes off by one pixel
-// of the right edge. Investigate if this is expected, otherwise replace this
-// with equality checks in tests that use it. Checks |a| is within 1 of |b|.
-void CheckEqualsWithMarginOne(int a, int b) {
- EXPECT_LE(std::abs(a - b), 1);
-}
-
-// Checks that |view|'s current display rect and offset does not display
-// |path|, and also does not display |subdomain_and_scheme| if
-// |should_elide_to_registrable_domain| is true.
-//
-// |subdomain_and_scheme| is assumed to be a prefix of |hostname_and_scheme|.
-// |subdomain_and_scheme| and |subdomain| should include a trailing ".", and
-// |path| should include a leading "/".
-void ExpectElidedToSimplifiedDomain(TestingOmniboxView* view,
- base::StringPiece16 scheme,
- base::StringPiece16 subdomain,
- base::StringPiece16 hostname_and_scheme,
- base::StringPiece16 path,
- bool should_elide_to_registrable_domain) {
- gfx::RenderText* render_text = view->GetRenderText();
- gfx::Rect subdomain_and_scheme_rect;
- for (const auto& rect : render_text->GetSubstringBounds(
- gfx::Range(0, scheme.size() + subdomain.size()))) {
- subdomain_and_scheme_rect.Union(rect);
- }
- gfx::Rect path_rect;
- for (const auto& rect : render_text->GetSubstringBounds(
- gfx::Range(hostname_and_scheme.size(),
- hostname_and_scheme.size() + path.size()))) {
- path_rect.Union(rect);
- }
- EXPECT_FALSE(render_text->display_rect().Contains(path_rect));
- if (should_elide_to_registrable_domain) {
- EXPECT_FALSE(
- render_text->display_rect().Contains(subdomain_and_scheme_rect));
- gfx::Rect registrable_domain_rect;
- for (const auto& rect : render_text->GetSubstringBounds(gfx::Range(
- scheme.size() + subdomain.size(), hostname_and_scheme.size()))) {
- registrable_domain_rect.Union(rect);
- }
- EXPECT_TRUE(render_text->display_rect().Contains(registrable_domain_rect));
- // The text should be scrolled to push the scheme and subdomain offscreen,
- // so that the text starts at the registrable domain. Note that this code
- // computes the expected offset by comparing x() values rather than
- // comparing based on widths (for example, it wouldn't work to check that
- // the display offset is equal to |subdomain_and_scheme_rect|'s width). This
- // is because GetSubstringBounds() rounds outward, so the width of
- // |subdomain_and_scheme_rect| could slightly overlap
- // |registrable_domain_rect|.
- // In the RTL UI case, the offset instead has to push the path offscreen to
- // the right, so we check offset equals the width of the path rectangle.
- if (base::i18n::IsRTL()) {
- CheckEqualsWithMarginOne(path_rect.width(),
- render_text->GetUpdatedDisplayOffset().x());
- } else {
- EXPECT_EQ(registrable_domain_rect.x() - subdomain_and_scheme_rect.x(),
- -1 * render_text->GetUpdatedDisplayOffset().x());
- }
- // The scheme and subdomain should be transparent.
- EXPECT_EQ(SK_ColorTRANSPARENT, view->GetLatestColorForRange(gfx::Range(
- 0, scheme.size() + subdomain.size())));
- } else {
- // When elision to registrable domain is disabled, the scheme should be
- // hidden but the subdomain should not be.
- EXPECT_FALSE(
- render_text->display_rect().Contains(subdomain_and_scheme_rect));
- gfx::Rect hostname_rect;
- for (const auto& rect : render_text->GetSubstringBounds(
- gfx::Range(scheme.size(), hostname_and_scheme.size()))) {
- hostname_rect.Union(rect);
- }
- // The text should be scrolled to push the scheme offscreen, so that the
- // text starts at the subdomain. As above, it's important to compute the
- // expected offset with x() values instead of width()s, since the width()s
- // of different adjacent substring bounds could overlap.
- // In the RTL UI case, the offset instead has to push the path offscreen to
- // the right, so we check offset equals the width of the path rectangle.
- if (base::i18n::IsRTL()) {
- CheckEqualsWithMarginOne(path_rect.width(),
- render_text->GetUpdatedDisplayOffset().x());
- } else {
- EXPECT_EQ(hostname_rect.x() - subdomain_and_scheme_rect.x(),
- -1 * render_text->GetUpdatedDisplayOffset().x());
- }
- // The scheme should be transparent.
- EXPECT_EQ(SK_ColorTRANSPARENT,
- view->GetLatestColorForRange(gfx::Range(0, scheme.size())));
- }
- // The path should be transparent.
- EXPECT_EQ(SK_ColorTRANSPARENT,
- view->GetLatestColorForRange(
- gfx::Range(hostname_and_scheme.size(),
- hostname_and_scheme.size() + path.size())));
-}
-
-// Checks that |render_text|'s current display rect and offset displays all of
-// |display_url|, starting at the leading edge.
-void ExpectUnelidedFromSimplifiedDomain(gfx::RenderText* render_text,
- const gfx::Range& display_url) {
- gfx::Rect unelided_rect;
- for (const auto& rect : render_text->GetSubstringBounds(display_url)) {
- unelided_rect.Union(rect);
- }
- EXPECT_TRUE(render_text->display_rect().Contains(unelided_rect));
- // |display_url| should be at the leading edge of |render_text|'s display
- // rect for LTR UI, or at the rightmost side of the omnibox for RTL UI.
- if (base::i18n::IsRTL()) {
- CheckEqualsWithMarginOne(
- unelided_rect.x(),
- render_text->display_rect().right() - unelided_rect.width());
- } else {
- EXPECT_EQ(unelided_rect.x(), render_text->display_rect().x());
- }
-}
-
// TestingOmniboxEditController -----------------------------------------------
class TestingOmniboxEditController : public ChromeOmniboxEditController {
@@ -489,19 +262,6 @@
base::test::ScopedFeatureList scoped_feature_list_;
};
-// The display URL used in simplified domain display tests.
-static constexpr base::StringPiece16 kSimplifiedDomainDisplayUrl =
- u"https://foo.example.test/bar";
-static constexpr base::StringPiece16
- kSimplifiedDomainDisplayUrlHostnameAndScheme = u"https://foo.example.test";
-static constexpr base::StringPiece16
- kSimplifiedDomainDisplayUrlSubdomainAndScheme = u"https://foo.";
-static constexpr base::StringPiece16 kSimplifiedDomainDisplayUrlSubdomain =
- u"foo.";
-static constexpr base::StringPiece16 kSimplifiedDomainDisplayUrlPath = u"/bar";
-static constexpr base::StringPiece16 kSimplifiedDomainDisplayUrlScheme =
- u"https://";
-
class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {
public:
OmniboxViewViewsTest(const std::vector<FeatureAndParams>& enabled_features,
@@ -556,13 +316,6 @@
omnibox_view()->RevertAll();
}
- // Sets up tests for the simplified domain field trials.
- void SetUpSimplifiedDomainTest() {
- UpdateDisplayURL(kSimplifiedDomainDisplayUrl);
- // Call OnThemeChanged() to create the animations.
- omnibox_view()->OnThemeChanged();
- }
-
// testing::Test:
void SetUp() override;
void TearDown() override;
@@ -1092,30 +845,6 @@
EXPECT_FALSE(omnibox_view()->IsSelectAll());
}
-TEST_F(OmniboxViewViewsTest, ElideAnimationDoesntStartIfNoVisibleChange) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- OmniboxViewViews::ElideAnimation elide_animation(omnibox_view(), render_text);
- // Before any animation runs, the elide from rectangle is considered to be
- // render_text's DisplayRect, so set it manually to be the current URL length.
- gfx::Rect full_url_bounds;
- for (auto rect : render_text->GetSubstringBounds(
- gfx::Range(0, omnibox_view()->GetOmniboxTextLength()))) {
- full_url_bounds.Union(rect);
- }
- render_text->SetDisplayRect(full_url_bounds);
- // Start the animation, and have it animate to the current state.
- elide_animation.Start(
- gfx::Range(0,
- omnibox_view()->GetOmniboxTextLength()), /* elide_to_bounds */
- 0, /* delay_ms */
- {gfx::Range(0, 0)}, /* ranges_surrounding_simplified_domain */
- SK_ColorBLACK, /* starting_color */
- SK_ColorBLACK); /* ending_color */
- // Animation shouldn't have been started.
- EXPECT_FALSE(elide_animation.IsAnimating());
-}
-
class OmniboxViewViewsClipboardTest
: public OmniboxViewViewsTest,
public ::testing::WithParamInterface<ui::TextEditCommand> {
@@ -1688,1880 +1417,3 @@
EXPECT_EQ(0U, end);
ExpectFullUrlDisplayed();
}
-
-// Returns true if |render_text|'s current display rect and offset display at
-// least part of |path_bounds|, but not the full |display_url|. This is useful
-// for checking the displayed text partway through an animation.
-bool IsPartlyThroughSimplifiedDomainElision(gfx::RenderText* render_text,
- base::StringPiece16 display_url,
- const gfx::Range& path_bounds) {
- // First check if all of |display_url| is showing; if it is, we aren't partly
- // elided.
- gfx::Rect unelided_rect;
- for (const auto& rect :
- render_text->GetSubstringBounds(gfx::Range(0, display_url.size()))) {
- unelided_rect.Union(rect);
- }
- if (render_text->display_rect().Contains(unelided_rect) &&
- render_text->GetUpdatedDisplayOffset().x() == 0) {
- return false;
- }
- // Now check if at least some of |path| is visible.
- gfx::Rect path_rect;
- for (const auto& rect : render_text->GetSubstringBounds(path_bounds)) {
- path_rect.Union(rect);
- }
- return render_text->display_rect().Intersects(path_rect);
-}
-
-class OmniboxViewViewsNoSimplifiedDomainTest : public OmniboxViewViewsTest {
- public:
- OmniboxViewViewsNoSimplifiedDomainTest()
- : OmniboxViewViewsTest(
- {},
- {omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction,
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover}) {}
-
- OmniboxViewViewsNoSimplifiedDomainTest(
- const OmniboxViewViewsNoSimplifiedDomainTest&) = delete;
- OmniboxViewViewsNoSimplifiedDomainTest& operator=(
- const OmniboxViewViewsNoSimplifiedDomainTest&) = delete;
-};
-
-// Tests that when no simplified domain field trials are enabled, URL components
-// are not hidden. Regression test for https://crbug.com/1093748.
-TEST_F(OmniboxViewViewsNoSimplifiedDomainTest, UrlNotSimplifiedByDefault) {
- SetUpSimplifiedDomainTest();
- omnibox_view()->EmphasizeURLComponents();
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
-}
-
-class OmniboxViewViewsRevealOnHoverTest
- : public OmniboxViewViewsTest,
- public ::testing::WithParamInterface<std::pair<bool, bool>> {
- public:
- OmniboxViewViewsRevealOnHoverTest()
- : OmniboxViewViewsTest(
- GetParam().first
- ? std::vector<FeatureAndParams>(
- {{omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- {}},
- {omnibox::kMaybeElideToRegistrableDomain,
- // Ensure all domains are elidable by policy.
- {{"max_unelided_host_length", "0"}}}})
- : std::vector<FeatureAndParams>(
- {{omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- {}}}),
- {},
- GetParam().second) {
- // The lookalike allowlist is used by the registrable-domain-elision code.
- reputation::InitializeBlankLookalikeAllowlistForTesting();
- }
-
- OmniboxViewViewsRevealOnHoverTest(const OmniboxViewViewsRevealOnHoverTest&) =
- delete;
- OmniboxViewViewsRevealOnHoverTest& operator=(
- const OmniboxViewViewsRevealOnHoverTest&) = delete;
-
- protected:
- bool ShouldElideToRegistrableDomain() { return GetParam().first; }
-};
-
-INSTANTIATE_TEST_SUITE_P(OmniboxViewViewsRevealOnHoverTest,
- OmniboxViewViewsRevealOnHoverTest,
- ::testing::ValuesIn({std::make_pair(true, false),
- std::make_pair(false, false),
- std::make_pair(true, true),
- std::make_pair(false, true)}));
-
-// Tests the field trial variation that shows a simplified domain by default and
-// reveals the unsimplified URL on hover.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, HoverAndExit) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // As soon as the mouse hovers over the omnibox, the unelide animation should
- // start running.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* hover_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(hover_animation);
- EXPECT_TRUE(hover_animation->IsAnimating());
-
- // Advance the clock through the animation.
- ASSERT_NO_FATAL_FAILURE(omnibox_view()->StepSimplifiedDomainHoverAnimation(
- OmniboxFieldTrial::UnelideURLOnHoverThresholdMs()));
- // After the extended hover threshold has elapsed, the display text shouldn't
- // have changed yet.
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // Now advance through the unelision and check the display text. We assume
- // that the animation takes less than 1 second.
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
- EXPECT_FALSE(hover_animation->IsAnimating());
- // Check that the path and subdomain are not transparent.
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(
- gfx::Range(kSimplifiedDomainDisplayUrlHostnameAndScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(gfx::Range(
- 0, kSimplifiedDomainDisplayUrlSubdomainAndScheme.size())));
-
- // Now exit the mouse. At this point the elision animation should run.
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_EXITED, {0, 0}));
- EXPECT_TRUE(hover_animation->IsAnimating());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-}
-
-// Tests the field trial variation that shows a simplified domain by default and
-// reveals the unsimplified URL on hover, using an IDN url.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, HoverAndExitIDN) {
- // The display URL used in simplified domain display tests.
- static constexpr base::StringPiece16 kSimplifiedDomainDisplayIDNUrl =
- u"https://テスト.住所の例.test/bar";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayIDNUrlHostnameAndScheme =
- u"https://テスト.住所の例.test";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayIDNUrlSubdomainAndScheme = u"https://テスト.";
- static constexpr base::StringPiece16 kSimplifiedDomainDisplayIDNUrlSubdomain =
- u"テスト.";
- static constexpr base::StringPiece16 kSimplifiedDomainDisplayIDNUrlPath =
- u"/bar";
- static constexpr base::StringPiece16 kSimplifiedDomainDisplayIDNUrlScheme =
- u"https://";
- UpdateDisplayURL(kSimplifiedDomainDisplayIDNUrl);
- // Call OnThemeChanged() to create the animations.
- omnibox_view()->OnThemeChanged();
-
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayIDNUrlScheme,
- kSimplifiedDomainDisplayIDNUrlSubdomain,
- kSimplifiedDomainDisplayIDNUrlHostnameAndScheme,
- kSimplifiedDomainDisplayIDNUrlPath, ShouldElideToRegistrableDomain()));
-
- // As soon as the mouse hovers over the omnibox, the unelide animation should
- // start running.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- // Advance the clock through the animation.
- ASSERT_NO_FATAL_FAILURE(omnibox_view()->StepSimplifiedDomainHoverAnimation(
- OmniboxFieldTrial::UnelideURLOnHoverThresholdMs()));
- // After the extended hover threshold has elapsed, the display text shouldn't
- // have changed yet.
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayIDNUrlScheme,
- kSimplifiedDomainDisplayIDNUrlSubdomain,
- kSimplifiedDomainDisplayIDNUrlHostnameAndScheme,
- kSimplifiedDomainDisplayIDNUrlPath, ShouldElideToRegistrableDomain()));
-
- // Now advance through the unelision and check the display text. We assume
- // that the animation takes less than 1 second.
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(0, kSimplifiedDomainDisplayIDNUrl.size())));
- OmniboxViewViews::ElideAnimation* hover_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(hover_animation);
- EXPECT_FALSE(hover_animation->IsAnimating());
- // Check that the path and subdomain are not transparent.
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(gfx::Range(
- kSimplifiedDomainDisplayIDNUrlHostnameAndScheme.size(),
- kSimplifiedDomainDisplayIDNUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(gfx::Range(
- 0, kSimplifiedDomainDisplayIDNUrlSubdomainAndScheme.size())));
-
- // Now exit the mouse. At this point the elision animation should run.
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_EXITED, {0, 0}));
- EXPECT_TRUE(hover_animation->IsAnimating());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayIDNUrlScheme,
- kSimplifiedDomainDisplayIDNUrlSubdomain,
- kSimplifiedDomainDisplayIDNUrlHostnameAndScheme,
- kSimplifiedDomainDisplayIDNUrlPath, ShouldElideToRegistrableDomain()));
-}
-
-// Tests the field trial variation that shows a simplified domain by default
-// using a private registry (https://publicsuffix.org/list/). Private registries
-// should be ignored when computing the simplified domain, to avoid creating
-// incentives for malicious sites to add themselves to the Public Suffix List.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, PrivateRegistry) {
- // This test is only applicable when we elide to the registrable domain;
- // otherwise private vs public registries are irrelevant.
- if (!ShouldElideToRegistrableDomain())
- return;
-
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayPrivateRegistryUrl =
- u"https://foo.blogspot.com/bar";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayPrivateRegistryUrlHostnameAndScheme =
- u"https://foo.blogspot.com";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayPrivateRegistryUrlSubdomain = u"foo.";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayPrivateRegistryUrlPath = u"/bar";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayPrivateRegistryUrlScheme = u"https://";
- UpdateDisplayURL(kSimplifiedDomainDisplayPrivateRegistryUrl);
- // Call OnThemeChanged() to create the animations.
- omnibox_view()->OnThemeChanged();
-
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayPrivateRegistryUrlScheme,
- kSimplifiedDomainDisplayPrivateRegistryUrlSubdomain,
- kSimplifiedDomainDisplayPrivateRegistryUrlHostnameAndScheme,
- kSimplifiedDomainDisplayPrivateRegistryUrlPath,
- ShouldElideToRegistrableDomain()));
-}
-
-// Tests the field trial variation that shows a simplified domain by default and
-// reveals the unsimplified URL on hover, using a URL where the path contains
-// the domain name.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, HoverAndExitDomainInPath) {
- // The display URL used in simplified domain display tests.
- static constexpr base::StringPiece16 kSimplifiedDomainDisplayRepeatedUrl =
- u"https://ex.example.test/example.test";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayRepeatedUrlHostnameAndScheme =
- u"https://ex.example.test";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayRepeatedUrlSubdomain = u"ex.";
- static constexpr base::StringPiece16 kSimplifiedDomainDisplayRepeatedUrlPath =
- u"/example.test";
- static constexpr base::StringPiece16
- kSimplifiedDomainDisplayRepeatedUrlScheme = u"https://";
- location_bar_model()->set_url(GURL(kSimplifiedDomainDisplayRepeatedUrl));
- location_bar_model()->set_url_for_display(
- std::u16string(kSimplifiedDomainDisplayRepeatedUrl));
- omnibox_view()->model()->ResetDisplayTexts();
- omnibox_view()->RevertAll();
- // Call OnThemeChanged() to create the animations.
- omnibox_view()->OnThemeChanged();
-
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayRepeatedUrlScheme,
- kSimplifiedDomainDisplayRepeatedUrlSubdomain,
- kSimplifiedDomainDisplayRepeatedUrlHostnameAndScheme,
- kSimplifiedDomainDisplayRepeatedUrlPath,
- ShouldElideToRegistrableDomain()));
-}
-
-class OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest
- : public OmniboxViewViewsTest,
- public ::testing::WithParamInterface<std::pair<bool, bool>> {
- public:
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest()
- : OmniboxViewViewsTest(
- GetParam().first
- ? std::vector<FeatureAndParams>(
- {{omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- {}},
- {omnibox::
- kHideSteadyStateUrlPathQueryAndRefOnInteraction,
- {}},
- {omnibox::kMaybeElideToRegistrableDomain,
- // Ensure all domains are elidable by policy.
- {{"max_unelided_host_length", "0"}}}})
- : std::vector<FeatureAndParams>(
- {{omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- {}},
- {omnibox::
- kHideSteadyStateUrlPathQueryAndRefOnInteraction,
- {}}}),
- {},
- GetParam().second) {
- // The lookalike allowlist is used by the registrable-domain-elision code.
- reputation::InitializeBlankLookalikeAllowlistForTesting();
- }
-
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest(
- const OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest&) = delete;
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest& operator=(
- const OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest&) = delete;
-
- protected:
- bool ShouldElideToRegistrableDomain() { return GetParam().first; }
-};
-
-INSTANTIATE_TEST_SUITE_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- ::testing::ValuesIn({std::make_pair(true, false),
- std::make_pair(false, false),
- std::make_pair(true, true),
- std::make_pair(false, true)}));
-
-// Tests the field trial variation that shows the simplified domain when the
-// user interacts with the page and brings back the URL when the user hovers
-// over the omnibox.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- UserInteractionAndHover) {
- SetUpSimplifiedDomainTest();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction and check that the fade-out animation runs.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- // Advance the clock through the fade-out animation; we assume that it takes
- // less than 1s.
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // A second user interaction should not run the animation again.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- EXPECT_FALSE(omnibox_view()
- ->GetElideAfterInteractionAnimationForTesting()
- ->IsAnimating());
-
- // The URL should come back on hover.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- // The hover should bring back the full URL, including scheme and trivial
- // subdomains.
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
- // The path and scheme/subdomain should not be transparent.
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(
- gfx::Range(kSimplifiedDomainDisplayUrlHostnameAndScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(gfx::Range(
- 0, kSimplifiedDomainDisplayUrlSubdomainAndScheme.size())));
-}
-
-// Tests that the hide-on-interaction simplified domain field trial handles
-// intermediate states during a navigation properly. This test simulates a
-// browser-initiated navigation in which the URL updates before the navigation
-// commits.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- BrowserInitiatedNavigation) {
- SetUpSimplifiedDomainTest();
-
- ASSERT_NO_FATAL_FAILURE(omnibox_view()->NavigateAndExpectUnelided(
- kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(), kSimplifiedDomainDisplayUrlScheme));
-
- // Before a user interaction triggers elision, a browser-initiated navigation
- // should show the full URL (minus scheme and trivial subdomain) throughout
- // the navigation.
-
- // Set a longer URL to ensure that the full URL stays visible even if it's
- // longer than the previous URL.
- static constexpr base::StringPiece16 kUrlSuffix = u"/foobar";
- UpdateDisplayURL(base::StrCat({kSimplifiedDomainDisplayUrl, kUrlSuffix}));
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size() + kUrlSuffix.size())));
-
- {
- // In this test, we create MockNavigationHandles here instead of using the
- // NavigateAndExpect* helpers because those helpers simulate
- // renderer-initiated navigations, where the display URL isn't updated until
- // just before DidFinishNavigation.
- content::MockNavigationHandle navigation;
- navigation.set_is_renderer_initiated(false);
-
- omnibox_view()->DidStartNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size() + kUrlSuffix.size())));
-
- omnibox_view()->DidFinishNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size() + kUrlSuffix.size())));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
- }
-
- // Simulate a user interaction and advance all the way through the animation
- // until the URL is elided to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- base::StrCat({kSimplifiedDomainDisplayUrlPath, kUrlSuffix}),
- ShouldElideToRegistrableDomain()));
-
- // Begin simulating a browser-initiated navigation, in which the URL is
- // updated before DidStartNavigation() runs.
- UpdateDisplayURL(base::StrCat({kSimplifiedDomainDisplayUrl, kUrlSuffix}));
- // Ideally we would actually be unelided at this point, when a
- // browser-initiated navigation has begun. But EmphasizeURLComponents()
- // doesn't know which type of navigation is in progress, so this is the best
- // we can do.
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- base::StrCat({kSimplifiedDomainDisplayUrlPath, kUrlSuffix}),
- ShouldElideToRegistrableDomain()));
- {
- content::MockNavigationHandle navigation;
- navigation.set_is_renderer_initiated(false);
-
- // Once the navigation starts and we know that it's a cross-document
- // navigation, the URL should be unelided.
- omnibox_view()->DidStartNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size() + kUrlSuffix.size())));
-
- omnibox_view()->DidFinishNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size() + kUrlSuffix.size())));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
- }
-}
-
-// Tests that the hide-on-interaction simplified domain field trial handles
-// non-committed navigations properly.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- NonCommittedNavigations) {
- SetUpSimplifiedDomainTest();
-
- ASSERT_NO_FATAL_FAILURE(omnibox_view()->NavigateAndExpectUnelided(
- kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(), kSimplifiedDomainDisplayUrlScheme));
- // Simulate a user interaction to elide the URL.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // When a renderer-initiated navigation finishes without committing, the URL
- // should remain elided; we don't update the display URL until the navigation
- // commits.
- {
- content::MockNavigationHandle navigation;
- navigation.set_is_renderer_initiated(true);
- navigation.set_has_committed(false);
- omnibox_view()->DidStartNavigation(&navigation);
- omnibox_view()->DidFinishNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
- }
-
- // When a browser-initiated navigation finishes without committing, the URL
- // updates before commit, so we should reset back to the on-page-load state if
- // the navigation doesn't eventually commit.
- content::MockNavigationHandle navigation;
- navigation.set_is_renderer_initiated(false);
- navigation.set_has_committed(false);
- omnibox_view()->DidStartNavigation(&navigation);
- omnibox_view()->DidFinishNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
-}
-
-// Tests that mouse clicks do not count as user interactions and do not elide
-// the URL.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest, MouseClick) {
- SetUpSimplifiedDomainTest();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a mouse click and check that the fade-out animation does not run.
- blink::WebMouseEvent event;
- event.SetType(blink::WebInputEvent::Type::kMouseDown);
- omnibox_view()->DidGetUserInteraction(event);
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-}
-
-// Tests that focusing an editable node does count as a user interaction and
-// elides the URL.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- FocusingEditableNode) {
- SetUpSimplifiedDomainTest();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Focusing a non-editable node should not run the fade-out animation.
- content::FocusedNodeDetails details;
- details.is_editable_node = false;
- details.focus_type = blink::mojom::FocusType::kMouse;
- omnibox_view()->OnFocusChangedInPage(&details);
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-
- // Focusing via keypress should not run the fade-out animation.
- details.is_editable_node = true;
- details.focus_type = blink::mojom::FocusType::kForward;
- omnibox_view()->OnFocusChangedInPage(&details);
- elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-
- // Other ways that an element can be focused, such as element.focus() in
- // JavaScript, have a focus type of kNone and should not run the fade-out
- // animation.
- details.is_editable_node = true;
- details.focus_type = blink::mojom::FocusType::kNone;
- omnibox_view()->OnFocusChangedInPage(&details);
- elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-
- // Focusing an editable node should run the fade-out animation.
- details.is_editable_node = true;
- details.focus_type = blink::mojom::FocusType::kMouse;
- omnibox_view()->OnFocusChangedInPage(&details);
- elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
-}
-
-// Tests that simplified domain elisions are re-applied when the omnibox's
-// bounds change.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest, BoundsChanged) {
- SetUpSimplifiedDomainTest();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // After the bounds change, the URL should remain unelided.
- omnibox_view()->OnBoundsChanged(gfx::Rect());
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
-
- // Hover over the omnibox and change the bounds during the animation. The
- // animation should be cancelled and immediately transition back to the
- // unelided URL.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* unelide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(unelide_animation);
- EXPECT_TRUE(unelide_animation->IsAnimating());
- omnibox_view()->OnBoundsChanged(gfx::Rect());
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
-
- // Simulate a user interaction and change the bounds during the animation. The
- // animation should be cancelled and immediately transition to the animation's
- // end state (simplified domain).
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
- omnibox_view()->OnBoundsChanged(gfx::Rect());
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-}
-
-// Tests that simplified domain elisions are re-applied when the omnibox's
-// bounds change when only reveal-on-hover is enabled.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, BoundsChanged) {
- SetUpSimplifiedDomainTest();
-
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // After the bounds change, the URL should remain elided.
- omnibox_view()->OnBoundsChanged(gfx::Rect());
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // Hover over the omnibox and change the bounds during the animation. The
- // animation should be cancelled and immediately transition back to the
- // simplified domain.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* unelide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(unelide_animation);
- EXPECT_TRUE(unelide_animation->IsAnimating());
- omnibox_view()->OnBoundsChanged(gfx::Rect());
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-}
-
-// Tests that simplified domain hover duration histogram is recorded correctly.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, HoverHistogram) {
- base::SimpleTestClock clock;
- constexpr int kHoverTimeMs = 1000;
- SetUpSimplifiedDomainTest();
- clock.SetNow(base::Time::Now());
- omnibox_view()->clock_ = &clock;
-
- // Hover over the omnibox and then exit and check that the histogram is
- // recorded correctly.
- {
- base::HistogramTester histograms;
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* unelide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(unelide_animation);
- EXPECT_TRUE(unelide_animation->IsAnimating());
- clock.Advance(base::TimeDelta::FromMilliseconds(kHoverTimeMs / 2));
- // Call OnMouseMoved() again halfway through the hover time to ensure that
- // the histogram is only recorded once per continuous hover.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- clock.Advance(base::TimeDelta::FromMilliseconds(kHoverTimeMs / 2));
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- auto samples = histograms.GetAllSamples("Omnibox.HoverTime");
- ASSERT_EQ(1u, samples.size());
- histograms.ExpectTimeBucketCount(
- "Omnibox.HoverTime", base::TimeDelta::FromMilliseconds(kHoverTimeMs),
- 1);
-
- // Focusing the omnibox while not hovering should not record another sample.
- omnibox_view()->OnFocus();
- samples = histograms.GetAllSamples("Omnibox.HoverTime");
- ASSERT_EQ(1u, samples.size());
- }
-
- // Hover over the omnibox and then focus it, and check that the histogram is
- // recorded correctly.
- {
- base::HistogramTester histograms;
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* unelide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(unelide_animation);
- EXPECT_TRUE(unelide_animation->IsAnimating());
- clock.Advance(base::TimeDelta::FromMilliseconds(kHoverTimeMs));
- omnibox_view()->OnFocus();
- auto samples = histograms.GetAllSamples("Omnibox.HoverTime");
- ASSERT_EQ(1u, samples.size());
- histograms.ExpectTimeBucketCount(
- "Omnibox.HoverTime", base::TimeDelta::FromMilliseconds(kHoverTimeMs),
- 1);
-
- // Moving the mouse, focusing again, and exiting from the omnibox after
- // focusing it should not record any more samples.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- omnibox_view()->OnFocus();
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- samples = histograms.GetAllSamples("Omnibox.HoverTime");
- ASSERT_EQ(1u, samples.size());
-
- // Hovering and exiting again should record another sample.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- samples = histograms.GetAllSamples("Omnibox.HoverTime");
- ASSERT_EQ(2u, samples.size());
- }
-
- // Hovering over the omnibox while focused should not record a histogram,
- // because no elide animation happens while focused.
- {
- base::HistogramTester histograms;
- omnibox_view()->RequestFocus();
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* unelide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(unelide_animation);
- EXPECT_FALSE(unelide_animation->IsAnimating());
- clock.Advance(base::TimeDelta::FromMilliseconds(kHoverTimeMs));
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- auto samples = histograms.GetAllSamples("Omnibox.HoverTime");
- ASSERT_EQ(0u, samples.size());
- }
-}
-
-// Tests that the simplified domain animation doesn't crash when it's cancelled.
-// Regression test for https://crbug.com/1103738.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, CancellingAnimationDoesNotCrash) {
- SetUpSimplifiedDomainTest();
-
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // Hover over the omnibox to begin the unelision animation, then change the
- // URL such that the current animation would go out of bounds if it continued
- // running.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- // Step through the animation partially so that it has a nonzero current
- // value. (A zero current value causes an early return that circumvents the
- // crash we are regression-testing.)
- ASSERT_NO_FATAL_FAILURE(omnibox_view()->StepSimplifiedDomainHoverAnimation(
- OmniboxFieldTrial::UnelideURLOnHoverThresholdMs() + 1));
-
- // Stopping the animation after changing the underlying display text should
- // not crash.
- UpdateDisplayURL(u"https://foo.test");
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting()->Stop();
-}
-
-// Tests scheme and trivial subdomain elision when simplified domain field
-// trials are enabled.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- SchemeAndTrivialSubdomainElision) {
- // Use custom setup code instead of SetUpSimplifiedDomainTest() to use a URL
- // with a "www." prefix (a trivial subdomain).
- static constexpr base::StringPiece16 kFullUrl =
- u"https://www.example.test/foo";
- constexpr size_t kSchemeAndSubdomainSize = 12; // "https://www."
- UpdateDisplayURL(kFullUrl);
- omnibox_view()->OnThemeChanged();
-
- omnibox_view()->NavigateAndExpectUnelided(kFullUrl,
- /*is_same_document=*/false, GURL(),
- u"htpts://www.");
- EXPECT_EQ(SK_ColorTRANSPARENT, omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, kSchemeAndSubdomainSize)));
-
- // Hovering before user interaction should bring back the scheme and trivial
- // subdomain.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(), gfx::Range(0, kFullUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT, omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, kSchemeAndSubdomainSize)));
-
- // After mousing out, the scheme should fade out again.
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSchemeAndSubdomainSize, kSimplifiedDomainDisplayUrl.size())));
- EXPECT_EQ(SK_ColorTRANSPARENT, omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, kSchemeAndSubdomainSize)));
-
- // Simulate a user interaction and check that the URL gets elided to the
- // simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- // Use should_elide_to_registrable_domain=true here regardless of how the
- // field trial is set because the "www." should be elided as a trivial
- // subdomain.
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), u"https://", u"www.", u"https://www.example.test",
- u"/foo",
- /* should_elide_to_registrable_domain=*/true));
-
- // Do another hover and check that the URL gets unelided to the full URL.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(), gfx::Range(0, kFullUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT, omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, kSchemeAndSubdomainSize)));
-
- // And after another mouse exit, the URL should go back to the simplified
- // domain.
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), u"https://", u"www.", u"https://www.example.test",
- u"/foo",
- /* should_elide_to_registrable_domain=*/true));
- EXPECT_EQ(SK_ColorTRANSPARENT, omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, kSchemeAndSubdomainSize)));
-}
-
-class OmniboxViewViewsHideOnInteractionTest
- : public OmniboxViewViewsTest,
- public ::testing::WithParamInterface<std::pair<bool, bool>> {
- public:
- OmniboxViewViewsHideOnInteractionTest()
- : OmniboxViewViewsTest(
- GetParam().first
- ? std::vector<FeatureAndParams>(
- {{omnibox::
- kHideSteadyStateUrlPathQueryAndRefOnInteraction,
- {}},
- {omnibox::kMaybeElideToRegistrableDomain,
- // Ensure all domains are elidable by policy.
- {{"max_unelided_host_length", "0"}}}})
- : std::vector<FeatureAndParams>(
- {{omnibox::
- kHideSteadyStateUrlPathQueryAndRefOnInteraction,
- {}}}),
- {},
- GetParam().second) {
- // The lookalike allowlist is used by the registrable-domain-elision code.
- reputation::InitializeBlankLookalikeAllowlistForTesting();
- }
-
- OmniboxViewViewsHideOnInteractionTest(
- const OmniboxViewViewsHideOnInteractionTest&) = delete;
- OmniboxViewViewsHideOnInteractionTest& operator=(
- const OmniboxViewViewsHideOnInteractionTest&) = delete;
-
- protected:
- bool ShouldElideToRegistrableDomain() { return GetParam().first; }
-};
-
-INSTANTIATE_TEST_SUITE_P(OmniboxViewViewsHideOnInteractionTest,
- OmniboxViewViewsHideOnInteractionTest,
- ::testing::ValuesIn({std::make_pair(true, false),
- std::make_pair(false, false),
- std::make_pair(true, true),
- std::make_pair(false, true)}));
-
-// Tests the the "Always Show Full URLs" option works with the field trial
-// variation that shows a simplified domain when the user interacts with the
-// page.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, AlwaysShowFullURLs) {
- // This test does setup itself and doesn't call SetUpSimplifiedDomainTest()
- // because SetUpSimplifiedDomainTest() uses a URL with a foo.example.test
- // hostname, and in this test we want to use a "www." subdomain to test that
- // the URL is displayed properly when trivial subdomain elision is disabled.
- static constexpr base::StringPiece16 kFullUrl =
- u"https://www.example.test/foo";
- UpdateDisplayURL(kFullUrl);
- omnibox_view()->OnThemeChanged();
-
- // Enable the "Always show full URLs" setting.
- location_bar_model()->set_should_prevent_elision(true);
- omnibox_view()->OnShouldPreventElisionChanged();
- std::unique_ptr<content::WebContents> web_contents =
- content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
- omnibox_view()->OnTabChanged(web_contents.get());
- EXPECT_EQ(kFullUrl, omnibox_view()->GetText());
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(), gfx::Range(0, kFullUrl.size())));
-
- // When the Always Show Full URLs pref is enabled, the omnibox view won't
- // observe user interactions and elide the URL.
- EXPECT_FALSE(omnibox_view()->web_contents());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-}
-
-// Tests the the "Always Show Full URLs" option works with the field trial
-// variation that shows a simplified domain until the user hovers over the
-// omnibox.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, AlwaysShowFullURLs) {
- SetUpSimplifiedDomainTest();
-
- // Enable the "Always show full URLs" setting.
- location_bar_model()->set_should_prevent_elision(true);
- omnibox_view()->OnShouldPreventElisionChanged();
-
- // After a hover, there should be no animations running.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- EXPECT_FALSE(elide_animation);
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- elide_animation = omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-}
-
-// This test fixture enables the reveal-on-hover simplified domain field trial,
-// and the hide-on-interaction variation when the parameter is true.
-class OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest
- : public OmniboxViewViewsTest,
- public ::testing::WithParamInterface<std::pair<bool, bool>> {
- public:
- OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest()
- : OmniboxViewViewsTest(
- GetParam().first
- ? std::vector<FeatureAndParams>(
- {{omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- {}},
- {omnibox::
- kHideSteadyStateUrlPathQueryAndRefOnInteraction,
- {}}})
- : std::vector<FeatureAndParams>(
- {{omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- {}}}),
- {omnibox::kMaybeElideToRegistrableDomain},
- GetParam().second) {}
-
- OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest(
- const OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest&) =
- delete;
- OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest& operator=(
- const OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest&) =
- delete;
-
- protected:
- bool IsHideOnInteractionEnabled() { return GetParam().first; }
-};
-
-INSTANTIATE_TEST_SUITE_P(
- OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest,
- OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest,
- ::testing::ValuesIn({std::make_pair(true, false),
- std::make_pair(false, false),
- std::make_pair(true, true),
- std::make_pair(false, true)}));
-
-// Tests that unsetting the "Always show full URLs" option begins showing/hiding
-// the full URL appropriately when simplified domain field trials are enabled.
-// This test has kMaybeElideToRegistrableDomain disabled so that we can check
-// that www is elided when the option is unset but other subdomains are not.
-TEST_P(OmniboxViewViewsRevealOnHoverAndMaybeHideOnInteractionTest,
- UnsetAlwaysShowFullURLs) {
- // This test does setup itself and doesn't call SetUpSimplifiedDomainTest()
- // because SetUpSimplifiedDomainTest() uses a URL with a foo.example.test
- // hostname, and in this test we want to use a "www." subdomain to test that
- // the URL is displayed properly when trivial subdomain elision is disabled.
- static constexpr base::StringPiece16 kFullUrl =
- u"https://www.example.test/foo";
- UpdateDisplayURL(kFullUrl);
- omnibox_view()->OnThemeChanged();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
-
- // Enable the "Always show full URLs" setting.
- location_bar_model()->set_should_prevent_elision(true);
- omnibox_view()->OnShouldPreventElisionChanged();
- std::unique_ptr<content::WebContents> web_contents =
- content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
- omnibox_view()->OnTabChanged(web_contents.get());
- EXPECT_EQ(u"https://www.example.test/foo", omnibox_view()->GetText());
-
- // Now toggle the preference and check that the animations run as expected.
- location_bar_model()->set_should_prevent_elision(false);
- location_bar_model()->set_url_for_display(u"https://www.example.test/foo");
- omnibox_view()->OnShouldPreventElisionChanged();
- // When simplified domain field trials are enabled, LocationBarModelImpl
- // doesn't do any elision, leaving it all up to OmniboxViewViews, so the text
- // returned from LocationBarModelImpl is the same even though the preference
- // has changed.
- EXPECT_EQ(u"https://www.example.test/foo", omnibox_view()->GetText());
- if (IsHideOnInteractionEnabled()) {
- ExpectUnelidedFromSimplifiedDomain(
- render_text,
- gfx::Range(std::string("https://www.").size(), kFullUrl.size()));
- // Simulate a user interaction and check the fade-out animation.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
- } else {
- // Even though kMaybeElideToRegistrableDomain is disabled, we expect to be
- // elided to the registrable domain because the www subdomain is considered
- // trivial.
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), u"https://", u"www.", u"https://www.example.test",
- u"/foo", true /* should elide to registrable domain */));
- }
- // Simulate a hover event and check the elide/unelide animations. This
- // should happen the same regardless of whether hide-on-interaction is
- // enabled.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
-}
-
-// Tests that in the hide-on-interaction field trial, the omnibox is reset to
-// the local bounds on tab change when the new text is not eligible for
-// simplified domain elision.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- TabChangeWhenNotEligibleForEliding) {
- SetUpSimplifiedDomainTest();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction and advance through the animation to elide the
- // URL.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // Change the tab and set state such that the current text is not eligible for
- // simplified domain eliding (specifically, use an ftp:// URL; only http/https
- // URLs are eligible for eliding). The omnibox should take up the full local
- // bounds and be reset to tail-eliding behavior, just as if the above
- // simplified domain elision had not happened.
- UpdateDisplayURL(u"ftp://foo.example.test");
- std::unique_ptr<content::WebContents> web_contents =
- content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
- omnibox_view()->SaveStateToTab(web_contents.get());
- omnibox_view()->OnTabChanged(web_contents.get());
-
- EXPECT_EQ(gfx::ELIDE_TAIL, omnibox_view()->GetRenderText()->elide_behavior());
- EXPECT_EQ(u"ftp://foo.example.test",
- omnibox_view()->GetRenderText()->GetDisplayText());
-
- // Change the tab and simulate user input in progress. In this case, the
- // omnibox should take up the full local bounds but should not be reset to
- // tail-eliding behavior, because it should always be in NO_ELIDE mode when
- // editing.
- UpdateDisplayURL(kSimplifiedDomainDisplayUrl);
- omnibox_view()->Focus();
- omnibox_view()->model()->SetInputInProgress(true);
- std::unique_ptr<content::WebContents> web_contents2 =
- content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
- omnibox_view()->SaveStateToTab(web_contents2.get());
- omnibox_view()->OnTabChanged(web_contents2.get());
-
- EXPECT_EQ(gfx::NO_ELIDE, omnibox_view()->GetRenderText()->elide_behavior());
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
-}
-
-// Tests that in the simplified domain field trials, non-http/https and
-// localhost URLs are not elided.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, UrlsNotEligibleForEliding) {
- static constexpr base::StringPiece16 kTestCases[] = {
- // Various URLs that aren't eligible for simplified domain eliding.
- u"ftp://foo.bar.test/baz",
- u"javascript:alert(1)",
- u"data:text/html,hello",
- u"http://localhost:4000/foo",
- u"blob:https://example.test/",
- u"view-source:https://example.test/",
- u"filesystem:https://example.test/a",
- // A smoke test to check that the test code results in
- // the URL being elided properly when eligible.
- kSimplifiedDomainDisplayUrl,
- };
-
- for (const auto& test_case : kTestCases) {
- UpdateDisplayURL(test_case);
- omnibox_view()->OnThemeChanged();
-
- if (test_case == kSimplifiedDomainDisplayUrl) {
- // This case is the smoke test to check that the test setup does properly
- // elide URLs that are eligible for eliding.
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
- } else {
- EXPECT_EQ(gfx::ELIDE_TAIL,
- omnibox_view()->GetRenderText()->elide_behavior());
- EXPECT_EQ(test_case, omnibox_view()->GetRenderText()->GetDisplayText());
- EXPECT_EQ(0,
- omnibox_view()->GetRenderText()->GetUpdatedDisplayOffset().x());
- }
- }
-}
-
-// Tests that in the hide-on-interaction field trial, when the path changes
-// while being elided, the animation is stopped.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- PathChangeDuringAnimation) {
- SetUpSimplifiedDomainTest();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction and check that the fade-out animation runs.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_TRUE(elide_animation->IsAnimating());
-
- // Change the path and check that the animation is cancelled.
- UpdateDisplayURL(u"foo.example.test/bar#bar");
- omnibox_view()->model()->ResetDisplayTexts();
- omnibox_view()->RevertAll();
- EXPECT_FALSE(elide_animation->IsAnimating());
-}
-
-// Tests that vertical and horizontal positioning doesn't change when eliding
-// to/from simplified domain. Regression test for https://crbug.com/1101674.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- VerticalAndHorizontalPosition) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
-
- const gfx::Rect& original_display_rect = render_text->display_rect();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // After a navigation, the URL should not be elided to the simplified domain,
- // and the display rect (including vertical and horizontal position) should be
- // unchanged.
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
- EXPECT_EQ(original_display_rect, render_text->display_rect());
-
- // Simulate a user interaction to elide to simplified domain and advance
- // through the animation; the vertical position should still be unchanged, and
- // the text should still start at the some position (the same x value).
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- const gfx::Rect& elided_display_rect = render_text->display_rect();
- EXPECT_EQ(original_display_rect.y(), elided_display_rect.y());
- EXPECT_EQ(original_display_rect.height(), elided_display_rect.height());
- EXPECT_EQ(original_display_rect.x(), elided_display_rect.x());
-
- // Now hover over the omnibox to trigger an unelide and check that the display
- // rect (including vertical and horizontal position) is back to what it was
- // originally.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
- const gfx::Rect& unelided_display_rect = render_text->display_rect();
- EXPECT_EQ(original_display_rect, unelided_display_rect);
-}
-
-// Tests that modifier keys don't count as user interactions in the
-// hide-on-interaction field trial.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, ModifierKeys) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction with a modifier key and check that the elide
- // animation doesn't run.
- blink::WebKeyboardEvent event(
- blink::WebInputEvent::Type::kRawKeyDown,
- blink::WebInputEvent::kControlKey,
- blink::WebInputEvent::GetStaticTimeStampForTests());
- omnibox_view()->DidGetUserInteraction(event);
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
-}
-
-// Tests that in the hide-on-interaction field trial, the URL is unelided when
-// navigating to an error page.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, ErrorPageNavigation) {
- SetUpSimplifiedDomainTest();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
- // Simulate a user interaction to elide to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
-
- // Now simulate a navigation to an error page and check that the URL is
- // unelided.
- content::MockNavigationHandle navigation;
- navigation.set_url(GURL(kSimplifiedDomainDisplayUrl));
- navigation.set_is_error_page(true);
- omnibox_view()->DidStartNavigation(&navigation);
- omnibox_view()->DidFinishNavigation(&navigation);
- ExpectUnelidedFromSimplifiedDomain(
- omnibox_view()->GetRenderText(),
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size()));
-}
-
-// Tests that in the hide-on-interaction field trial, the URL is simplified on
-// cross-document main-frame navigations, but not on same-document navigations.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, SameDocNavigations) {
- SetUpSimplifiedDomainTest();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
- static constexpr base::StringPiece16 kUrlSuffix = u"/foobar";
-
- // On a same-document navigation before the URL has been simplified, the URL
- // should remain unsimplified after the navigation finishes.
-
- {
- // Set a longer URL to ensure that the full URL stays visible even if it's
- // longer than the previous URL.
- omnibox_view()->NavigateAndExpectUnelided(
- base::StrCat({kSimplifiedDomainDisplayUrl, kUrlSuffix}),
- /*is_same_document=*/true, GURL(), kSimplifiedDomainDisplayUrlScheme);
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
- }
-
- // Simulate a user interaction to elide to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
-
- // On a cross-document main-frame navigation, the unsimplified URL should
- // remain visible.
- {
- omnibox_view()->NavigateAndExpectUnelided(
- kSimplifiedDomainDisplayUrl, /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
- }
-
- // Simulate another user interaction to elide to the simplified domain, and
- // advance the clock all the way through the animation.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // On same-document main-frame fragment navigation, the URL should remain
- // elided to the simplified domain.
- {
- omnibox_view()->NavigateAndExpectElided(
- GURL(base::StrCat({kSimplifiedDomainDisplayUrl, u"#foobar"})),
- /*is_same_document=*/true, GURL(kSimplifiedDomainDisplayUrl),
- kSimplifiedDomainDisplayUrlScheme, kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- base::StrCat({kSimplifiedDomainDisplayUrlPath, u"#foobar"}),
- ShouldElideToRegistrableDomain());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_FALSE(elide_animation->IsAnimating());
- }
-
- // On same-document main-frame non-fragment navigation, the URL shouldn't
- // remain elided to the simplified domain.
- {
- omnibox_view()->NavigateAndExpectUnelided(
- base::StrCat({kSimplifiedDomainDisplayUrl, kUrlSuffix}),
- /*is_same_document=*/true, GURL(kSimplifiedDomainDisplayUrl),
- kSimplifiedDomainDisplayUrlScheme);
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_FALSE(elide_animation);
- }
-}
-
-// Tests that in the hide-on-interaction field trial, a same-document navigation
-// cancels a currently-running animation and goes straight to the end state
-// (elided to the simplified domain).
-TEST_P(OmniboxViewViewsHideOnInteractionTest,
- SameDocNavigationDuringAnimation) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- gfx::Range path_bounds(
- kSimplifiedDomainDisplayUrl.find(kSimplifiedDomainDisplayUrlPath),
- kSimplifiedDomainDisplayUrl.size());
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to begin animating to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
-
- // Advance the clock by 1ms until the full URL is no longer showing, but we
- // haven't finished eliding to the simplified domain yet. After a
- // same-document navigation, we check that the URL has gone straight to the
- // end state. In other words, a same-document navigation will cancel a
- // currently-running animation but should end up where the animation was
- // targeting.
- bool is_midway_through_elision = false;
- uint32_t step_ms = 1;
- while (!is_midway_through_elision) {
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(++step_ms));
- is_midway_through_elision = IsPartlyThroughSimplifiedDomainElision(
- render_text, kSimplifiedDomainDisplayUrl, path_bounds);
- }
-
- omnibox_view()->NavigateAndExpectElided(
- GURL(kSimplifiedDomainDisplayUrl),
- /*is_same_document=*/true, GURL(kSimplifiedDomainDisplayUrl),
- kSimplifiedDomainDisplayUrlScheme, kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain());
-
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_FALSE(elide_animation->IsAnimating());
-}
-
-// Tests that gradient mask is set correctly.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, GradientMask) {
- if (base::i18n::IsRTL()) {
- // TODO(crbug.com/1101472): Re-enable this test once gradient mask is
- // implemented for RTL UI.
- return;
- }
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to begin animating to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- // Advance the clock by 1ms until the full size gradient has been added.
- uint32_t step_ms = 1;
- int max_gradient_width = OmniboxViewViews::kSmoothingGradientMaxWidth - 1;
- while (omnibox_view()->elide_animation_smoothing_rect_right_.width() <
- max_gradient_width) {
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(++step_ms));
- }
- // If we are eliding from the left, the other side gradient should also be
- // full size at this point, otherwise it should be 0.
- if (ShouldElideToRegistrableDomain()) {
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(),
- max_gradient_width);
- } else {
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(), 0);
- }
-
- // Get a bounding box for the unelided section of the URL.
- std::vector<gfx::Range> ranges_surrounding_simplified_domain;
- gfx::Range simplified_range = omnibox_view()->GetSimplifiedDomainBounds(
- &ranges_surrounding_simplified_domain);
- gfx::Rect simplified_rect;
- for (auto rect : render_text->GetSubstringBounds(simplified_range)) {
- simplified_rect.Union(rect - render_text->GetLineOffset(0));
- }
-
- // Advance the animation until both gradients start shrinking.
- while (omnibox_view()->elide_animation_smoothing_rect_left_.width() ==
- max_gradient_width ||
- omnibox_view()->elide_animation_smoothing_rect_right_.width() ==
- max_gradient_width) {
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(++step_ms));
- }
- int offset = omnibox_view()
- ->GetElideAfterInteractionAnimationForTesting()
- ->GetCurrentOffsetForTesting();
- gfx::Rect display_rect = render_text->display_rect();
- // Check the expected size and positions for both gradients.
- EXPECT_TRUE(omnibox_view()->elide_animation_smoothing_rect_left_.width() ==
- simplified_rect.x() + offset - 1 ||
- omnibox_view()->elide_animation_smoothing_rect_left_.width() ==
- 0);
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.x(),
- display_rect.x());
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(),
- display_rect.right() - (simplified_rect.right() + offset) - 1);
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.x() - 1,
- simplified_rect.right() + offset);
-}
-
-// Tests that gradient mask is reset when animation is stopped.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, GradientMaskResetAfterStop) {
- if (base::i18n::IsRTL()) {
- // TODO(crbug.com/1101472): Re-enable this test once gradient mask is
- // implemented for RTL UI.
- return;
- }
- SetUpSimplifiedDomainTest();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to begin animating to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- // Advance animation so it sets the gradient mask, then stop it.
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- omnibox_view()->GetElideAfterInteractionAnimationForTesting()->Stop();
-
- // Both gradient mask rectangles should have a width of 0 once the animation
- // has stopped.
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(), 0);
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(), 0);
-}
-
-// Tests that in the hide-on-interaction field trial, a second user interaction
-// does not interfere with an animation that is currently running. This is
-// similar to SameDocNavigationDuringAnimation except that this test checks that
-// a second user interaction (rather than a same-doc navigation) lets the
-// animation proceed undisturbed.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, UserInteractionDuringAnimation) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- gfx::Range path_bounds(
- kSimplifiedDomainDisplayUrl.find(kSimplifiedDomainDisplayUrlPath),
- kSimplifiedDomainDisplayUrl.size());
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to begin animating to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
-
- // Advance the clock by 1ms until the full URL is no longer showing, but we
- // haven't finished eliding to the simplified domain yet. After a subsequent
- // user interaction, we check that the URL is still in the same state (midway
- // through elision) and that the animation is still running undisturbed. In
- // other words, a second user interaction shouldn't change anything when an
- // animation is in progress.
- bool is_midway_through_elision = false;
- uint32_t step_ms = 0;
- while (!is_midway_through_elision) {
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(++step_ms));
- is_midway_through_elision = IsPartlyThroughSimplifiedDomainElision(
- render_text, kSimplifiedDomainDisplayUrl, path_bounds);
- }
- double animation_value = omnibox_view()
- ->GetElideAfterInteractionAnimationForTesting()
- ->GetAnimationForTesting()
- ->GetCurrentValue();
-
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
- EXPECT_EQ(animation_value,
- elide_animation->GetAnimationForTesting()->GetCurrentValue());
- // The current display text should reflect that the animation in progress: the
- // full display URL shouldn't be still visible, but we haven't necessarily
- // reached the end state (just the simplified domain visible) yet.
- EXPECT_TRUE(IsPartlyThroughSimplifiedDomainElision(
- render_text, kSimplifiedDomainDisplayUrl, path_bounds));
-}
-
-// Tests that in the hide-on-interaction field trial, the path is not re-shown
-// on subframe navigations.
-TEST_P(OmniboxViewViewsHideOnInteractionTest, SubframeNavigations) {
- SetUpSimplifiedDomainTest();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to elide to the simplified domain, and advance
- // the clock all the way through the animation.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // On a subframe navigation, the URL should remain elided to a simplified
- // domain.
- {
- content::MockNavigationHandle navigation;
- navigation.set_is_same_document(false);
- std::unique_ptr<content::WebContents> web_contents =
- content::WebContentsTester::CreateTestWebContents(profile(), nullptr);
- content::RenderFrameHostTester::For(web_contents->GetMainFrame())
- ->InitializeRenderFrameIfNeeded();
- content::RenderFrameHost* subframe =
- content::RenderFrameHostTester::For(web_contents->GetMainFrame())
- ->AppendChild("subframe");
- navigation.set_render_frame_host(subframe);
- omnibox_view()->DidStartNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
- omnibox_view()->DidFinishNavigation(&navigation);
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
- }
-}
-
-// Tests that in the reveal-on-hover field trial variation, domains are aligned
-// to the right (truncated from the left) if the omnibox is too narrow to fit
-// the whole domain.
-TEST_P(OmniboxViewViewsRevealOnHoverTest,
- SimplifiedDomainElisionWithNarrowOmnibox) {
- const int kOmniboxWidth = 60;
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- gfx::Rect current_bounds = omnibox_view()->GetLocalBounds();
- gfx::Rect bounds(current_bounds.x(), current_bounds.y(), kOmniboxWidth,
- current_bounds.height());
- omnibox_view()->SetBoundsRect(bounds);
- SetUpSimplifiedDomainTest();
-
- ASSERT_EQ(kSimplifiedDomainDisplayUrl, render_text->GetDisplayText());
-
- // The omnibox should contain a substring of the domain, aligned to the right.
- gfx::Rect hostname_bounds;
- for (const auto& rect : render_text->GetSubstringBounds(
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrlHostnameAndScheme.size()))) {
- hostname_bounds.Union(rect);
- }
- EXPECT_LT(hostname_bounds.x(), omnibox_view()->GetLocalBounds().x());
- EXPECT_FALSE(omnibox_view()->GetLocalBounds().Contains(hostname_bounds));
-
- // No hover animations should run when the omnibox is too narrow to fit the
- // simplified domain.
-
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_FALSE(elide_animation->IsAnimating());
-
- omnibox_view()->OnMouseExited(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- elide_animation = omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_FALSE(elide_animation->IsAnimating());
-}
-
-// Tests that in the reveal-on-hover and hide-on-interaction field trial
-// variation, domains are aligned to the right (truncated from the left) if the
-// omnibox is too narrow to fit the whole domain.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- SimplifiedDomainElisionWithNarrowOmnibox) {
- const int kOmniboxWidth = 60;
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- gfx::Rect current_bounds = omnibox_view()->GetLocalBounds();
- gfx::Rect bounds(current_bounds.x(), current_bounds.y(), kOmniboxWidth,
- current_bounds.height());
- omnibox_view()->SetBoundsRect(bounds);
- SetUpSimplifiedDomainTest();
-
- content::MockNavigationHandle navigation;
- navigation.set_is_same_document(false);
- omnibox_view()->DidFinishNavigation(&navigation);
-
- ASSERT_EQ(kSimplifiedDomainDisplayUrl, render_text->GetDisplayText());
-
- // The omnibox should contain a substring of the domain, aligned to the right.
- gfx::Rect hostname_bounds;
- for (const auto& rect : render_text->GetSubstringBounds(
- gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrlHostnameAndScheme.size()))) {
- hostname_bounds.Union(rect);
- }
- EXPECT_LT(hostname_bounds.x(), omnibox_view()->GetLocalBounds().x());
- EXPECT_FALSE(omnibox_view()->GetLocalBounds().Contains(hostname_bounds));
-}
-
-// Tests that in the hide-on-interaction field trial variation, the path is
-// faded out after omnibox focus and blur.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- HideOnInteractionAfterFocusAndBlur) {
- SetUpSimplifiedDomainTest();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
-
- // Simulate a user interaction to fade out the path.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // After focus, the URL should be fully unelided.
- omnibox_view()->OnFocus();
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, omnibox_view()->GetText().size())));
- EXPECT_EQ(gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrlHostnameAndScheme.size()),
- omnibox_view()->emphasis_range());
-
- // After blur, the URL should return to the same state as page load: only
- // scheme and trivial subdomains elided.
- omnibox_view()->OnBlur();
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
- EXPECT_NE(SK_ColorTRANSPARENT,
- omnibox_view()->GetLatestColorForRange(
- gfx::Range(0, omnibox_view()->GetText().size())));
- EXPECT_EQ(gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrlHostnameAndScheme.size()),
- omnibox_view()->emphasis_range());
-
- // After a post-blur user interaction, the URL should animate to the
- // simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetElideAfterInteractionAnimationForTesting();
- EXPECT_TRUE(elide_animation->IsAnimating());
-}
-
-// Tests that in the hide-on-interaction field trial variation, the URL is
-// aligned as appropriate for LTR and RTL UIs during the different stages
-// of elision.
-// Regression test for crbug.com/1114332
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- URLPositionWithHideOnInteraction) {
- SetUpSimplifiedDomainTest();
- gfx::RenderText* render_text = omnibox_view()->GetRenderText();
- // Initially the display rect of the render text matches the omnibox bounds,
- // store a copy of it.
- gfx::Rect omnibox_bounds(render_text->display_rect());
-
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to fade out the path.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
-
- // Check the URL is right aligned if the UI is RTL, or left aligned if it is
- // LTR.
- if (base::i18n::IsRTL()) {
- EXPECT_EQ(render_text->display_rect().x(),
- omnibox_bounds.right() - render_text->display_rect().width());
- } else {
- EXPECT_EQ(render_text->display_rect().x(), omnibox_bounds.x());
- }
-
- // Call OnFocus to trigger unelision.
- omnibox_view()->OnFocus();
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(0, kSimplifiedDomainDisplayUrl.size())));
-
- // Check alignment again
- if (base::i18n::IsRTL()) {
- EXPECT_EQ(render_text->display_rect().x(),
- omnibox_bounds.right() - render_text->display_rect().width());
- } else {
- EXPECT_EQ(render_text->display_rect().x(), omnibox_bounds.x());
- }
-
- // Call OnBlur to return to the state on page load.
- omnibox_view()->OnBlur();
- ASSERT_NO_FATAL_FAILURE(ExpectUnelidedFromSimplifiedDomain(
- render_text, gfx::Range(kSimplifiedDomainDisplayUrlScheme.size(),
- kSimplifiedDomainDisplayUrl.size())));
-
- // Check alignment again
- if (base::i18n::IsRTL()) {
- EXPECT_EQ(render_text->display_rect().x(),
- omnibox_bounds.right() - render_text->display_rect().width());
- } else {
- EXPECT_EQ(render_text->display_rect().x(), omnibox_bounds.x());
- }
-}
-
-// Tests that the last gradient mask from a previous animation is no longer
-// visible when starting a new animation.
-TEST_P(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
- NoStaleGradientMask) {
- if (base::i18n::IsRTL()) {
- // TODO(crbug.com/1101472): Re-enable this test once gradient mask is
- // implemented for RTL UI.
- return;
- }
- SetUpSimplifiedDomainTest();
- omnibox_view()->NavigateAndExpectUnelided(kSimplifiedDomainDisplayUrl,
- /*is_same_document=*/false, GURL(),
- kSimplifiedDomainDisplayUrlScheme);
-
- // Simulate a user interaction to begin animating to the simplified domain.
- omnibox_view()->DidGetUserInteraction(blink::WebKeyboardEvent());
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainInteractionAnimation(
- /*step_ms=*/1000));
-
- // Hover over the omnibox to trigger unelide animation.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- ASSERT_NO_FATAL_FAILURE(
- omnibox_view()->StepSimplifiedDomainHoverAnimation(/*step_ms=*/1000));
-
- // Both gradient mask rectangles will be full sized at this point
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(),
- OmniboxViewViews::kSmoothingGradientMaxWidth - 1);
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(),
- OmniboxViewViews::kSmoothingGradientMaxWidth - 1);
-
- // Select the text in the omnibox, then click on the page, this will trigger
- // an elision with no animation.
- omnibox_view()->SelectAll(false);
- blink::WebMouseEvent event;
- event.SetType(blink::WebInputEvent::Type::kMouseDown);
- omnibox_view()->DidGetUserInteraction(event);
-
- // Hover over the omnibox to trigger the unelide animation.
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
-
- // Even though the unelide animation hasn't advanced, the gradient mask
- // rectangles should have been reset.
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_left_.width(), 0);
- EXPECT_EQ(omnibox_view()->elide_animation_smoothing_rect_right_.width(), 0);
-}
-
-// Tests that in the reveal-on-hover field trial variation (without
-// hide-on-interaction), the path is faded back in after focus, then blur, then
-// hover.
-// TODO(crbug.com/1115551): Test is flaky.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, DISABLED_AfterBlur) {
- SetUpSimplifiedDomainTest();
-
- // Focus and blur the omnibox, then hover over it. The URL should unelide.
- omnibox_view()->OnFocus();
- omnibox_view()->OnBlur();
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), kSimplifiedDomainDisplayUrlScheme,
- kSimplifiedDomainDisplayUrlSubdomain,
- kSimplifiedDomainDisplayUrlHostnameAndScheme,
- kSimplifiedDomainDisplayUrlPath, ShouldElideToRegistrableDomain()));
- omnibox_view()->OnMouseMoved(CreateMouseEvent(ui::ET_MOUSE_MOVED, {0, 0}));
- OmniboxViewViews::ElideAnimation* elide_animation =
- omnibox_view()->GetHoverElideOrUnelideAnimationForTesting();
- ASSERT_TRUE(elide_animation);
- EXPECT_TRUE(elide_animation->IsAnimating());
-}
-
-// Tests that registrable domain elision properly handles the case when the
-// registrable domain appears as a subdomain, e.g. test.com.test.com.
-TEST_P(OmniboxViewViewsRevealOnHoverTest, RegistrableDomainRepeated) {
- // This test only applies when the URL is elided to the registrable domain.
- if (!ShouldElideToRegistrableDomain())
- return;
-
- static constexpr base::StringPiece16 kRepeatedRegistrableDomainUrl =
- u"https://example.com.example.com/foo";
- gfx::Range registrable_domain_and_path_range(
- 20 /* "https://www.example.com." */,
- kRepeatedRegistrableDomainUrl.size());
-
- UpdateDisplayURL(kRepeatedRegistrableDomainUrl);
- // Call OnThemeChanged() to create the animations.
- omnibox_view()->OnThemeChanged();
-
- ASSERT_NO_FATAL_FAILURE(ExpectElidedToSimplifiedDomain(
- omnibox_view(), u"https://", u"example.com.",
- u"https://example.com.example.com", u"/foo",
- ShouldElideToRegistrableDomain()));
-
- // Check that the domain is elided up to the second instance of "example.com",
- // not the first.
- gfx::Rect registrable_domain_and_path;
- for (const auto& rect : omnibox_view()->GetRenderText()->GetSubstringBounds(
- registrable_domain_and_path_range)) {
- registrable_domain_and_path.Union(rect);
- }
- EXPECT_EQ(omnibox_view()->GetRenderText()->display_rect().x(),
- registrable_domain_and_path.x());
-}
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index 45b5075..1d4b9a33 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -5227,7 +5227,6 @@
"../browser/lookalikes/lookalike_url_navigation_throttle_unittest.cc",
"../browser/reputation/local_heuristics_unittest.cc",
"../browser/reputation/reputation_service_unittest.cc",
- "../browser/reputation/url_elision_policy_unittest.cc",
# Media remoting is not supported on Android for now.
"../browser/media/cast_remoting_connector_unittest.cc",
diff --git a/components/omnibox/browser/location_bar_model_impl.cc b/components/omnibox/browser/location_bar_model_impl.cc
index 0efffc14..1709f26 100644
--- a/components/omnibox/browser/location_bar_model_impl.cc
+++ b/components/omnibox/browser/location_bar_model_impl.cc
@@ -91,19 +91,6 @@
~url_formatter::kFormatUrlOmitHTTP;
}
- // Prevent scheme/trivial subdomain elision when simplified domain field
- // trials are enabled. In these field trials, OmniboxViewViews handles elision
- // of scheme and trivial subdomains because they are shown/hidden based on
- // user interactions with the omnibox.
- if (base::FeatureList::IsEnabled(
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover) ||
- base::FeatureList::IsEnabled(
- omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction)) {
- format_types &= ~url_formatter::kFormatUrlOmitHTTP;
- format_types &= ~url_formatter::kFormatUrlOmitHTTPS;
- format_types &= ~url_formatter::kFormatUrlOmitTrivialSubdomains;
- }
-
GURL url(GetURL());
#if defined(OS_IOS)
diff --git a/components/omnibox/browser/location_bar_model_impl_unittest.cc b/components/omnibox/browser/location_bar_model_impl_unittest.cc
index 06abaf8e..51b6a530 100644
--- a/components/omnibox/browser/location_bar_model_impl_unittest.cc
+++ b/components/omnibox/browser/location_bar_model_impl_unittest.cc
@@ -104,114 +104,6 @@
LocationBarModelImpl model_;
};
-// A test fixture that enables the
-// #omnibox-ui-reveal-steady-state-url-path-query-and-ref-on-hover field trial.
-class LocationBarModelImplRevealOnHoverTest : public LocationBarModelImplTest {
- public:
- LocationBarModelImplRevealOnHoverTest() = default;
- LocationBarModelImplRevealOnHoverTest(
- const LocationBarModelImplRevealOnHoverTest&) = delete;
- LocationBarModelImplRevealOnHoverTest& operator=(
- const LocationBarModelImplRevealOnHoverTest&) = delete;
-
- protected:
- // testing::Test:
- void SetUp() override {
- scoped_feature_list_.InitAndEnableFeature(
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover);
- LocationBarModelImplTest::SetUp();
- }
-
- private:
- base::test::ScopedFeatureList scoped_feature_list_;
-};
-
-// A test fixture that enables the
-// #omnibox-ui-hide-steady-state-url-path-query-and-ref-on-interaction field
-// trial.
-class LocationBarModelImplHideOnInteractionTest
- : public LocationBarModelImplTest {
- public:
- LocationBarModelImplHideOnInteractionTest() = default;
- LocationBarModelImplHideOnInteractionTest(
- const LocationBarModelImplHideOnInteractionTest&) = delete;
- LocationBarModelImplHideOnInteractionTest& operator=(
- const LocationBarModelImplHideOnInteractionTest&) = delete;
-
- protected:
- // testing::Test:
- void SetUp() override {
- scoped_feature_list_.InitAndEnableFeature(
- omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction);
- LocationBarModelImplTest::SetUp();
- }
-
- private:
- base::test::ScopedFeatureList scoped_feature_list_;
-};
-
-// Tests that in the
-// #omnibox-ui-reveal-steady-state-url-path-query-and-ref-on-hover, the display
-// URL does not elide scheme or trivial subdomains.
-TEST_F(LocationBarModelImplRevealOnHoverTest, DisplayUrl) {
- delegate()->SetURL(GURL("http://www.example.test/foo"));
-#if defined(OS_IOS)
- EXPECT_EQ(u"http://www.example.test/TestSuffix", model()->GetURLForDisplay());
-#else // #!defined(OS_IOS)
- EXPECT_EQ(u"http://www.example.test/foo/TestSuffix",
- model()->GetURLForDisplay());
-#endif // #!defined(OS_IOS)
- EXPECT_EQ(u"http://www.example.test/foo/TestSuffix",
- model()->GetFormattedFullURL());
-
- delegate()->SetURL(GURL("https://www.example.test/foo"));
-#if defined(OS_IOS)
- EXPECT_EQ(u"https://www.example.test/TestSuffix",
- model()->GetURLForDisplay());
-#else // #!defined(OS_IOS)
- EXPECT_EQ(u"https://www.example.test/foo/TestSuffix",
- model()->GetURLForDisplay());
-#endif // #!defined(OS_IOS)
- EXPECT_EQ(u"https://www.example.test/foo/TestSuffix",
- model()->GetFormattedFullURL());
-}
-
-// Tests that in the
-// #omnibox-ui-hide-steady-state-url-path-query-and-ref-on-interaction, the
-// display URL does not elide scheme or trivial subdomains.
-TEST_F(LocationBarModelImplHideOnInteractionTest, DisplayUrl) {
- delegate()->SetURL(GURL("http://www.example.test/foo"));
-#if defined(OS_IOS)
- EXPECT_EQ(u"http://www.example.test/TestSuffix", model()->GetURLForDisplay());
-#else // #!defined(OS_IOS)
- EXPECT_EQ(u"http://www.example.test/foo/TestSuffix",
- model()->GetURLForDisplay());
-#endif // #!defined(OS_IOS)
- EXPECT_EQ(u"http://www.example.test/foo/TestSuffix",
- model()->GetFormattedFullURL());
-
- delegate()->SetURL(GURL("https://www.example.test/foo"));
-#if defined(OS_IOS)
- EXPECT_EQ(u"https://www.example.test/TestSuffix",
- model()->GetURLForDisplay());
-#else // #!defined(OS_IOS)
- EXPECT_EQ(u"https://www.example.test/foo/TestSuffix",
- model()->GetURLForDisplay());
-#endif // #!defined(OS_IOS)
- EXPECT_EQ(u"https://www.example.test/foo/TestSuffix",
- model()->GetFormattedFullURL());
-}
-
-TEST_F(LocationBarModelImplTest,
- DisplayUrlAppliesFormattedStringWithEquivalentMeaning) {
- delegate()->SetURL(GURL("http://www.google.com/"));
-
- // Verify that both the full formatted URL and the display URL add the test
- // suffix.
- EXPECT_EQ(u"www.google.com/TestSuffix", model()->GetFormattedFullURL());
- EXPECT_EQ(u"google.com/TestSuffix", model()->GetURLForDisplay());
-}
-
TEST_F(LocationBarModelImplTest, FormatsReaderModeUrls) {
const GURL http_url("http://www.example.com/article.html");
// Get the real article's URL shown to the user.
diff --git a/components/omnibox/browser/omnibox_field_trial.cc b/components/omnibox/browser/omnibox_field_trial.cc
index dbe0c21..8c7d23d 100644
--- a/components/omnibox/browser/omnibox_field_trial.cc
+++ b/components/omnibox/browser/omnibox_field_trial.cc
@@ -700,28 +700,6 @@
return demote_mode;
}
-bool OmniboxFieldTrial::ShouldRevealPathQueryRefOnHover() {
- return base::FeatureList::IsEnabled(
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover);
-}
-
-bool OmniboxFieldTrial::ShouldHidePathQueryRefOnInteraction() {
- return base::FeatureList::IsEnabled(
- omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction);
-}
-
-bool OmniboxFieldTrial::ShouldMaybeElideToRegistrableDomain() {
- return base::FeatureList::IsEnabled(omnibox::kMaybeElideToRegistrableDomain);
-}
-
-int OmniboxFieldTrial::UnelideURLOnHoverThresholdMs() {
- const int kDefaultThresholdMs = 250;
- int threshold = base::GetFieldTrialParamByFeatureAsInt(
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover,
- kOmniboxUIUnelideURLOnHoverThresholdMsParam, kDefaultThresholdMs);
- return threshold < 0 ? kDefaultThresholdMs : threshold;
-}
-
bool OmniboxFieldTrial::ShouldDisableCGIParamMatching() {
return base::FeatureList::IsEnabled(omnibox::kDisableCGIParamMatching);
}
@@ -815,9 +793,6 @@
int OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 100;
-const char OmniboxFieldTrial::kOmniboxUIUnelideURLOnHoverThresholdMsParam[] =
- "OmniboxUIUnelideURLOnHoverThresholdMsdMs";
-
namespace OmniboxFieldTrial {
// Rich autocompletion.
diff --git a/components/omnibox/browser/omnibox_field_trial.h b/components/omnibox/browser/omnibox_field_trial.h
index 9531411..0bfc776f 100644
--- a/components/omnibox/browser/omnibox_field_trial.h
+++ b/components/omnibox/browser/omnibox_field_trial.h
@@ -391,14 +391,6 @@
// Function only works in non-incognito when server suggestions are available.
std::string OnDeviceHeadSuggestDemoteMode();
-// Experiment to hide components of the URL in the steady state.
-bool ShouldRevealPathQueryRefOnHover();
-bool ShouldHidePathQueryRefOnInteraction();
-// If true, the above two features elide subdomains beyond the registrable
-// domain, as well as the path, query, and ref.
-bool ShouldMaybeElideToRegistrableDomain();
-int UnelideURLOnHoverThresholdMs();
-
// Returns true if CGI parameter names should not be considered when scoring
// suggestions.
bool ShouldDisableCGIParamMatching();
diff --git a/components/omnibox/common/omnibox_features.cc b/components/omnibox/common/omnibox_features.cc
index 8d3d7da0..d58e681c 100644
--- a/components/omnibox/common/omnibox_features.cc
+++ b/components/omnibox/common/omnibox_features.cc
@@ -301,27 +301,6 @@
"OmniboxUpdatedConnectionSecurityIndicators",
base::FEATURE_DISABLED_BY_DEFAULT};
-// Feature used to reveal the path, query and ref from steady state URLs
-// on hover.
-const base::Feature kRevealSteadyStateUrlPathQueryAndRefOnHover{
- "OmniboxUIExperimentRevealSteadyStateUrlPathQueryAndRefOnHover",
- base::FEATURE_DISABLED_BY_DEFAULT};
-
-// Feature used to hide the path, query and ref from steady state URLs
-// on interaction with the page.
-const base::Feature kHideSteadyStateUrlPathQueryAndRefOnInteraction{
- "OmniboxUIExperimentHideSteadyStateUrlPathQueryAndRefOnInteraction",
- base::FEATURE_DISABLED_BY_DEFAULT};
-
-// Feature used to possibly elide not just the path, query, and ref from steady
-// state URLs, but also subdomains beyond the registrable domain, depending on
-// whether the hostname fails lookalike checks. Has no effect unless
-// kRevealSteadyStateUrlPathQueryAndRefOnHover and/or
-// kHideSteadyStateUrlPathQueryAndRefOnInteraction are enabled.
-const base::Feature kMaybeElideToRegistrableDomain{
- "OmniboxUIExperimentElideToRegistrableDomain",
- base::FEATURE_DISABLED_BY_DEFAULT};
-
// Feature used to default typed navigations to use HTTPS instead of HTTP.
// This only applies to navigations that don't have a scheme such as
// "example.com". Presently, typing "example.com" in a clean browsing profile
diff --git a/components/omnibox/common/omnibox_features.h b/components/omnibox/common/omnibox_features.h
index 36ae0d1..82b287395f 100644
--- a/components/omnibox/common/omnibox_features.h
+++ b/components/omnibox/common/omnibox_features.h
@@ -80,12 +80,6 @@
// Experiment to introduce new security indicators for HTTPS.
extern const base::Feature kUpdatedConnectionSecurityIndicators;
-// Path-hiding experiments - these hide the path and other URL components in
-// some circumstances in the steady-state omnibox.
-extern const base::Feature kRevealSteadyStateUrlPathQueryAndRefOnHover;
-extern const base::Feature kHideSteadyStateUrlPathQueryAndRefOnInteraction;
-extern const base::Feature kMaybeElideToRegistrableDomain;
-
// Navigation experiments.
extern const base::Feature kDefaultTypedNavigationsToHttps;
extern const char kDefaultTypedNavigationsToHttpsTimeoutParam[];
diff --git a/ios/chrome/browser/safe_browsing/chrome_password_protection_service.mm b/ios/chrome/browser/safe_browsing/chrome_password_protection_service.mm
index 5d145af..926f090 100644
--- a/ios/chrome/browser/safe_browsing/chrome_password_protection_service.mm
+++ b/ios/chrome/browser/safe_browsing/chrome_password_protection_service.mm
@@ -356,13 +356,6 @@
base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings));
experiment.set_delayed_warnings_mouse_clicks_enabled(
safe_browsing::kDelayedWarningsEnableMouseClicks.Get());
- // Actual URL display experiments:
- experiment.set_reveal_on_hover(base::FeatureList::IsEnabled(
- omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover));
- experiment.set_hide_on_interaction(base::FeatureList::IsEnabled(
- omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction));
- experiment.set_elide_to_registrable_domain(
- base::FeatureList::IsEnabled(omnibox::kMaybeElideToRegistrableDomain));
return experiment;
}
diff --git a/testing/variations/fieldtrial_testing_config.json b/testing/variations/fieldtrial_testing_config.json
index f52da4bd..c04c45a8 100644
--- a/testing/variations/fieldtrial_testing_config.json
+++ b/testing/variations/fieldtrial_testing_config.json
@@ -7276,31 +7276,6 @@
]
}
],
- "SimplifiedUrlDisplay": [
- {
- "platforms": [
- "chromeos",
- "chromeos_lacros",
- "linux",
- "mac",
- "windows"
- ],
- "experiments": [
- {
- "name": "AllDisplayExperimentsEnabled",
- "params": {
- "enable_keyword_elision": "false"
- },
- "enable_features": [
- "OmniboxUIExperimentElideToRegistrableDomain",
- "OmniboxUIExperimentHideSteadyStateUrlPathQueryAndRefOnInteraction",
- "OmniboxUIExperimentRevealSteadyStateUrlPathQueryAndRefOnHover",
- "SafeBrowsingDelayedWarnings"
- ]
- }
- ]
- }
- ],
"SimplifySignOutIOS": [
{
"platforms": [