Bug 1269832 - Only show base domain for http/https URLs. r=margaret,kats, a=ritu
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 04 May 2016 13:30:48 +0200
changeset 326213 df31b4706eb48b305b8481aa77e1e6634b16f8c4
parent 326212 f07d961162adaf999dcaffc8c06bebfe8c5b8067
child 326214 1751932376045714265455bc1354b65e8533f712
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, kats, ritu
bugs1269832
milestone47.0
Bug 1269832 - Only show base domain for http/https URLs. r=margaret,kats, a=ritu 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
@@ -258,16 +258,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));
         }
 
@@ -275,22 +276,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"));
+    }
+}