Bug 1031210 - Add junit tests for StringUtils.stripScheme. r=snorp, a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Mon, 27 Feb 2017 16:21:47 -0600
changeset 376482 984adcec5b2e720c5f1257f136eaa5dfb3a21fd8
parent 376481 d1e712e5d17f57d263645df3d16fb4cfe189f2b1
child 376483 e4f35a45184ce760f88c9d6572fb9b9542c4bcfb
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, jcristau
bugs1031210
milestone53.0a2
Bug 1031210 - Add junit tests for StringUtils.stripScheme. r=snorp, a=jcristau
mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java
@@ -53,16 +53,31 @@ public class TestStringUtils {
 
         assertEquals(StringUtils.stripRef("??AAABBBCCC"), "??AAABBBCCC");
         assertEquals(StringUtils.stripRef("https://mozilla.org"), "https://mozilla.org");
         assertEquals(StringUtils.stripRef("https://mozilla.org#BBBB"), "https://mozilla.org");
         assertEquals(StringUtils.stripRef("https://mozilla.org/#BBBB"), "https://mozilla.org/");
     }
 
     @Test
+    public void testStripScheme() {
+        assertEquals("mozilla.org", StringUtils.stripScheme("http://mozilla.org"));
+        assertEquals("mozilla.org", StringUtils.stripScheme("http://mozilla.org/"));
+        assertEquals("https://mozilla.org", StringUtils.stripScheme("https://mozilla.org"));
+        assertEquals("https://mozilla.org", StringUtils.stripScheme("https://mozilla.org/"));
+        assertEquals("mozilla.org", StringUtils.stripScheme("https://mozilla.org/", StringUtils.UrlFlags.STRIP_HTTPS));
+        assertEquals("mozilla.org", StringUtils.stripScheme("https://mozilla.org", StringUtils.UrlFlags.STRIP_HTTPS));
+        assertEquals("", StringUtils.stripScheme("http://"));
+        assertEquals("", StringUtils.stripScheme("https://", StringUtils.UrlFlags.STRIP_HTTPS));
+        // This edge case is not handled properly yet
+//        assertEquals(StringUtils.stripScheme("https://"), "");
+        assertEquals(null, StringUtils.stripScheme(null));
+    }
+
+    @Test
     public void testIsRTL() {
         assertFalse(StringUtils.isRTL("mozilla.org"));
         assertFalse(StringUtils.isRTL("something.عربي"));
 
         assertTrue(StringUtils.isRTL("عربي"));
         assertTrue(StringUtils.isRTL("عربي.org"));
 
         // Text with LTR mark