Commit d0351675 authored by Brian R. Bondy's avatar Brian R. Bondy Committed by Georg Koppen
Browse files

Bug 973933 - Fix mochitest chrome updater tests. r=rstrong

Conflicts:
	toolkit/mozapps/update/tests/chrome/utils.js
parent d824edaf
Loading
Loading
Loading
Loading
+62 −1
Original line number Diff line number Diff line
@@ -114,7 +114,16 @@
 *   install completes.
 */

Components.utils.import("resource://gre/modules/AddonManager.jsm");
'use strict';

const { classes: Cc, interfaces: Ci, manager: Cm, results: Cr,
        utils: Cu } = Components;

Cu.import("resource://gre/modules/AddonManager.jsm", this);
Cu.import("resource://gre/modules/Services.jsm", this);

const IS_MACOSX = ("nsILocalFileMac" in Ci);
const IS_WIN = ("@mozilla.org/windows-registry-key;1" in Cc);

// The tests have to use the pageid instead of the pageIndex due to the
// app update wizard's access method being random.
@@ -166,6 +175,12 @@ const TEST_ADDONS = [ "appdisabled_1", "appdisabled_2",
                      "updateversion_1", "updateversion_2",
                      "userdisabled_1", "userdisabled_2", "hotfix" ];

const LOG_FUNCTION = info;

const BIN_SUFFIX = (IS_WIN ? ".exe" : "");
const FILE_UPDATER_BIN = "updater" + (IS_MACOSX ? ".app" : BIN_SUFFIX);
const FILE_UPDATER_BIN_BAK = FILE_UPDATER_BIN + ".bak";

var gURLData = URL_HOST + "/" + REL_PATH_DATA + "/";

var gTestTimeout = 240000; // 4 minutes
@@ -853,6 +868,26 @@ function verifyTestsRan() {
  }
}

/**
 * Restore the updater that was backed up.  This is called both in setupFiles
 * and resetFiles.  It is called in setupFiles before the backup is done in
 * case the previous test failed.  It is called in resetFiles to put things
 * back to its original state.
 */
function resetUpdaterBackup() {
  let baseAppDir = getAppBaseDir();
  let updater = baseAppDir.clone();
  let updaterBackup = baseAppDir.clone();
  updater.append(FILE_UPDATER_BIN);
  updaterBackup.append(FILE_UPDATER_BIN_BAK);
  if (updaterBackup.exists()) {
    if (updater.exists()) {
      updater.remove(true);
    }
    updaterBackup.moveTo(baseAppDir, FILE_UPDATER_BIN);
  }
}

/**
 * Creates a backup of files the tests need to modify so they can be restored to
 * the original file when the test has finished and then modifies the files.
@@ -868,6 +903,31 @@ function setupFiles() {
  updateSettingsIni = baseAppDir.clone();
  updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI);
  writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS);

  // Just in case the last test failed, try to reset.
  resetUpdaterBackup();

  // Move away the real updater
  let updater = baseAppDir.clone();
  updater.append(FILE_UPDATER_BIN);
  updater.moveTo(baseAppDir, FILE_UPDATER_BIN_BAK);

  // Move in the test only updater
  let testUpdaterDir = Cc["@mozilla.org/file/directory_service;1"].
    getService(Ci.nsIProperties).
    get("CurWorkD", Ci.nsILocalFile);

  let relPath = REL_PATH_DATA;
  let pathParts = relPath.split("/");
  for (let i = 0; i < pathParts.length; ++i) {
    testUpdaterDir.append(pathParts[i]);
  }

  let testUpdater = testUpdaterDir.clone();
  testUpdater.append(FILE_UPDATER_BIN);
  if (testUpdater.exists()) {
    testUpdater.copyToFollowingLinks(baseAppDir, FILE_UPDATER_BIN);
  }
}

/**
@@ -959,6 +1019,7 @@ function resetFiles() {
           "Exception: " + e + "\n");
    }
  }
  resetUpdaterBackup();
}

/**
+7 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
# For changes here, also consider ../Makefile.in

XPCSHELLTESTROOT = $(abspath $(DEPTH))/_tests/xpcshell/toolkit/mozapps/update/tests
MOCHITESTROOT = $(abspath $(DEPTH))/_tests/testing/mochitest/chrome/toolkit/mozapps/update/tests

ifndef MOZ_PROFILE_GENERATE
ifdef COMPILE_ENVIRONMENT
@@ -34,6 +35,7 @@ endif

libs::
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
	# Copy for xpcshell tests
	$(NSINSTALL) -D $(XPCSHELLTESTROOT)/data/updater-xpcshell.app
	rsync -a -C --exclude '*.in' $(srcdir)/../macbuild/Contents $(XPCSHELLTESTROOT)/data/updater-xpcshell.app
	sed -e 's/%APP_NAME%/$(MOZ_APP_DISPLAYNAME)/' $(srcdir)/../macbuild/Contents/Resources/English.lproj/InfoPlist.strings.in | \
@@ -41,10 +43,15 @@ ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
	$(NSINSTALL) -D $(XPCSHELLTESTROOT)/data/updater-xpcshell.app/Contents/MacOS/updater-xpcshell
	$(NSINSTALL) $(XPCSHELLTESTROOT)/data/updater-xpcshell $(XPCSHELLTESTROOT)/data/updater-xpcshell.app/Contents/MacOS
	rm -f $(XPCSHELLTESTROOT)/data/updater-xpcshell
	rm -Rf $(XPCSHELLTESTROOT)/data/updater.app
	mv $(XPCSHELLTESTROOT)/data/updater-xpcshell.app $(XPCSHELLTESTROOT)/data/updater.app
	mv $(XPCSHELLTESTROOT)/data/updater.app/Contents/MacOS/updater-xpcshell $(XPCSHELLTESTROOT)/data/updater.app/Contents/MacOS/updater

	# Copy for mochitest chrome tests
	rsync -a -C $(XPCSHELLTESTROOT)/data/updater.app $(MOCHITESTROOT)/data/updater.app
else
	mv $(XPCSHELLTESTROOT)/data/updater-xpcshell$(BIN_SUFFIX) $(XPCSHELLTESTROOT)/data/updater$(BIN_SUFFIX)
	cp $(XPCSHELLTESTROOT)/data/updater$(BIN_SUFFIX) $(MOCHITESTROOT)/data/updater$(BIN_SUFFIX)
endif

CXXFLAGS += $(MOZ_BZ2_CFLAGS)