B2G/gecko/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js
/**
 * Checks if the update has finished and if it has finished performs checks for
 * the test.
 */
Checks if the update has finished and if it has finished performs checks for
the test.
Checks if the update has finished and if it has finished performs checks for the test .
function checkUpdateFinished() {
  gTimeoutRuns++;
  try {
    let status = readStatusFile();
    if (status != STATE_SUCCEEDED) {
      if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
        do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to change to succeeded, current status: " + status);
      else
        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
      return;
    }
  } catch (e) {
  }
  try {
    getAppConsoleLogPath();
  } catch (e) {
    if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) {
      if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
        do_throw("Exceeded whilst waiting for file to be unlocked");
      else
        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
      return;
    } else {
      do_throw("getAppConsoleLogPath threw: " + e);
    }
  }
  let updatedDir = getAppDir();
  if (IS_MACOSX) {
    updatedDir = updatedDir.parent.parent;
  }
  updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
  logTestInfo("testing " + updatedDir.path + " shouldn't exist");
  if (updatedDir.exists()) {
    if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
      do_throw("Exceeded whilst waiting for update dir to not exist");
    else
      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
    return;
  }
  let updateTestDir = getUpdateTestDir();
  let file = updateTestDir.clone();
  file.append("UpdateTestRemoveFile");
  logTestInfo("testing " + file.path + " shouldn't exist");
  do_check_false(file.exists());
  file = updateTestDir.clone();
  file.append("UpdateTestAddFile");
  logTestInfo("testing " + file.path + " should exist");
  do_check_true(file.exists());
  do_check_eq(readFileBytes(file), "UpdateTestAddFile\n");
  file = updateTestDir.clone();
  file.append("removed-files");
  logTestInfo("testing " + file.path + " should exist");
  do_check_true(file.exists());
  do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n");
  let updatesDir = getUpdatesDir();
  log = updatesDir.clone();
  log.append("0");
  log.append(FILE_UPDATE_LOG);
  if (IS_WIN) {
    logTestInfo("testing " + log.path + " should exist");
    do_check_true(log.exists());
  } else {
    logTestInfo("testing " + log.path + " shouldn't exist");
    do_check_false(log.exists());
  }
  log = updatesDir.clone();
  log.append(FILE_LAST_LOG);
  logTestInfo("testing " + log.path + " should exist");
  do_check_true(log.exists());
  log = updatesDir.clone();
  log.append(FILE_BACKUP_LOG);
  logTestInfo("testing " + log.path + " shouldn't exist");
  do_check_false(log.exists());
  updatesDir.append("0");
  logTestInfo("testing " + updatesDir.path + " should exist");
  do_check_true(updatesDir.exists());
  removeCallbackCopy();
}
function checkUpdateFinished ( ) { gTimeoutRuns ++ ; try { let status = readStatusFile ( ) ; if ( status != STATE_SUCCEEDED ) { if ( gTimeoutRuns > MAX_TIMEOUT_RUNS ) do_throw ( "Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to change to succeeded, current status: " + status ) ; else do_timeout ( CHECK_TIMEOUT_MILLI , checkUpdateFinished ) ; return ; } } catch ( e ) { } try { getAppConsoleLogPath ( ) ; } catch ( e ) { if ( e . result == Components . results . NS_ERROR_FILE_IS_LOCKED ) { if ( gTimeoutRuns > MAX_TIMEOUT_RUNS ) do_throw ( "Exceeded whilst waiting for file to be unlocked" ) ; else do_timeout ( CHECK_TIMEOUT_MILLI , checkUpdateFinished ) ; return ; } else { do_throw ( "getAppConsoleLogPath threw: " + e ) ; } } let updatedDir = getAppDir ( ) ; if ( IS_MACOSX ) { updatedDir = updatedDir . parent . parent ; } updatedDir . append ( UPDATED_DIR_SUFFIX . replace ( "/" , "" ) ) ; logTestInfo ( "testing " + updatedDir . path + " shouldn't exist" ) ; if ( updatedDir . exists ( ) ) { if ( gTimeoutRuns > MAX_TIMEOUT_RUNS ) do_throw ( "Exceeded whilst waiting for update dir to not exist" ) ; else do_timeout ( CHECK_TIMEOUT_MILLI , checkUpdateFinished ) ; return ; } let updateTestDir = getUpdateTestDir ( ) ; let file = updateTestDir . clone ( ) ; file . append ( "UpdateTestRemoveFile" ) ; logTestInfo ( "testing " + file . path + " shouldn't exist" ) ; do_check_false ( file . exists ( ) ) ; file = updateTestDir . clone ( ) ; file . append ( "UpdateTestAddFile" ) ; logTestInfo ( "testing " + file . path + " should exist" ) ; do_check_true ( file . exists ( ) ) ; do_check_eq ( readFileBytes ( file ) , "UpdateTestAddFile\n" ) ; file = updateTestDir . clone ( ) ; file . append ( "removed-files" ) ; logTestInfo ( "testing " + file . path + " should exist" ) ; do_check_true ( file . exists ( ) ) ; do_check_eq ( readFileBytes ( file ) , "update_test/UpdateTestRemoveFile\n" ) ; let updatesDir = getUpdatesDir ( ) ; log = updatesDir . clone ( ) ; log . append ( "0" ) ; log . append ( FILE_UPDATE_LOG ) ; if ( IS_WIN ) { logTestInfo ( "testing " + log . path + " should exist" ) ; do_check_true ( log . exists ( ) ) ; } else { logTestInfo ( "testing " + log . path + " shouldn't exist" ) ; do_check_false ( log . exists ( ) ) ; } log = updatesDir . clone ( ) ; log . append ( FILE_LAST_LOG ) ; logTestInfo ( "testing " + log . path + " should exist" ) ; do_check_true ( log . exists ( ) ) ; log = updatesDir . clone ( ) ; log . append ( FILE_BACKUP_LOG ) ; logTestInfo ( "testing " + log . path + " shouldn't exist" ) ; do_check_false ( log . exists ( ) ) ; updatesDir . append ( "0" ) ; logTestInfo ( "testing " + updatesDir . path + " should exist" ) ; do_check_true ( updatesDir . exists ( ) ) ; removeCallbackCopy ( ) ; }
Checks if the update has finished and if it has finished performs checks for
 the test.
Checks if the update has finished and if it has finished performs checks for the test .
// Don't proceed until the update status is no longer applied. // Ignore exceptions if the status file is not found // This will delete the app console log file if it exists. // This might happen on Windows in case the callback application has not // finished its job yet.  So, we'll wait some more. // At this point we need to see if the application was switched successfully. // On Windows, this log file is written to the AppData directory, and will // therefore exist.