Bug 1377287: Rm now unused ActivityStream.extractLabel. r=sebastian
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 19 Jul 2017 14:38:18 -0700
changeset 422313 4da81d3d8c65be8fecb9c1d4452ca463cb136c67
parent 422312 93c07d38f88036aabdd785bf4ef834a8a658e753
child 422314 7a3e7c2caaf7e760ffe8222c1d5e30f8d68a0773
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1377287
milestone56.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 1377287: Rm now unused ActivityStream.extractLabel. r=sebastian MozReview-Commit-ID: KP2AxzVA3CL
mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStream.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/activitystream/TestActivityStream.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStream.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStream.java
@@ -145,69 +145,9 @@ public class ActivityStream {
 
     /**
      * Query whether we want to display Activity Stream as a Home Panel (within the HomePager),
      * or as a HomePager replacement.
      */
     public static boolean isHomePanel() {
         return true;
     }
-
-    /**
-     * Extract a label from a URL to use in Activity Stream.
-     *
-     * This method implements the proposal from this desktop AS issue:
-     * https://github.com/mozilla/activity-stream/issues/1311
-     *
-     * @param usePath Use the path of the URL to extract a label (if suitable)
-     */
-    public static void extractLabel(final Context context, final String url, final boolean usePath, final LabelCallback callback) {
-        new AsyncTask<Void, Void, String>() {
-            @Override
-            protected String doInBackground(Void... params) {
-                if (TextUtils.isEmpty(url)) {
-                    return "";
-                }
-
-                final Uri uri = Uri.parse(url);
-
-                // Use last path segment if suitable
-                if (usePath) {
-                    final String segment = uri.getLastPathSegment();
-                    if (!TextUtils.isEmpty(segment)
-                            && !UNDESIRED_LABELS.contains(segment)
-                            && !segment.matches("^[0-9]+$")) {
-
-                        boolean hasUndesiredPrefix = false;
-                        for (int i = 0; i < UNDESIRED_LABEL_PREFIXES.size(); i++) {
-                            if (segment.startsWith(UNDESIRED_LABEL_PREFIXES.get(i))) {
-                                hasUndesiredPrefix = true;
-                                break;
-                            }
-                        }
-
-                        if (!hasUndesiredPrefix) {
-                            return segment;
-                        }
-                    }
-                }
-
-                // If no usable path segment was found then use the host without public suffix and common subdomains
-                final String host = uri.getHost();
-                if (TextUtils.isEmpty(host)) {
-                    return url;
-                }
-
-                return StringUtils.stripCommonSubdomains(
-                        PublicSuffix.stripPublicSuffix(context, host));
-            }
-
-            @Override
-            protected void onPostExecute(String label) {
-                callback.onLabelExtracted(label);
-            }
-        }.execute();
-    }
-
-    public abstract static class LabelCallback {
-        public abstract void onLabelExtracted(String label);
-    }
 }
deleted file mode 100644
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/activitystream/TestActivityStream.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.gecko.activitystream;
-
-import android.os.SystemClock;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mozilla.gecko.background.testhelpers.TestRunner;
-import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.shadows.ShadowLooper;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(TestRunner.class)
-public class TestActivityStream {
-    /**
-     * Unit tests for ActivityStream.extractLabel().
-     *
-     * Most test cases are based on this list:
-     * https://gist.github.com/nchapman/36502ad115e8825d522a66549971a3f0
-     */
-    @Test
-    public void testExtractLabelWithPath() {
-        // Empty values
-        assertLabelEquals("", "", true);
-        assertLabelEquals("", null, true);
-
-        // Without path
-        assertLabelEquals("news.ycombinator", "https://news.ycombinator.com/", true);
-        assertLabelEquals("sql.telemetry.mozilla", "https://sql.telemetry.mozilla.org/", true);
-        assertLabelEquals("sso.mozilla", "http://sso.mozilla.com/", true);
-        assertLabelEquals("youtube", "http://youtube.com/", true);
-        assertLabelEquals("images.google", "http://images.google.com/", true);
-        assertLabelEquals("smile.amazon", "http://smile.amazon.com/", true);
-        assertLabelEquals("localhost", "http://localhost:5000/", true);
-        assertLabelEquals("independent", "http://www.independent.co.uk/", true);
-
-        // With path
-        assertLabelEquals("firefox", "https://addons.mozilla.org/en-US/firefox/", true);
-        assertLabelEquals("activity-stream", "https://trello.com/b/KX3hV8XS/activity-stream", true);
-        assertLabelEquals("activity-stream", "https://github.com/mozilla/activity-stream", true);
-        assertLabelEquals("sidekiq", "https://dispatch-news.herokuapp.com/sidekiq", true);
-        assertLabelEquals("nchapman", "https://github.com/nchapman/", true);
-
-        // Unusable paths
-        assertLabelEquals("phonebook.mozilla","https://phonebook.mozilla.org/mellon/login?ReturnTo=https%3A%2F%2Fphonebook.mozilla.org%2F&IdP=http%3A%2F%2Fwww.okta.com", true);
-        assertLabelEquals("ipay.adp", "https://ipay.adp.com/iPay/index.jsf", true);
-        assertLabelEquals("calendar.google", "https://calendar.google.com/calendar/render?pli=1#main_7", true);
-        assertLabelEquals("myworkday", "https://www.myworkday.com/vhr_mozilla/d/home.htmld", true);
-        assertLabelEquals("mail.google", "https://mail.google.com/mail/u/1/#inbox", true);
-        assertLabelEquals("docs.google", "https://docs.google.com/presentation/d/11cyrcwhKTmBdEBIZ3szLO0-_Imrx2CGV2B9_LZHDrds/edit#slide=id.g15d41bb0f3_0_82", true);
-
-        // Special cases
-        assertLabelEquals("irccloud.mozilla", "https://irccloud.mozilla.com/#!/ircs://irc1.dmz.scl3.mozilla.com:6697/%23universal-search", true);
-    }
-
-    @Test
-    public void testExtractLabelWithoutPath() {
-        assertLabelEquals("addons.mozilla", "https://addons.mozilla.org/en-US/firefox/", false);
-        assertLabelEquals("trello", "https://trello.com/b/KX3hV8XS/activity-stream", false);
-        assertLabelEquals("github", "https://github.com/mozilla/activity-stream", false);
-        assertLabelEquals("dispatch-news", "https://dispatch-news.herokuapp.com/sidekiq", false);
-        assertLabelEquals("github", "https://github.com/nchapman/", false);
-    }
-
-    private void assertLabelEquals(String expectedLabel, String url, boolean usePath) {
-        final String[] actualLabel = new String[1];
-
-        ActivityStream.LabelCallback callback = new ActivityStream.LabelCallback() {
-            @Override
-            public void onLabelExtracted(String label) {
-                actualLabel[0] = label;
-            }
-        };
-
-        ActivityStream.extractLabel(RuntimeEnvironment.application, url, usePath, callback);
-
-        ShadowLooper.runUiThreadTasks();
-
-        assertEquals(expectedLabel, actualLabel[0]);
-    }
-}