Bug 1220906 - Part 7: Miscellaneous purging. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Mon, 18 Jan 2016 17:17:03 -0800
changeset 303125 35cbe50b67460f06c18d3014b4521e1c708a5ef9
parent 303124 0b67a9cbbe6593db6d35c23c8e8fce0d12ff2a34
child 303126 57327dc816470c156305f3cb0ac221fd5716d5eb
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1220906
milestone46.0a1
Bug 1220906 - Part 7: Miscellaneous purging. r=rnewman
mobile/android/base/android-services.mozbuild
mobile/android/services/src/main/java/org/mozilla/gecko/background/common/DateUtils.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/setup/Constants.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/setup/activities/ActivityUtils.java
mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
mobile/android/tests/background/junit3/instrumentation.ini
mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestDateUtils.java
mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSyncKeyVerification.java
--- a/mobile/android/base/android-services.mozbuild
+++ b/mobile/android/base/android-services.mozbuild
@@ -760,17 +760,16 @@ sync_thirdparty_java_files = [
     'org/mozilla/apache/commons/codec/net/Utils.java',
     'org/mozilla/apache/commons/codec/StringDecoder.java',
     'org/mozilla/apache/commons/codec/StringEncoder.java',
     'org/mozilla/apache/commons/codec/StringEncoderComparator.java',
 ]
 
 sync_java_files = [TOPSRCDIR + '/mobile/android/services/src/main/java/org/mozilla/gecko/' + x for x in [
     'background/BackgroundService.java',
-    'background/common/DateUtils.java',
     'background/common/EditorBranch.java',
     'background/common/GlobalConstants.java',
     'background/common/log/Logger.java',
     'background/common/log/writers/AndroidLevelCachingLogWriter.java',
     'background/common/log/writers/AndroidLogWriter.java',
     'background/common/log/writers/LevelFilteringLogWriter.java',
     'background/common/log/writers/LogWriter.java',
     'background/common/log/writers/PrintLogWriter.java',
deleted file mode 100644
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/common/DateUtils.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/* 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.background.common;
-
-import java.util.Calendar;
-import java.util.Formatter;
-import java.util.TimeZone;
-
-public class DateUtils {
-  private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
-
-  public static final class DateFormatter {
-    private final Calendar calendar;
-    private final Formatter formatter;
-    private final StringBuilder builder;
-
-    public DateFormatter() {
-      this.calendar = Calendar.getInstance(UTC);
-      this.builder = new StringBuilder();              // So we can reset it.
-      this.formatter = new Formatter(this.builder, null);
-    }
-
-    public String getDateString(long time) {
-      calendar.setTimeInMillis(time);
-      builder.setLength(0);
-      return formatter.format("%04d-%02d-%02d",
-                              calendar.get(Calendar.YEAR),
-                              calendar.get(Calendar.MONTH) + 1,      // 0-indexed.
-                              calendar.get(Calendar.DAY_OF_MONTH))
-                      .toString();
-    }
-
-    public String getDateStringForDay(long day) {
-      return getDateString(GlobalConstants.MILLISECONDS_PER_DAY * day);
-    }
-  }
-
-  public static int getDay(final long time) {
-    return (int) Math.floor(time / GlobalConstants.MILLISECONDS_PER_DAY);
-  }
-}
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/setup/Constants.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/setup/Constants.java
@@ -1,35 +1,18 @@
 /* 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.sync.setup;
 
-import android.content.Intent;
-
 public class Constants {
-  // Constants for Firefox Sync SyncAdapter Accounts.
-  public static final String OPTION_SYNCKEY       = "option.synckey";
-  public static final String OPTION_USERNAME      = "option.username";
-  public static final String AUTHTOKEN_TYPE_PLAIN = "auth.plain";
-  public static final String OPTION_SERVER        = "option.serverUrl";
-  public static final String DATA_ENABLE_ON_UPGRADE = "data.enableOnUpgrade";
-  public static final String DATA_SHOULD_BE_REMOVED = "data.shouldBeRemoved";
-
   public static final String DEFAULT_PROFILE = "default";
 
   /**
-   * Name of file to pickle current account preferences to each sync.
-   * <p>
-   * Must not contain path separators!
-   */
-  public static final String ACCOUNT_PICKLE_FILENAME = "sync.account.json";
-
-  /**
    * Key in sync extras bundle specifying stages to sync this sync session.
    * <p>
    * Corresponding value should be a String JSON-encoding an object, the keys of
    * which are the stage names to sync. For example:
    * <code>"{ \"stageToSync\": 0 }"</code>.
    */
   public static final String EXTRAS_KEY_STAGES_TO_SYNC = "sync";
 
@@ -37,75 +20,10 @@ public class Constants {
    * Key in sync extras bundle specifying stages to skip this sync session.
    * <p>
    * Corresponding value should be a String JSON-encoding an object, the keys of
    * which are the stage names to skip. For example:
    * <code>"{ \"stageToSkip\": 0 }"</code>.
    */
   public static final String EXTRAS_KEY_STAGES_TO_SKIP = "skip";
 
-  // Constants for Activities.
-  public static final String INTENT_EXTRA_IS_SETUP        = "isSetup";
-  public static final String INTENT_EXTRA_IS_PAIR         = "isPair";
-  public static final String INTENT_EXTRA_IS_ACCOUNTERROR = "isAccountError";
-
-  public static final int FLAG_ACTIVITY_REORDER_TO_FRONT_NO_ANIMATION =
-    Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
-    Intent.FLAG_ACTIVITY_NO_ANIMATION;
-
-  // Constants for Account Authentication.
-  public static final String AUTH_SERVER_VERSION  = "1.1/";
-  public static final String AUTH_SERVER_SUFFIX   = "info/collections/";
-
-  // Account Authentication Errors.
-  public static final String AUTH_ERROR_NOUSER    = "auth.error.badcredentials";
-
-  // Links for J-PAKE setup help pages.
-  public static final String LINK_FIND_CODE       = "https://support.mozilla.org/kb/find-code-to-add-device-to-firefox-sync";
-  public static final String LINK_FIND_ADD_DEVICE = "https://support.mozilla.org/kb/add-a-device-to-firefox-sync";
-
-  // Constants for JSON payload.
-  public static final String JSON_KEY_PAYLOAD    = "payload";
-  public static final String JSON_KEY_CIPHERTEXT = "ciphertext";
-  public static final String JSON_KEY_HMAC       = "hmac";
-  public static final String JSON_KEY_IV         = "IV";
-  public static final String JSON_KEY_TYPE       = "type";
-  public static final String JSON_KEY_VERSION    = "version";
-  public static final String JSON_KEY_ETAG       = "etag";
-
   public static final String JSON_KEY_ACCOUNT    = "account";
-  public static final String JSON_KEY_PASSWORD   = "password";
-  public static final String JSON_KEY_SYNCKEY    = "synckey";
-  public static final String JSON_KEY_SERVER     = "serverURL";
-  public static final String JSON_KEY_CLUSTER    = "clusterURL";
-  public static final String JSON_KEY_CLIENT_NAME = "clientName";
-  public static final String JSON_KEY_CLIENT_GUID = "clientGUID";
-  public static final String JSON_KEY_SYNC_AUTOMATICALLY = "syncAutomatically";
-  public static final String JSON_KEY_TIMESTAMP  = "timestamp";
-
-  public static final String CRYPTO_KEY_GR1 = "gr1";
-  public static final String CRYPTO_KEY_GR2 = "gr2";
-
-  public static final String ZKP_KEY_GX1    = "gx1";
-  public static final String ZKP_KEY_GX2    = "gx2";
-
-  public static final String ZKP_KEY_ZKP_X1 = "zkp_x1";
-  public static final String ZKP_KEY_ZKP_X2 = "zkp_x2";
-  public static final String ZKP_KEY_B      = "b";
-  public static final String ZKP_KEY_GR     = "gr";
-  public static final String ZKP_KEY_ID     = "id";
-
-  public static final String ZKP_KEY_A      = "A";
-  public static final String ZKP_KEY_ZKP_A  = "zkp_A";
-
-  // J-PAKE errors.
-  public static final String JPAKE_ERROR_CHANNEL          = "jpake.error.channel";
-  public static final String JPAKE_ERROR_NETWORK          = "jpake.error.network";
-  public static final String JPAKE_ERROR_SERVER           = "jpake.error.server";
-  public static final String JPAKE_ERROR_TIMEOUT          = "jpake.error.timeout";
-  public static final String JPAKE_ERROR_INTERNAL         = "jpake.error.internal";
-  public static final String JPAKE_ERROR_INVALID          = "jpake.error.invalid";
-  public static final String JPAKE_ERROR_NODATA           = "jpake.error.nodata";
-  public static final String JPAKE_ERROR_KEYMISMATCH      = "jpake.error.keymismatch";
-  public static final String JPAKE_ERROR_WRONGMESSAGE     = "jpake.error.wrongmessage";
-  public static final String JPAKE_ERROR_USERABORT        = "jpake.error.userabort";
-  public static final String JPAKE_ERROR_DELAYUNSUPPORTED = "jpake.error.delayunsupported";
 }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/setup/activities/ActivityUtils.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/setup/activities/ActivityUtils.java
@@ -1,59 +1,22 @@
 /* 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.sync.setup.activities;
 
-import java.util.Locale;
-
-import org.mozilla.gecko.background.common.GlobalConstants;
-import org.mozilla.gecko.background.common.log.Logger;
-import org.mozilla.gecko.db.BrowserContract;
-import org.mozilla.gecko.sync.SyncConstants;
-import org.mozilla.gecko.sync.setup.InvalidSyncKeyException;
-
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
-import android.text.Html;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.TextPaint;
-import android.text.method.LinkMovementMethod;
-import android.text.style.ClickableSpan;
-import android.text.style.URLSpan;
-import android.view.View;
-import android.widget.TextView;
+
+import org.mozilla.gecko.background.common.GlobalConstants;
+import org.mozilla.gecko.db.BrowserContract;
 
 public class ActivityUtils {
-  private static final String LOG_TAG = "ActivityUtils";
-
-  public static void prepareLogging() {
-    Logger.setThreadLogTag(SyncConstants.GLOBAL_LOG_TAG);
-  }
-
-  /**
-   * Sync key should be a 26-character string, and can include arbitrary
-   * capitalization and hyphenation.
-   *
-   * @param key
-   *          Sync key entered by user in account setup.
-   * @return Sync key in correct format (lower-case, no hyphens).
-   * @throws InvalidSyncKeyException
-   */
-  public static String validateSyncKey(String key) throws InvalidSyncKeyException {
-    String charKey = key.trim().replace("-", "").toLowerCase(Locale.US);
-    if (!charKey.matches("^[abcdefghijkmnpqrstuvwxyz23456789]{26}$")) {
-      throw new InvalidSyncKeyException();
-    }
-    return charKey;
-  }
-
   /**
    * Open a URL in Fennec, if one is provided; or just open Fennec.
    *
    * @param context Android context.
    * @param url to visit, or null to just open Fennec.
    */
   public static void openURLInFennec(final Context context, final String url) {
     Intent intent;
@@ -63,79 +26,9 @@ public class ActivityUtils {
     } else {
       intent = new Intent(Intent.ACTION_MAIN);
     }
     intent.setClassName(GlobalConstants.BROWSER_INTENT_PACKAGE, GlobalConstants.BROWSER_INTENT_CLASS);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     intent.putExtra(BrowserContract.SKIP_TAB_QUEUE_FLAG, true);
     context.startActivity(intent);
   }
-
-  /**
-   * Open a clicked span in Fennec with the provided URL.
-   */
-  public static class FennecClickableSpan extends ClickableSpan {
-    private final String url;
-    private final boolean underlining;
-
-    public FennecClickableSpan(final String url, boolean underlining) {
-      this.url = url;
-      this.underlining = underlining;
-    }
-
-    @Override
-    public void updateDrawState(TextPaint ds) {
-      super.updateDrawState(ds);
-      if (!this.underlining) {
-        ds.setUnderlineText(false);
-      }
-    }
-
-    @Override
-    public void onClick(View widget) {
-      openURLInFennec(widget.getContext(), this.url);
-    }
-  }
-
-  /**
-   * Replace the contents of a plain text view with the provided text wrapped in a link.
-   * TODO: escape the URL!
-   */
-  public static void linkTextView(TextView view, int text, int link) {
-    final Context context = view.getContext();
-    linkTextView(view, context.getString(text), context.getString(link));
-  }
-
-  /**
-   * Replace the contents of a plain text view with the provided text wrapped in a link.
-   * TODO: escape the URL!
-   */
-  public static void linkTextView(TextView view, String text, String url) {
-    view.setText("<a href=\"" + url + "\">" + text + "</a>");
-    linkifyTextView(view, false);
-  }
-
-  public static void linkifyTextView(TextView textView, boolean underlining) {
-    if (textView == null) {
-      Logger.warn(LOG_TAG, "Could not process links for view.");
-      return;
-    }
-
-    textView.setMovementMethod(LinkMovementMethod.getInstance());
-
-    // Create spans.
-    final Spanned spanned = Html.fromHtml(textView.getText().toString());
-
-    // Replace the spans with Fennec-launching links.
-    SpannableString replaced = new SpannableString(spanned);
-    URLSpan[] spans = replaced.getSpans(0, replaced.length(), URLSpan.class);
-    for (URLSpan span : spans) {
-      final int start = replaced.getSpanStart(span);
-      final int end = replaced.getSpanEnd(span);
-      final int flags = replaced.getSpanFlags(span);
-
-      replaced.removeSpan(span);
-      replaced.setSpan(new FennecClickableSpan(span.getURL(), underlining), start, end, flags);
-    }
-
-    textView.setText(replaced);
-  }
 }
--- a/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
+++ b/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
@@ -2,17 +2,16 @@
 # vim: set filetype=python:
 # 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/.
 
 background_junit3_sources = [
     'src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java',
     'src/org/mozilla/gecko/background/common/TestBrowserContractHelpers.java',
-    'src/org/mozilla/gecko/background/common/TestDateUtils.java',
     'src/org/mozilla/gecko/background/common/TestUtils.java',
     'src/org/mozilla/gecko/background/common/TestWaitHelper.java',
     'src/org/mozilla/gecko/background/db/AndroidBrowserRepositoryTestCase.java',
     'src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java',
     'src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryDataExtender.java',
     'src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java',
     'src/org/mozilla/gecko/background/db/TestBookmarks.java',
     'src/org/mozilla/gecko/background/db/TestCachedSQLiteOpenHelper.java',
--- a/mobile/android/tests/background/junit3/instrumentation.ini
+++ b/mobile/android/tests/background/junit3/instrumentation.ini
@@ -1,14 +1,13 @@
 [DEFAULT]
 subsuite = background
 
 [src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java]
 [src/org/mozilla/gecko/background/common/TestBrowserContractHelpers.java]
-[src/org/mozilla/gecko/background/common/TestDateUtils.java]
 [src/org/mozilla/gecko/background/common/TestUtils.java]
 [src/org/mozilla/gecko/background/common/TestWaitHelper.java]
 [src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java]
 [src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryDataExtender.java]
 [src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java]
 [src/org/mozilla/gecko/background/db/TestBookmarks.java]
 [src/org/mozilla/gecko/background/db/TestCachedSQLiteOpenHelper.java]
 [src/org/mozilla/gecko/background/db/TestClientsDatabase.java]
deleted file mode 100644
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestDateUtils.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.gecko.background.common;
-
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
-
-import org.mozilla.gecko.background.common.DateUtils.DateFormatter;
-//import android.util.SparseArray;
-
-public class TestDateUtils extends TestCase {
-  // Our old, correct implementation -- used to test the new one.
-  public static String getDateStringUsingFormatter(long time) {
-    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
-    format.setTimeZone(TimeZone.getTimeZone("UTC"));
-    return format.format(time);
-  }
-
-  private void checkDateString(long time) {
-    assertEquals(getDateStringUsingFormatter(time),
-                 new DateUtils.DateFormatter().getDateString(time));
-  }
-
-  public void testDateImplementations() {
-    checkDateString(1L);
-    checkDateString(System.currentTimeMillis());
-    checkDateString(1379118065844L);
-    checkDateString(1379110000000L);
-    for (long i = 0L; i < (2 * GlobalConstants.MILLISECONDS_PER_DAY); i += 11000) {
-      checkDateString(i);
-    }
-  }
-
-  @SuppressWarnings("static-method")
-  public void testReuse() {
-    DateFormatter formatter = new DateFormatter();
-    long time = System.currentTimeMillis();
-    assertEquals(formatter.getDateString(time), formatter.getDateString(time));
-  }
-
-  // Perf tests. Disabled until you need them.
-  /*
-  @SuppressWarnings("static-method")
-  public void testDateTiming() {
-    long start = 1379118000000L;
-    long end   = 1379118045844L;
-
-    long t0 = android.os.SystemClock.elapsedRealtime();
-    for (long i = start; i < end; ++i) {
-      DateUtils.getDateString(i);
-    }
-    long t1 = android.os.SystemClock.elapsedRealtime();
-    System.err.println("CALENDAR: " + (t1 - t0));
-
-
-    t0 = android.os.SystemClock.elapsedRealtime();
-    for (long i = start; i < end; ++i) {
-      getDateStringFormatter(i);
-    }
-    t1 = android.os.SystemClock.elapsedRealtime();
-    System.err.println("FORMATTER: " + (t1 - t0));
-  }
-
-  @SuppressWarnings("static-method")
-  public void testDayTiming() {
-    long start = 33 * 365;
-    long end   = start + 90;
-    int reps   = 1;
-    long t0 = android.os.SystemClock.elapsedRealtime();
-    for (long i = start; i < end; ++i) {
-      for (int j = 0; j < reps; ++j) {
-        DateUtils.getDateStringForDay(i);
-      }
-    }
-    long t1 = android.os.SystemClock.elapsedRealtime();
-    System.err.println("Non-memo: " + (t1 - t0));
-  }
-  */
-}
deleted file mode 100644
--- a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSyncKeyVerification.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.android.sync.test;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mozilla.gecko.background.testhelpers.TestRunner;
-import org.mozilla.gecko.sync.setup.InvalidSyncKeyException;
-import org.mozilla.gecko.sync.setup.activities.ActivityUtils;
-
-import static org.junit.Assert.fail;
-
-@RunWith(TestRunner.class)
-public class TestSyncKeyVerification {
-
-  private int[] mutateIndices;
-  private final String validBasicKey = "abcdefghijkmnpqrstuvwxyz23"; // 26 char, valid characters.
-  char[] invalidChars = new char[] { '1', 'l', 'o', '0' };
-
-  @Before
-  public void setUp() {
-    // Generate indicies to mutate.
-    mutateIndices = generateMutationArray();
-  }
-
-  @Test
-  public void testValidKey() {
-    try {
-      ActivityUtils.validateSyncKey(validBasicKey);
-    } catch (InvalidSyncKeyException e) {
-      fail("Threw unexpected InvalidSyncKeyException.");
-    }
-  }
-
-  @Test
-  public void testHyphenationSuccess() {
-    StringBuilder sb = new StringBuilder();
-    int prev = 0;
-    for (int i : mutateIndices) {
-      sb.append(validBasicKey.substring(prev, i));
-      sb.append("-");
-      prev = i;
-    }
-    sb.append(validBasicKey.substring(prev));
-    String hString = sb.toString();
-    try {
-      ActivityUtils.validateSyncKey(hString);
-    } catch (InvalidSyncKeyException e) {
-      fail("Failed validation with hypenation.");
-    }
-  }
-
-  @Test
-  public void testCapitalizationSuccess() {
-
-    char[] mutatedKey = validBasicKey.toCharArray();
-    for (int i : mutateIndices) {
-      mutatedKey[i] = Character.toUpperCase(validBasicKey.charAt(i));
-    }
-    String mKey = new String(mutatedKey);
-    try {
-      ActivityUtils.validateSyncKey(mKey);
-    } catch (InvalidSyncKeyException e) {
-      fail("Failed validation with uppercasing.");
-    }
-  }
-
-  @Test (expected = InvalidSyncKeyException.class)
-  public void testInvalidCharFailure() throws InvalidSyncKeyException {
-    char[] mutatedKey = validBasicKey.toCharArray();
-    for (int i : mutateIndices) {
-      mutatedKey[i] = invalidChars[i % invalidChars.length];
-    }
-    ActivityUtils.validateSyncKey(mutatedKey.toString());
-  }
-
-  private int[] generateMutationArray() {
-    // Hardcoded; change if desired?
-    return new int[] { 2, 4, 5, 9, 16 };
-  }
-}