Bug 1031210 - Add junit tests for StringUtils.stripScheme. r=snorp
authorMichael Kaply <mozilla@kaply.com>
Mon, 27 Feb 2017 16:21:47 -0600
changeset 490322 4ee8c67b75bc1e300ffa5376198b1b991d0928e7
parent 490321 dbe72cd317e29cc7805cba0b7d8eca653a291dc6
child 490323 e1a939a64f4b0ce63d1879705685c866f4297b36
push id47063
push userbmo:rail@mozilla.com
push dateTue, 28 Feb 2017 03:41:15 +0000
reviewerssnorp
bugs1031210
milestone54.0a1
Bug 1031210 - Add junit tests for StringUtils.stripScheme. r=snorp
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