Bug 1269832 - Only show base domain for http/https URLs. r=margaret,kats
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 04 May 2016 13:30:48 +0200
changeset 296768 8fe0095972a5f19d2c078e218d44631c75a4fd7e
parent 296767 77c1d14c1e1f389a6e4dffd50e401cf739461a82
child 296769 8deb0d7312e5688d4a2e8cb7837b1a9bca2f9006
push id76476
push usercbook@mozilla.com
push dateTue, 10 May 2016 10:15:07 +0000
treeherdermozilla-inbound@d372ddfd228f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, kats
bugs1269832
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1269832 - Only show base domain for http/https URLs. r=margaret,kats MozReview-Commit-ID: Dzk6vN2cyVb
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/base/java/org/mozilla/gecko/util/StringUtils.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -260,16 +260,17 @@ public class ToolbarDisplayLayout extend
             final SpannableStringBuilder builder = new SpannableStringBuilder(title);
             builder.setSpan(mBlockedColorSpan, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
 
             setTitle(builder);
             setContentDescription(null);
             return;
         }
 
+        final boolean isHttpOrHttps = StringUtils.isHttpOrHttps(url);
         final String baseDomain = tab.getBaseDomain();
 
         String strippedURL = stripAboutReaderURL(url);
 
         if (mPrefs.shouldTrimUrls()) {
             strippedURL = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(strippedURL));
         }
 
@@ -277,22 +278,25 @@ public class ToolbarDisplayLayout extend
         // readers will instead focus BrowserToolbar and read the "base domain" from there. UI tests
         // will read the content description to obtain the full URL for performing assertions.
         setContentDescription(strippedURL);
 
         final SiteIdentity siteIdentity = tab.getSiteIdentity();
         if (siteIdentity.hasOwner()) {
             // Show Owner of EV certificate as title
             updateTitleFromSiteIdentity(siteIdentity);
-        } else if (!HardwareUtils.isTablet() && !TextUtils.isEmpty(baseDomain)) {
+        } else if (isHttpOrHttps && !HardwareUtils.isTablet() && !TextUtils.isEmpty(baseDomain)) {
             // Show just the base domain as title
             setTitle(baseDomain);
+        } else if (isHttpOrHttps) {
+            // Display full URL with base domain highlighted as title
+            updateAndColorTitleFromFullURL(strippedURL, baseDomain, tab.isPrivate());
         } else {
-            // Display full URL as title
-            updateAndColorTitleFromFullURL(strippedURL, baseDomain, tab.isPrivate());
+            // Not http(s): Just show the full URL as title
+            setTitle(url);
         }
     }
 
     private void updateTitleFromSiteIdentity(SiteIdentity siteIdentity) {
         final String title;
 
         if (siteIdentity.hasCountry()) {
             title = String.format("%s (%s)", siteIdentity.getOwner(), siteIdentity.getCountry());
--- a/mobile/android/base/java/org/mozilla/gecko/util/StringUtils.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/StringUtils.java
@@ -87,16 +87,24 @@ public class StringUtils {
 
         if (url.endsWith("/")) {
             end--;
         }
 
         return url.substring(start, end);
     }
 
+    public static boolean isHttpOrHttps(String url) {
+        if (TextUtils.isEmpty(url)) {
+            return false;
+        }
+
+        return url.startsWith("http://") || url.startsWith("https://");
+    }
+
     public static String stripCommonSubdomains(String host) {
         if (host == null) {
             return host;
         }
 
         // In contrast to desktop, we also strip mobile subdomains,
         // since its unlikely users are intentionally typing them
         int start = 0;
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java
@@ -0,0 +1,43 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.util;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mozilla.gecko.background.testhelpers.TestRunner;
+
+@RunWith(TestRunner.class)
+public class TestStringUtils {
+    @Test
+    public void testIsHttpOrHttps() {
+        // No value
+        Assert.assertFalse(StringUtils.isHttpOrHttps(null));
+        Assert.assertFalse(StringUtils.isHttpOrHttps(""));
+
+        // Garbage
+        Assert.assertFalse(StringUtils.isHttpOrHttps("lksdjflasuf"));
+
+        // URLs with http/https
+        Assert.assertTrue(StringUtils.isHttpOrHttps("https://www.google.com"));
+        Assert.assertTrue(StringUtils.isHttpOrHttps("http://www.facebook.com"));
+        Assert.assertTrue(StringUtils.isHttpOrHttps("https://mozilla.org/en-US/firefox/products/"));
+
+        // IP addresses
+        Assert.assertTrue(StringUtils.isHttpOrHttps("https://192.168.0.1"));
+        Assert.assertTrue(StringUtils.isHttpOrHttps("http://63.245.215.20/en-US/firefox/products"));
+
+        // Other protocols
+        Assert.assertFalse(StringUtils.isHttpOrHttps("ftp://people.mozilla.org"));
+        Assert.assertFalse(StringUtils.isHttpOrHttps("javascript:window.google.com"));
+        Assert.assertFalse(StringUtils.isHttpOrHttps("tel://1234567890"));
+
+        // No scheme
+        Assert.assertFalse(StringUtils.isHttpOrHttps("google.com"));
+        Assert.assertFalse(StringUtils.isHttpOrHttps("git@github.com:mozilla/gecko-dev.git"));
+    }
+}