summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/BUILD.gn1
-rw-r--r--chrome/browser/ui/DEPS1
-rw-r--r--chrome/browser/ui/cocoa/status_bubble_mac.mm6
-rw-r--r--chrome/browser/ui/content_settings/content_setting_bubble_model.cc9
-rw-r--r--chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc50
-rw-r--r--chrome/browser/ui/passwords/manage_passwords_view_utils.cc6
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc5
-rw-r--r--chrome/browser/ui/views/status_bubble_views.cc8
-rw-r--r--chrome/chrome_browser_ui.gypi6
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--components/BUILD.gn2
-rw-r--r--components/components.gyp1
-rw-r--r--components/components_tests.gyp5
-rw-r--r--components/secure_display.gypi28
-rw-r--r--components/secure_display/BUILD.gn29
-rw-r--r--components/secure_display/DEPS7
-rw-r--r--components/secure_display/OWNERS2
-rw-r--r--components/secure_display/elide_url.cc (renamed from chrome/browser/ui/elide_url.cc)70
-rw-r--r--components/secure_display/elide_url.h (renamed from chrome/browser/ui/elide_url.h)14
-rw-r--r--components/secure_display/elide_url_unittest.cc (renamed from chrome/browser/ui/elide_url_unittest.cc)208
20 files changed, 270 insertions, 189 deletions
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index 205bde3..aab970e 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -91,6 +91,7 @@ source_set("ui") {
"//chrome/installer/util",
"//components/autofill/content/browser:risk_proto",
"//components/power",
+ "//components/secure_display",
"//components/suggestions/proto",
"//device/nfc",
"//media",
diff --git a/chrome/browser/ui/DEPS b/chrome/browser/ui/DEPS
index 7972a50..e4df03b 100644
--- a/chrome/browser/ui/DEPS
+++ b/chrome/browser/ui/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+components/auto_login_parser",
"+components/favicon/core",
+ "+components/secure_display",
"-chrome/browser/ui/views",
]
diff --git a/chrome/browser/ui/cocoa/status_bubble_mac.mm b/chrome/browser/ui/cocoa/status_bubble_mac.mm
index 7f7c455..d7418d9 100644
--- a/chrome/browser/ui/cocoa/status_bubble_mac.mm
+++ b/chrome/browser/ui/cocoa/status_bubble_mac.mm
@@ -17,7 +17,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "chrome/browser/ui/cocoa/bubble_view.h"
-#include "chrome/browser/ui/elide_url.h"
+#include "components/secure_display/elide_url.h"
#include "net/base/net_util.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
@@ -237,7 +237,7 @@ void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) {
base::string16 original_url_text = net::FormatUrl(url, languages);
base::string16 status =
- ElideUrl(url, font_list_chr, text_width, languages);
+ secure_display::ElideUrl(url, font_list_chr, text_width, languages);
SetText(status, true);
@@ -706,7 +706,7 @@ void StatusBubbleMac::ExpandBubble() {
NSFont* font = [[window_ contentView] font];
gfx::FontList font_list_chr(
gfx::Font(gfx::PlatformFont::CreateFromNativeFont(font)));
- base::string16 expanded_url = ElideUrl(
+ base::string16 expanded_url = secure_display::ElideUrl(
url_, font_list_chr, max_bubble_width, languages_);
// Scale width from gfx::Font in view coordinates to window coordinates.
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
index 6f7dbb1..b16b668 100644
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
@@ -21,7 +21,6 @@
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h"
-#include "chrome/browser/ui/elide_url.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
@@ -30,6 +29,7 @@
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/content_settings.h"
+#include "components/secure_display/elide_url.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
@@ -275,7 +275,7 @@ bool ContentSettingSingleRadioGroup::settings_changed() const {
// content type and setting the default value based on the content setting.
void ContentSettingSingleRadioGroup::SetRadioGroup() {
GURL url = web_contents()->GetURL();
- base::string16 display_host = FormatUrlForSecurityDisplay(
+ base::string16 display_host = secure_display::FormatUrlForSecurityDisplay(
url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
if (display_host.empty())
display_host = base::ASCIIToUTF16(url.spec());
@@ -677,8 +677,9 @@ void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
RadioGroup radio_group;
radio_group.url = url;
- base::string16 display_host_utf16 = FormatUrlForSecurityDisplay(
- url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
+ base::string16 display_host_utf16 =
+ secure_display::FormatUrlForSecurityDisplay(
+ url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
std::string display_host(base::UTF16ToUTF8(display_host_utf16));
if (display_host.empty())
display_host = url.spec();
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc
index 943693c..e9b8d29 100644
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc
@@ -13,7 +13,6 @@
#include "chrome/browser/media/media_stream_capture_indicator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
-#include "chrome/browser/ui/elide_url.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
@@ -22,6 +21,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/infobars/core/infobar_delegate.h"
+#include "components/secure_display/elide_url.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -118,9 +118,9 @@ TEST_F(ContentSettingBubbleModelTest, Cookies) {
EXPECT_EQ(bubble_content_2.radio_group.radio_items[1],
l10n_util::GetStringFUTF8(
IDS_ALLOWED_COOKIES_BLOCK,
- FormatUrlForSecurityDisplay(web_contents()->GetURL(),
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ web_contents()->GetURL(), profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_FALSE(bubble_content_2.custom_link.empty());
EXPECT_TRUE(bubble_content_2.custom_link_enabled);
EXPECT_FALSE(bubble_content_2.manage_link.empty());
@@ -157,9 +157,9 @@ TEST_F(ContentSettingBubbleModelTest, MediastreamMicAndCamera) {
EXPECT_EQ(bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK));
@@ -542,9 +542,9 @@ TEST_F(ContentSettingBubbleModelTest, MediastreamMic) {
EXPECT_EQ(bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK));
@@ -576,9 +576,9 @@ TEST_F(ContentSettingBubbleModelTest, MediastreamMic) {
EXPECT_EQ(new_bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_BLOCKED_MEDIASTREAM_MIC_ASK,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(new_bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION));
@@ -621,9 +621,9 @@ TEST_F(ContentSettingBubbleModelTest, MediastreamCamera) {
EXPECT_EQ(bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK));
@@ -655,9 +655,9 @@ TEST_F(ContentSettingBubbleModelTest, MediastreamCamera) {
EXPECT_EQ(new_bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(new_bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION));
@@ -702,9 +702,9 @@ TEST_F(ContentSettingBubbleModelTest, AccumulateMediastreamMicAndCamera) {
EXPECT_EQ(bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK));
@@ -734,9 +734,9 @@ TEST_F(ContentSettingBubbleModelTest, AccumulateMediastreamMicAndCamera) {
EXPECT_EQ(new_bubble_content.radio_group.radio_items[0],
l10n_util::GetStringFUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION,
- FormatUrlForSecurityDisplay(security_origin,
- profile()->GetPrefs()->GetString(
- prefs::kAcceptLanguages))));
+ secure_display::FormatUrlForSecurityDisplay(
+ security_origin, profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages))));
EXPECT_EQ(new_bubble_content.radio_group.radio_items[1],
l10n_util::GetStringUTF8(
IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK));
diff --git a/chrome/browser/ui/passwords/manage_passwords_view_utils.cc b/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
index 02ea978..b2c50d2 100644
--- a/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
+++ b/chrome/browser/ui/passwords/manage_passwords_view_utils.cc
@@ -5,10 +5,10 @@
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/ui/elide_url.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/password_manager/core/browser/affiliation_utils.h"
+#include "components/secure_display/elide_url.h"
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "ui/base/l10n/l10n_util.h"
@@ -54,8 +54,8 @@ void GetSavePasswordDialogTitleTextAndLinkRange(
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
if (target_domain_differs) {
title_id = IDS_SAVE_PASSWORD_TITLE;
- replacements.push_back(
- FormatUrlForSecurityDisplay(form_origin_url, std::string()));
+ replacements.push_back(secure_display::FormatUrlForSecurityDisplay(
+ form_origin_url, std::string()));
}
if (is_smartlock_branding_enabled) {
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
index 450d448..e5336af 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -34,7 +34,6 @@
#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/chrome_pages.h"
-#include "chrome/browser/ui/elide_url.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
@@ -56,6 +55,7 @@
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
#include "components/metrics/metrics_service.h"
+#include "components/secure_display/elide_url.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/page_navigator.h"
@@ -721,7 +721,8 @@ base::string16 BookmarkBarView::CreateToolTipForURLAndTitle(
// default.
std::string languages = profile->GetPrefs()->GetString(
prefs::kAcceptLanguages);
- base::string16 elided_url(ElideUrl(url, tt_fonts, max_width, languages));
+ base::string16 elided_url(
+ secure_display::ElideUrl(url, tt_fonts, max_width, languages));
elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url);
result.append(elided_url);
}
diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc
index 2623edcb..92e4012 100644
--- a/chrome/browser/ui/views/status_bubble_views.cc
+++ b/chrome/browser/ui/views/status_bubble_views.cc
@@ -14,7 +14,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "chrome/browser/themes/theme_properties.h"
-#include "chrome/browser/ui/elide_url.h"
+#include "components/secure_display/elide_url.h"
#include "net/base/net_util.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkRect.h"
@@ -694,7 +694,8 @@ void StatusBubbleViews::SetURL(const GURL& url, const std::string& languages) {
gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
int text_width = static_cast<int>(popup_bounds.width() -
(kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1);
- url_text_ = ElideUrl(url, gfx::FontList(), text_width, languages);
+ url_text_ =
+ secure_display::ElideUrl(url, gfx::FontList(), text_width, languages);
// An URL is always treated as a left-to-right string. On right-to-left UIs
// we need to explicitly mark the URL as LTR to make sure it is displayed
@@ -857,7 +858,8 @@ void StatusBubbleViews::ExpandBubble() {
gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
int max_status_bubble_width = GetMaxStatusBubbleWidth();
const gfx::FontList font_list;
- url_text_ = ElideUrl(url_, font_list, max_status_bubble_width, languages_);
+ url_text_ = secure_display::ElideUrl(url_, font_list, max_status_bubble_width,
+ languages_);
int expanded_bubble_width =
std::max(GetStandardStatusBubbleWidth(),
std::min(gfx::GetStringWidth(url_text_, font_list) +
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index ab4a47d..0386fec 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -529,8 +529,6 @@
'browser/ui/android/infobars/generated_password_saved_infobar.h',
'browser/ui/auto_login_infobar_delegate.cc',
'browser/ui/auto_login_infobar_delegate.h',
- 'browser/ui/elide_url.cc',
- 'browser/ui/elide_url.h',
'browser/ui/screen_capture_notification_ui_stub.cc',
],
# Cross-platform ash sources.
@@ -1580,8 +1578,6 @@
'browser/ui/content_settings/content_setting_image_model.h',
'browser/ui/content_settings/content_setting_media_menu_model.cc',
'browser/ui/content_settings/content_setting_media_menu_model.h',
- 'browser/ui/elide_url.cc',
- 'browser/ui/elide_url.h',
'browser/ui/exclusive_access/exclusive_access_bubble.cc',
'browser/ui/exclusive_access/exclusive_access_bubble.h',
'browser/ui/exclusive_access/exclusive_access_bubble_type.cc',
@@ -2757,6 +2753,7 @@
'../components/components.gyp:omnibox_common',
'../components/components.gyp:onc_component',
'../components/components.gyp:password_manager_core_browser',
+ '../components/components.gyp:secure_display',
'../components/components.gyp:sync_driver',
'../components/components.gyp:ui_zoom',
'../components/components.gyp:update_client',
@@ -2813,6 +2810,7 @@
'installer_util',
'../components/components.gyp:app_modal',
'../components/components.gyp:autofill_content_risk_proto',
+ '../components/components.gyp:secure_display',
'../components/components.gyp:translate_content_common',
'../content/app/resources/content_resources.gyp:content_resources',
'../media/media.gyp:media',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index bdba72d..1508fa2 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1546,7 +1546,6 @@
'browser/ui/cocoa/autofill/new_credit_card_bubble_cocoa_unittest.mm',
'browser/ui/content_settings/content_setting_bubble_model_unittest.cc',
'browser/ui/content_settings/content_setting_image_model_unittest.cc',
- 'browser/ui/elide_url_unittest.cc', # URL elider not used on Android.
'browser/ui/exclusive_access/fullscreen_controller_state_unittest.cc',
'browser/ui/extensions/extension_action_view_controller_unittest.cc',
'browser/ui/omnibox/omnibox_controller_unittest.cc',
diff --git a/components/BUILD.gn b/components/BUILD.gn
index a869cf9..deb1cde 100644
--- a/components/BUILD.gn
+++ b/components/BUILD.gn
@@ -92,6 +92,7 @@ group("all_components") {
"//components/search",
"//components/search_engines",
"//components/search_provider_logos",
+ "//components/secure_display",
"//components/sessions",
"//components/signin/core/browser",
"//components/startup_metric_utils",
@@ -298,6 +299,7 @@ test("components_unittests") {
"//components/omnibox/browser:unit_tests",
"//components/packed_ct_ev_whitelist:unit_tests",
"//components/undo:unit_tests",
+ "//components/secure_display:unit_tests",
"//components/update_client:unit_tests",
"//components/variations:unit_tests",
"//components/webcrypto:unit_tests",
diff --git a/components/components.gyp b/components/components.gyp
index 43889d1..ff7bd7e0 100644
--- a/components/components.gyp
+++ b/components/components.gyp
@@ -62,6 +62,7 @@
'search.gypi',
'search_engines.gypi',
'search_provider_logos.gypi',
+ 'secure_display.gypi',
'sessions.gypi',
'signin.gypi',
'startup_metric_utils.gypi',
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index 75221d1..5bca9ae 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -540,6 +540,9 @@
'search_provider_logos/logo_cache_unittest.cc',
'search_provider_logos/logo_tracker_unittest.cc',
],
+ 'secure_display_unittest_sources': [
+ 'secure_display/elide_url_unittest.cc',
+ ],
'sessions_unittest_sources': [
'sessions/content/content_serialized_navigation_builder_unittest.cc',
'sessions/content/content_serialized_navigation_driver_unittest.cc',
@@ -747,6 +750,7 @@
'<@(search_unittest_sources)',
'<@(search_engines_unittest_sources)',
'<@(search_provider_logos_unittest_sources)',
+ '<@(secure_display_unittest_sources)',
'<@(sessions_unittest_sources)',
'<@(signin_unittest_sources)',
'<@(suggestions_unittest_sources)',
@@ -859,6 +863,7 @@
'components.gyp:search_engines',
'components.gyp:search_engines_test_support',
'components.gyp:search_provider_logos',
+ 'components.gyp:secure_display',
'components.gyp:sessions_test_support',
'components.gyp:signin_core_browser',
'components.gyp:signin_core_browser_test_support',
diff --git a/components/secure_display.gypi b/components/secure_display.gypi
new file mode 100644
index 0000000..8fe332d
--- /dev/null
+++ b/components/secure_display.gypi
@@ -0,0 +1,28 @@
+# Copyright (c) 2015 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.
+
+{
+ 'targets': [
+ {
+ # GN version: //components/secure_display
+ 'target_name': 'secure_display',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../net/net.gyp:net',
+ '../url/url.gyp:url_lib',
+ '../ui/gfx/gfx.gyp:gfx',
+ ],
+ 'defines': [
+ 'SECURE_DISPLAY_IMPLEMENTATION',
+ ],
+ 'sources': [
+ # Note: file list duplicated in GN build.
+ 'secure_display/elide_url.h',
+ 'secure_display/elide_url.cc',
+ ]
+ }
+ ]
+}
+
diff --git a/components/secure_display/BUILD.gn b/components/secure_display/BUILD.gn
new file mode 100644
index 0000000..5e7439d
--- /dev/null
+++ b/components/secure_display/BUILD.gn
@@ -0,0 +1,29 @@
+import("//testing/test.gni")
+
+source_set("secure_display") {
+ sources = [
+ "elide_url.cc",
+ "elide_url.h",
+ ]
+
+ deps = [
+ "//base:base",
+ "//net:net",
+ "//ui/gfx",
+ "//url",
+ ]
+}
+
+source_set("unit_tests") {
+ testonly = true
+ sources = [
+ "elide_url_unittest.cc",
+ ]
+
+ deps = [
+ ":secure_display",
+ "//base:base",
+ "//base/test:test_support",
+ "//testing/gtest",
+ ]
+}
diff --git a/components/secure_display/DEPS b/components/secure_display/DEPS
new file mode 100644
index 0000000..e378ef8
--- /dev/null
+++ b/components/secure_display/DEPS
@@ -0,0 +1,7 @@
+include_rules = [
+ "+base/",
+ "+base/strings",
+ "+net/base",
+ "+ui/gfx",
+ "+url/",
+]
diff --git a/components/secure_display/OWNERS b/components/secure_display/OWNERS
new file mode 100644
index 0000000..b0e35156c7
--- /dev/null
+++ b/components/secure_display/OWNERS
@@ -0,0 +1,2 @@
+felt@chromium.org
+palmer@chromium.org
diff --git a/chrome/browser/ui/elide_url.cc b/components/secure_display/elide_url.cc
index b5c7ca6..ec4d65a 100644
--- a/chrome/browser/ui/elide_url.cc
+++ b/components/secure_display/elide_url.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/elide_url.h"
+#include "components/secure_display/elide_url.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
@@ -23,6 +23,7 @@ using gfx::kForwardSlash;
namespace {
+#if !defined(OS_ANDROID)
const base::char16 kDot = '.';
// Build a path from the first |num_components| elements in |path_elements|.
@@ -61,8 +62,8 @@ base::string16 ElideComponentizedPath(
CHECK(url_path_number_of_elements);
for (size_t i = url_path_number_of_elements - 1; i > 0; --i) {
- base::string16 elided_path = BuildPathFromComponents(url_path_prefix,
- url_path_elements, url_filename, i);
+ base::string16 elided_path = BuildPathFromComponents(
+ url_path_prefix, url_path_elements, url_filename, i);
if (available_pixel_width >= GetStringWidthF(elided_path, font_list))
return ElideText(elided_path + url_query, font_list,
available_pixel_width, gfx::ELIDE_TAIL);
@@ -81,8 +82,8 @@ void SplitHost(const GURL& url,
*url_host = UTF8ToUTF16(url.host());
// Get domain and registry information from the URL.
- *url_domain = UTF8ToUTF16(
- net::registry_controlled_domains::GetDomainAndRegistry(
+ *url_domain =
+ UTF8ToUTF16(net::registry_controlled_domains::GetDomainAndRegistry(
url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES));
if (url_domain->empty())
*url_domain = *url_host;
@@ -99,13 +100,18 @@ void SplitHost(const GURL& url,
if (domain_start_index != base::string16::npos)
*url_subdomain = url_host->substr(0, domain_start_index);
if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() ||
- url.SchemeIsFile())) {
+ url.SchemeIsFile())) {
url_subdomain->clear();
}
}
+#endif // !defined(OS_ANDROID)
} // namespace
+namespace secure_display {
+
+#if !defined(OS_ANDROID)
+
// TODO(pkasting): http://crbug.com/77883 This whole function gets
// kerning/ligatures/etc. issues potentially wrong by assuming that the width of
// a rendered string is always the sum of the widths of its substrings. Also I
@@ -171,10 +177,9 @@ base::string16 ElideUrl(const GURL& url,
// Second Pass - remove scheme - the rest fits.
const float pixel_width_url_host = GetStringWidthF(url_host, font_list);
- const float pixel_width_url_path = GetStringWidthF(url_path_query_etc,
- font_list);
- if (available_pixel_width >=
- pixel_width_url_host + pixel_width_url_path)
+ const float pixel_width_url_path =
+ GetStringWidthF(url_path_query_etc, font_list);
+ if (available_pixel_width >= pixel_width_url_host + pixel_width_url_path)
return url_host + url_path_query_etc;
// Third Pass: Subdomain, domain and entire path fits.
@@ -182,14 +187,13 @@ base::string16 ElideUrl(const GURL& url,
const float pixel_width_url_subdomain =
GetStringWidthF(url_subdomain, font_list);
if (available_pixel_width >=
- pixel_width_url_subdomain + pixel_width_url_domain +
- pixel_width_url_path)
+ pixel_width_url_subdomain + pixel_width_url_domain + pixel_width_url_path)
return url_subdomain + url_domain + url_path_query_etc;
// Query element.
base::string16 url_query;
- const float kPixelWidthDotsTrailer = GetStringWidthF(
- base::string16(kEllipsisUTF16), font_list);
+ const float kPixelWidthDotsTrailer =
+ GetStringWidthF(base::string16(kEllipsisUTF16), font_list);
if (parsed.query.is_nonempty()) {
url_query = UTF8ToUTF16("?") + url_string.substr(parsed.query.begin);
if (available_pixel_width >=
@@ -201,9 +205,9 @@ base::string16 ElideUrl(const GURL& url,
}
// Parse url_path using '/'.
- std::vector<base::string16> url_path_elements = base::SplitString(
- url_path, base::string16(1, kForwardSlash),
- base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ std::vector<base::string16> url_path_elements =
+ base::SplitString(url_path, base::string16(1, kForwardSlash),
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// Get filename - note that for a path ending with /
// such as www.google.com/intl/ads/, the file name is ads/.
@@ -213,8 +217,8 @@ base::string16 ElideUrl(const GURL& url,
if (url_filename.empty() && (url_path_number_of_elements > 1)) {
// Path ends with a '/'.
--url_path_number_of_elements;
- url_filename = url_path_elements[url_path_number_of_elements - 1] +
- kForwardSlash;
+ url_filename =
+ url_path_elements[url_path_number_of_elements - 1] + kForwardSlash;
}
const size_t kMaxNumberOfUrlPathElementsAllowed = 1024;
@@ -233,10 +237,9 @@ base::string16 ElideUrl(const GURL& url,
GetStringWidthF(kEllipsisAndSlash, font_list);
// Check with both subdomain and domain.
- base::string16 elided_path =
- ElideComponentizedPath(url_subdomain + url_domain, url_path_elements,
- url_filename, url_query, font_list,
- available_pixel_width);
+ base::string16 elided_path = ElideComponentizedPath(
+ url_subdomain + url_domain, url_path_elements, url_filename, url_query,
+ font_list, available_pixel_width);
if (!elided_path.empty())
return elided_path;
@@ -262,15 +265,15 @@ base::string16 ElideUrl(const GURL& url,
// Return elided domain/.../filename anyway.
base::string16 final_elided_url_string(url_elided_domain);
- const float url_elided_domain_width = GetStringWidthF(url_elided_domain,
- font_list);
+ const float url_elided_domain_width =
+ GetStringWidthF(url_elided_domain, font_list);
// A hack to prevent trailing ".../...".
if ((available_pixel_width - url_elided_domain_width) >
pixel_width_ellipsis_slash + kPixelWidthDotsTrailer +
- GetStringWidthF(base::ASCIIToUTF16("UV"), font_list)) {
- final_elided_url_string += BuildPathFromComponents(base::string16(),
- url_path_elements, url_filename, 1);
+ GetStringWidthF(base::ASCIIToUTF16("UV"), font_list)) {
+ final_elided_url_string += BuildPathFromComponents(
+ base::string16(), url_path_elements, url_filename, 1);
} else {
final_elided_url_string += url_path;
}
@@ -299,11 +302,13 @@ base::string16 ElideHost(const GURL& url,
if (subdomain_width <= 0)
return base::string16(kEllipsisUTF16) + kDot + url_domain;
- const base::string16 elided_subdomain = ElideText(
- url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD);
+ const base::string16 elided_subdomain =
+ ElideText(url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD);
return elided_subdomain + url_domain;
}
+#endif // !defined(OS_ANDROID)
+
base::string16 FormatUrlForSecurityDisplay(const GURL& url,
const std::string& languages) {
if (!url.is_valid() || url.is_empty() || !url.IsStandard())
@@ -338,10 +343,11 @@ base::string16 FormatUrlForSecurityDisplay(const GURL& url,
result += base::UTF8ToUTF16(host);
const int port = origin.IntPort();
- const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(),
- origin.scheme().length());
+ const int default_port = url::DefaultPortForScheme(
+ scheme.c_str(), static_cast<int>(scheme.length()));
if (port != url::PORT_UNSPECIFIED && port != default_port)
result += colon + base::UTF8ToUTF16(origin.port());
return result;
}
+} // namespace secure_display
diff --git a/chrome/browser/ui/elide_url.h b/components/secure_display/elide_url.h
index b68267c..7d77b04 100644
--- a/chrome/browser/ui/elide_url.h
+++ b/components/secure_display/elide_url.h
@@ -4,8 +4,8 @@
//
// This file defines utility functions for eliding URLs.
-#ifndef CHROME_BROWSER_UI_ELIDE_URL_H_
-#define CHROME_BROWSER_UI_ELIDE_URL_H_
+#ifndef COMPONENTS_SECURE_DISPLAY_ELIDE_URL_H_
+#define COMPONENTS_SECURE_DISPLAY_ELIDE_URL_H_
#include <string>
@@ -17,6 +17,11 @@ namespace gfx {
class FontList;
}
+namespace secure_display {
+
+// ElideUrl and Elide host require
+// gfx::GetStringWidthF which is not implemented in Android
+#if !defined(OS_ANDROID)
// This function takes a GURL object and elides it. It returns a string
// which composed of parts from subdomain, domain, path, filename and query.
// A "..." is added automatically at the end if the elided string is bigger
@@ -44,6 +49,7 @@ base::string16 ElideUrl(const GURL& url,
base::string16 ElideHost(const GURL& host_url,
const gfx::FontList& font_list,
float available_pixel_width);
+#endif // !defined(OS_ANDROID)
// This is a convenience function for formatting a URL in a concise and
// human-friendly way, to help users make security-related decisions (or in
@@ -61,4 +67,6 @@ base::string16 ElideHost(const GURL& host_url,
base::string16 FormatUrlForSecurityDisplay(const GURL& origin,
const std::string& languages);
-#endif // CHROME_BROWSER_UI_ELIDE_URL_H_
+} // namespace secure_display
+
+#endif // COMPONENTS_SECURE_DISPLAY_ELIDE_URL_H_
diff --git a/chrome/browser/ui/elide_url_unittest.cc b/components/secure_display/elide_url_unittest.cc
index 312d8ed..cbd512c 100644
--- a/chrome/browser/ui/elide_url_unittest.cc
+++ b/components/secure_display/elide_url_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/elide_url.h"
+#include "components/secure_display/elide_url.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -22,6 +22,7 @@ struct Testcase {
const std::string output;
};
+#if !defined(OS_ANDROID)
void RunUrlTest(Testcase* testcases, size_t num_testcases) {
static const gfx::FontList font_list;
for (size_t i = 0; i < num_testcases; ++i) {
@@ -31,7 +32,8 @@ void RunUrlTest(Testcase* testcases, size_t num_testcases) {
const float available_width =
GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list);
EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
- ElideUrl(url, font_list, available_width, std::string()));
+ secure_display::ElideUrl(url, font_list, available_width,
+ std::string()));
}
}
@@ -39,23 +41,22 @@ void RunUrlTest(Testcase* testcases, size_t num_testcases) {
TEST(TextEliderTest, TestGeneralEliding) {
const std::string kEllipsisStr(kEllipsis);
Testcase testcases[] = {
- {"http://www.google.com/intl/en/ads/",
- "www.google.com/intl/en/ads/"},
- {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
- {"http://www.google.com/intl/en/ads/",
- "google.com/intl/" + kEllipsisStr + "/ads/"},
- {"http://www.google.com/intl/en/ads/",
- "google.com/" + kEllipsisStr + "/ads/"},
- {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr},
- {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr},
- {"https://subdomain.foo.com/bar/filename.html",
- "subdomain.foo.com/bar/filename.html"},
- {"https://subdomain.foo.com/bar/filename.html",
- "subdomain.foo.com/" + kEllipsisStr + "/filename.html"},
- {"http://subdomain.foo.com/bar/filename.html",
- kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"},
- {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired",
- "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
+ {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
+ {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
+ {"http://www.google.com/intl/en/ads/",
+ "google.com/intl/" + kEllipsisStr + "/ads/"},
+ {"http://www.google.com/intl/en/ads/",
+ "google.com/" + kEllipsisStr + "/ads/"},
+ {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr},
+ {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr},
+ {"https://subdomain.foo.com/bar/filename.html",
+ "subdomain.foo.com/bar/filename.html"},
+ {"https://subdomain.foo.com/bar/filename.html",
+ "subdomain.foo.com/" + kEllipsisStr + "/filename.html"},
+ {"http://subdomain.foo.com/bar/filename.html",
+ kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"},
+ {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired",
+ "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
};
RunUrlTest(testcases, arraysize(testcases));
@@ -83,17 +84,17 @@ TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) {
font_list),
GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list));
GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc");
- base::string16 expected =
- ElideUrl(long_url, font_list, available_width, std::string());
+ base::string16 expected = secure_display::ElideUrl(
+ long_url, font_list, available_width, std::string());
// Ensure that the expected result still contains part of the directory name.
ASSERT_GT(expected.length(), std::string("battersbox.com/d").length());
- EXPECT_EQ(expected,
- ElideUrl(url, font_list, available_width, std::string()));
+ EXPECT_EQ(expected, secure_display::ElideUrl(url, font_list, available_width,
+ std::string()));
// More space available - elide directories, partially elide filename.
Testcase testcases[] = {
- {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
- "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
+ {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
+ "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
};
RunUrlTest(testcases, arraysize(testcases));
}
@@ -102,35 +103,37 @@ TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) {
TEST(TextEliderTest, TestMoreEliding) {
const std::string kEllipsisStr(kEllipsis);
Testcase testcases[] = {
- {"http://www.google.com/foo?bar", "www.google.com/foo?bar"},
- {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr},
- {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr},
- {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr},
- {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"},
- {"", ""},
- {"http://foo.bar..example.com...hello/test/filename.html",
- "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"},
- {"http://foo.bar../", "foo.bar.."},
- {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"},
- {"http://me:mypass@secrethost.com:99/foo?bar#baz",
- "secrethost.com:99/foo?bar#baz"},
- {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"},
- {"mailto:elgoato@elgoato.com", "mailto:elgoato@elgoato.com"},
- {"javascript:click(0)", "javascript:click(0)"},
- {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
- "chess.eecs.berkeley.edu:4430/login/arbitfilename"},
- {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
- kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"},
+ {"http://www.google.com/foo?bar", "www.google.com/foo?bar"},
+ {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr},
+ {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr},
+ {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr},
+ {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"},
+ {"", ""},
+ {"http://foo.bar..example.com...hello/test/filename.html",
+ "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"},
+ {"http://foo.bar../", "foo.bar.."},
+ {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"},
+ {"http://me:mypass@secrethost.com:99/foo?bar#baz",
+ "secrethost.com:99/foo?bar#baz"},
+ {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"},
+ {"mailto:elgoato@elgoato.com", "mailto:elgoato@elgoato.com"},
+ {"javascript:click(0)", "javascript:click(0)"},
+ {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
+ "chess.eecs.berkeley.edu:4430/login/arbitfilename"},
+ {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
+ kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"},
- // Unescaping.
- {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
- "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
+ // Unescaping.
+ {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
+ "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
- // Invalid unescaping for path. The ref will always be valid UTF-8. We don't
- // bother to do too many edge cases, since these are handled by the escaper
- // unittest.
- {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
- "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
+ // Invalid unescaping for path. The ref will always be valid UTF-8. We
+ // don't
+ // bother to do too many edge cases, since these are handled by the
+ // escaper
+ // unittest.
+ {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
+ "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
};
RunUrlTest(testcases, arraysize(testcases));
@@ -142,8 +145,7 @@ TEST(TextEliderTest, TestFileURLEliding) {
Testcase testcases[] = {
{"file:///C:/path1/path2/path3/filename",
"file:///C:/path1/path2/path3/filename"},
- {"file:///C:/path1/path2/path3/filename",
- "C:/path1/path2/path3/filename"},
+ {"file:///C:/path1/path2/path3/filename", "C:/path1/path2/path3/filename"},
// GURL parses "file:///C:path" differently on windows than it does on posix.
#if defined(OS_WIN)
{"file:///C:path1/path2/path3/filename",
@@ -152,7 +154,7 @@ TEST(TextEliderTest, TestFileURLEliding) {
"C:/path1/" + kEllipsisStr + "/filename"},
{"file:///C:path1/path2/path3/filename",
"C:/" + kEllipsisStr + "/filename"},
-#endif
+#endif // defined(OS_WIN)
{"file://filer/foo/bar/file", "filer/foo/bar/file"},
{"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"},
{"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"},
@@ -173,7 +175,7 @@ TEST(TextEliderTest, TestHostEliding) {
{"http://google.com", "google.com"},
{"http://subdomain.google.com", kEllipsisStr + ".google.com"},
{"http://reallyreallyreallylongdomainname.com",
- "reallyreallyreallylongdomainname.com"},
+ "reallyreallyreallylongdomainname.com"},
{"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com"},
{"http://foo", "foo"},
{"http://foo.bar", "foo.bar"},
@@ -183,27 +185,33 @@ TEST(TextEliderTest, TestHostEliding) {
// many kerned letters on the default font set.
#if !defined(OS_IOS)
{"http://subdomain.reallylongdomainname.com",
- kEllipsisStr + "ain.reallylongdomainname.com"},
+ kEllipsisStr + "ain.reallylongdomainname.com"},
{"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com"},
-#endif
+#endif // !defined(OS_IOS)
};
for (size_t i = 0; i < arraysize(testcases); ++i) {
const float available_width =
GetStringWidthF(UTF8ToUTF16(testcases[i].output), gfx::FontList());
- EXPECT_EQ(UTF8ToUTF16(testcases[i].output), ElideHost(
- GURL(testcases[i].input), gfx::FontList(), available_width));
+ EXPECT_EQ(UTF8ToUTF16(testcases[i].output),
+ secure_display::ElideHost(GURL(testcases[i].input),
+ gfx::FontList(), available_width));
}
// Trying to elide to a really short length will still keep the full TLD+1
- EXPECT_EQ(base::ASCIIToUTF16("google.com"),
- ElideHost(GURL("http://google.com"), gfx::FontList(), 2));
+ EXPECT_EQ(
+ base::ASCIIToUTF16("google.com"),
+ secure_display::ElideHost(GURL("http://google.com"), gfx::FontList(), 2));
EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"),
- ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2));
- EXPECT_EQ(base::ASCIIToUTF16("foo.bar"),
- ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
+ secure_display::ElideHost(GURL("http://subdomain.google.com"),
+ gfx::FontList(), 2));
+ EXPECT_EQ(
+ base::ASCIIToUTF16("foo.bar"),
+ secure_display::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
}
+#endif // !defined(OS_ANDROID)
+
TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
struct OriginTestData {
const char* const description;
@@ -215,11 +223,9 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
{"Empty URL", "", L""},
{"HTTP URL", "http://www.google.com/", L"http://www.google.com"},
{"HTTPS URL", "https://www.google.com/", L"https://www.google.com"},
- {"Standard HTTP port",
- "http://www.google.com:80/",
+ {"Standard HTTP port", "http://www.google.com:80/",
L"http://www.google.com"},
- {"Standard HTTPS port",
- "https://www.google.com:443/",
+ {"Standard HTTPS port", "https://www.google.com:443/",
L"https://www.google.com"},
{"Standard HTTP port, IDN Chinese",
"http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
@@ -232,47 +238,35 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
{"HTTP URL with query string, IDN Arabic (RTL)",
"http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
L"http://xn--wgbh1c.icom.museum"},
- {"Non-standard HTTP port",
- "http://www.google.com:9000/",
+ {"Non-standard HTTP port", "http://www.google.com:9000/",
L"http://www.google.com:9000"},
- {"Non-standard HTTPS port",
- "https://www.google.com:9000/",
+ {"Non-standard HTTPS port", "https://www.google.com:9000/",
L"https://www.google.com:9000"},
- {"File URI",
- "file:///usr/example/file.html",
+ {"File URI", "file:///usr/example/file.html",
L"file:///usr/example/file.html"},
- {"File URI with hostname",
- "file://localhost/usr/example/file.html",
+ {"File URI with hostname", "file://localhost/usr/example/file.html",
L"file:///usr/example/file.html"},
- {"UNC File URI 1",
- "file:///CONTOSO/accounting/money.xls",
+ {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls",
L"file:///CONTOSO/accounting/money.xls"},
{"UNC File URI 2",
"file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO",
L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"},
- {"HTTP URL with path",
- "http://www.google.com/test.html",
+ {"HTTP URL with path", "http://www.google.com/test.html",
L"http://www.google.com"},
- {"HTTPS URL with path",
- "https://www.google.com/test.html",
+ {"HTTPS URL with path", "https://www.google.com/test.html",
L"https://www.google.com"},
- {"Unusual secure scheme (wss)",
- "wss://www.google.com/",
+ {"Unusual secure scheme (wss)", "wss://www.google.com/",
L"wss://www.google.com"},
- {"Unusual non-secure scheme (gopher)",
- "gopher://www.google.com/",
+ {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/",
L"gopher://www.google.com"},
{"Unlisted scheme (chrome)", "chrome://version", L"chrome://version"},
{"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103"},
{"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103"},
- {"HTTP IPv6 address",
- "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
+ {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
L"http://[fe80::202:b3ff:fe1e:8329]"},
- {"HTTPS IPv6 address with port",
- "https://[2001:db8:0:1]:443/",
+ {"HTTPS IPv6 address with port", "https://[2001:db8:0:1]:443/",
L"https://[2001:db8:0:1]"},
- {"HTTPS IP address, non-default port",
- "https://173.194.65.103:8443",
+ {"HTTPS IP address, non-default port", "https://173.194.65.103:8443",
L"https://173.194.65.103:8443"},
{"HTTP filesystem: URL with path",
"filesystem:http://www.google.com/temporary/test.html",
@@ -280,25 +274,19 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
{"File filesystem: URL with path",
"filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
L"filesystem:file:///temporary/stuff/test.html"},
- {"Invalid scheme 1",
- "twelve://www.cyber.org/wow.php",
+ {"Invalid scheme 1", "twelve://www.cyber.org/wow.php",
L"twelve://www.cyber.org/wow.php"},
- {"Invalid scheme 2",
- "://www.cyber.org/wow.php",
+ {"Invalid scheme 2", "://www.cyber.org/wow.php",
L"://www.cyber.org/wow.php"},
{"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber.."},
{"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber"},
- {"Invalid port 1",
- "https://173.194.65.103:000",
+ {"Invalid port 1", "https://173.194.65.103:000",
L"https://173.194.65.103:0"},
- {"Invalid port 2",
- "https://173.194.65.103:gruffle",
+ {"Invalid port 2", "https://173.194.65.103:gruffle",
L"https://173.194.65.103:gruffle"},
- {"Invalid port 3",
- "https://173.194.65.103:/hello.aspx",
+ {"Invalid port 3", "https://173.194.65.103:/hello.aspx",
L"https://173.194.65.103"},
- {"Trailing dot in DNS name",
- "https://www.example.com./get/goat",
+ {"Trailing dot in DNS name", "https://www.example.com./get/goat",
L"https://www.example.com."},
{"Blob URL",
"blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
@@ -308,17 +296,19 @@ TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar";
for (size_t i = 0; i < arraysize(tests); ++i) {
- base::string16 formatted =
- FormatUrlForSecurityDisplay(GURL(tests[i].input), std::string());
+ base::string16 formatted = secure_display::FormatUrlForSecurityDisplay(
+ GURL(tests[i].input), std::string());
EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
<< tests[i].description;
base::string16 formatted_with_languages =
- FormatUrlForSecurityDisplay(GURL(tests[i].input), languages);
+ secure_display::FormatUrlForSecurityDisplay(GURL(tests[i].input),
+ languages);
EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages)
<< tests[i].description;
}
- base::string16 formatted = FormatUrlForSecurityDisplay(GURL(), std::string());
+ base::string16 formatted =
+ secure_display::FormatUrlForSecurityDisplay(GURL(), std::string());
EXPECT_EQ(base::string16(), formatted)
<< "Explicitly test the 0-argument GURL constructor";
}