Bug 840825 - Clear distribution pref during testDistribution setup. r=wesj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 19 Feb 2013 10:49:42 -0800
changeset 122354 8619eb3bdee1abd6a8e456af8834a3b44390fdb8
parent 122353 16c9ccf0e50b856a1033e6cca670abe4b1b5eeb2
child 122355 a865bbcdc06dd4ec4c200bdea6334b04d60f7b40
push id24336
push userryanvm@gmail.com
push dateWed, 20 Feb 2013 12:07:46 +0000
treeherdermozilla-central@1bcc3c56b011 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs840825
milestone22.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 840825 - Clear distribution pref during testDistribution setup. r=wesj
mobile/android/base/Distribution.java
mobile/android/base/tests/testDistribution.java.in
--- a/mobile/android/base/Distribution.java
+++ b/mobile/android/base/Distribution.java
@@ -47,17 +47,17 @@ public final class Distribution {
     public static void init(final Context context, final String packagePath) {
         // Read/write preferences and files on the background thread.
         GeckoBackgroundThread.getHandler().post(new Runnable() {
             public void run() {
                 // Bail if we've already initialized the distribution.
                 SharedPreferences settings = context.getSharedPreferences(GeckoApp.PREFS_NAME, Activity.MODE_PRIVATE);
                 String keyName = context.getPackageName() + ".distribution_state";
                 int state = settings.getInt(keyName, STATE_UNKNOWN);
-                if (state == STATE_NONE && packagePath == null) {
+                if (state == STATE_NONE) {
                     return;
                 }
 
                 // Send a message to Gecko if we've set a distribution.
                 if (state == STATE_SET) {
                     GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Distribution:Set", null));
                     return;
                 }
--- a/mobile/android/base/tests/testDistribution.java.in
+++ b/mobile/android/base/tests/testDistribution.java.in
@@ -98,28 +98,37 @@ public class testDistribution extends Co
             outStream.write(b);
         }
         inStream.close();
         outStream.close();
 
         return outFile.getPath();
     }
 
+    // Clears the distribution pref to return distribution state to STATE_UNKNOWN
+    private void clearDistributionPref() {
+        SharedPreferences settings = mActivity.getSharedPreferences("GeckoApp", Activity.MODE_PRIVATE);
+        String keyName = mActivity.getPackageName() + ".distribution_state";
+        settings.edit().remove(keyName).commit();
+    }
+
     public void setUp() throws Exception {
         // TODO: Set up the content provider after setting the distribution.
         super.setUp("@ANDROID_PACKAGE_NAME@.db.BrowserProvider", "AUTHORITY");
 
         mActivity = getActivity();
 
+        // Clear the distribution pref in case Distribution.init has already run
+        clearDistributionPref();
+
         // Call Distribution.init with the mock package.
         ClassLoader classLoader = mActivity.getClassLoader();
         Class distributionClass = classLoader.loadClass("org.mozilla.gecko.Distribution");
         Class contextClass = classLoader.loadClass("android.content.Context");
-        Class stringClass = classLoader.loadClass("java.lang.String");
-        Method init = distributionClass.getMethod("init", contextClass, stringClass);
+        Method init = distributionClass.getMethod("init", contextClass, String.class);
 
         Actions.EventExpecter eventExpecter = mActions.expectGeckoEvent("Distribution:Set:OK");
         init.invoke(null, mActivity, getMockPackagePath());
         eventExpecter.blockForEvent();
     }
 
     public void tearDown() throws Exception {
         File dataDir = new File(mActivity.getApplicationInfo().dataDir);
@@ -131,16 +140,13 @@ public class testDistribution extends Co
         // Delete distribution files that Distribution.init copied to data directory.
         File distDir = new File(dataDir, "distribution");
         File[] files = distDir.listFiles();
         for (File f : files) {
             mAsserter.ok(f.delete(), "clean up distribution files", "deleted " + f.getPath());
         }
         mAsserter.ok(distDir.delete(), "clean up distribution directory", "deleted distribution directory");
 
-        // Reset distribution preference
-        SharedPreferences settings = mActivity.getSharedPreferences("GeckoApp", Activity.MODE_PRIVATE);
-        String keyName = mActivity.getPackageName() + ".distribution_state";
-        settings.edit().remove(keyName).commit();
+        clearDistributionPref();
 
         super.tearDown();
     }
 }