tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tests.sh (4562B)


      1 #!/bin/bash
      2 
      3 set -ex
      4 
      5 pwd
      6 
      7 SUITE=${1:-basic}
      8 SUITE=${SUITE//--/}
      9 
     10 export ARTIFACT_DIR=$TASKCLUSTER_ROOT_DIR/builds/worker/artifacts/
     11 mkdir -p "$ARTIFACT_DIR"
     12 
     13 # There's a bug in snapd ~2.60.3-2.61 that will make "snap refresh" fail
     14 # https://bugzilla.mozilla.org/show_bug.cgi?id=1873359
     15 # https://bugs.launchpad.net/snapd/+bug/2048104/comments/13
     16 # 
     17 # So we retrieve the version and we will allow the first "snap refresh" to
     18 # fail for versions < 2.61.1
     19 SNAP_VERSION=$(snap info snapd --color=never --unicode=never |grep "installed:" | awk '{ print $2 }')
     20 SNAP_MAJOR=$(echo "${SNAP_VERSION}" | cut -d'.' -f1)
     21 SNAP_MINOR=$(echo "${SNAP_VERSION}" | cut -d'.' -f2)
     22 SNAP_RELEASE=$(echo "${SNAP_VERSION}" | cut -d'.' -f3)
     23 
     24 REFRESH_CAN_FAIL=true
     25 if [ "${SNAP_MAJOR}" -ge 2 ]; then
     26  if [ "${SNAP_MAJOR}" -gt 2 ]; then
     27    REFRESH_CAN_FAIL=false
     28  else
     29    if [ "${SNAP_MINOR}" -ge 61 ]; then
     30      if [ "${SNAP_MINOR}" -gt 61 ]; then
     31        REFRESH_CAN_FAIL=false
     32      else
     33        if [ "${SNAP_RELEASE}" -gt 0 ]; then
     34          REFRESH_CAN_FAIL=false
     35        fi
     36      fi
     37    fi
     38  fi
     39 fi
     40 
     41 if [ "${REFRESH_CAN_FAIL}" = "true" ]; then
     42  sudo snap refresh || true
     43 else
     44  sudo snap refresh
     45 fi;
     46 
     47 sudo snap refresh --hold=24h firefox
     48 
     49 snap connections firefox
     50 
     51 # Collect existing connections from Snap store
     52 # Replace "firefox" snap name by SNAP_FIREFOX_INSTANCE
     53 (snap connections firefox | grep -v "Interface" | while read -r line; do INT=$(echo "${line}" | awk '{ print $1 }'); CONN=$(echo "${line}" | awk '{ print $2 }' | sed -e 's/firefox:/SNAP_FIREFOX_INSTANCE:/g'); PLUG=$(echo "${line}" | awk '{ print $3 }' | sed -e 's/firefox:/SNAP_FIREFOX_INSTANCE:/g'); echo "${INT};${CONN};${PLUG}"; done) > firefox.connections.txt
     54 cat firefox.connections.txt
     55 
     56 while true; do
     57  if snap changes 2>&1 | grep -E '(Doing|Undoing|Do\s|restarting)'; then
     58    echo wait; sleep 0.5
     59  else
     60    break
     61  fi
     62 done
     63 
     64 export TEST_SNAP_INSTANCE=${TEST_SNAP_INSTANCE:-firefox}
     65 
     66 sudo snap install --name "${TEST_SNAP_INSTANCE}" --dangerous ./firefox.snap
     67 
     68 snap connections "${TEST_SNAP_INSTANCE}"
     69 
     70 (snap connections "${TEST_SNAP_INSTANCE}" | grep -v "Interface" | while read -r line; do INT=$(echo "${line}" | awk '{ print $1 }'); CONN=$(echo "${line}" | awk '{ print $2 }' | sed -e "s/${TEST_SNAP_INSTANCE}:/SNAP_FIREFOX_INSTANCE:/g"); PLUG=$(echo "${line}" | awk '{ print $3 }' | sed -e "s/${TEST_SNAP_INSTANCE}:/SNAP_FIREFOX_INSTANCE:/g"); echo "${INT};${CONN};${PLUG}"; done) > instance.connections.txt
     71 cat instance.connections.txt
     72 
     73 # shellcheck disable=SC2013
     74 for missing_connection in $(grep ';-$' instance.connections.txt);
     75 do
     76  echo "MISSING ${missing_connection}"
     77  KEY="$(echo "$missing_connection" | cut -d';' -f1,2)"
     78  STORE=$(grep "$KEY;" firefox.connections.txt | cut -d';' -f3)
     79  PLUG="$STORE"
     80  if [ "${STORE}" = "-" ] || [ -z "${STORE}" ]; then
     81    echo "NO PREVIOUS STORE CONNECTION FOUND FOR '${KEY}' CHECKING FOR NEW LOCAL"
     82    LOCAL=$(grep "$KEY;" local.connections.txt | cut -d';' -f3)
     83    if [ "${LOCAL}" = "-" ] || [ -z "${LOCAL}" ]; then
     84      echo "NO PREVIOUS STORE NOR LOCAL CONNECTION FOUND FOR '${KEY}'. ABORTING"
     85      continue
     86    else
     87      PLUG="$LOCAL"
     88    fi
     89  fi
     90  CONNECTOR="$(echo "${missing_connection}" | cut -d';' -f2 | sed -e "s/SNAP_FIREFOX_INSTANCE/$TEST_SNAP_INSTANCE/g")"
     91  sudo snap connect "${CONNECTOR}" "${PLUG}"
     92 done;
     93 
     94 snap connections "${TEST_SNAP_INSTANCE}"
     95 
     96 RUNTIME_VERSION=$(snap run firefox --version | awk '{ print $3 }')
     97 
     98 mkdir -p ~/.config/pip/ && cat > ~/.config/pip/pip.conf <<EOF
     99 [global]
    100 break-system-packages = true
    101 EOF
    102 
    103 SNAP_PROFILE_PATH="$HOME/snap/${TEST_SNAP_INSTANCE}/common/.mozilla/firefox/"
    104 if [ ! -d "${SNAP_PROFILE_PATH}" ]; then
    105  mkdir -p "${SNAP_PROFILE_PATH}"
    106 fi
    107 
    108 python3 -m pip install --user -r requirements.txt
    109 
    110 # Required otherwise copy/paste does not work
    111 # Bug 1878643
    112 export TEST_NO_HEADLESS=1
    113 
    114 if [ -n "${MOZ_LOG}" ]; then
    115  export MOZ_LOG_FILE="${ARTIFACT_DIR}/gecko-log"
    116 fi
    117 
    118 RECORD_SCREEN_PID=0
    119 if [ "${TEST_RECORD_SCREEN}" = "true" ]; then
    120  python3 record.py &
    121  RECORD_SCREEN_PID=$!
    122  echo "Recording with PID ${RECORD_SCREEN_PID}"
    123 
    124  trap 'echo [EXIT] Stopping screen recording from PID ${RECORD_SCREEN_PID} && kill ${RECORD_SCREEN_PID}' EXIT
    125  trap 'echo [ERR] Stopping screen recording from PID ${RECORD_SCREEN_PID} && kill ${RECORD_SCREEN_PID}' ERR
    126 fi;
    127 
    128 if [ "${SUITE}" = "basic" ]; then
    129  sed -e "s/#RUNTIME_VERSION#/${RUNTIME_VERSION}/#" < basic_tests/expectations.json.in > basic_tests/expectations.json
    130  python3 basic_tests.py basic_tests/expectations.json
    131 else
    132  python3 "${SUITE}"_tests.py
    133 fi;