1 #!/bin/bash 2 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 7 # Test of the Mac Chrome installer. 8 9 10 # Where I am 11 DIR=$(dirname "${0}") 12 13 # My installer to test 14 INSTALLER="${DIR}"/keystone_install.sh 15 if [ ! -f "${INSTALLER}" ]; then 16 echo "Can't find scripts." >& 2 17 exit 1 18 fi 19 20 # What I test 21 PRODNAME="Google Chrome" 22 APPNAME="${PRODNAME}.app" 23 FWKNAME="${PRODNAME} Framework.framework" 24 25 # The version number for fake ksadmin to pretend to be 26 KSADMIN_VERSION_LIE="1.0.7.1306" 27 28 # Temp directory to be used as the disk image (source) 29 TEMPDIR=$(mktemp -d -t $(basename ${0})) 30 PATH=$PATH:"${TEMPDIR}" 31 32 # Clean up the temp directory 33 function cleanup_tempdir() { 34 chmod u+w "${TEMPDIR}" 35 rm -rf "${TEMPDIR}" 36 } 37 38 # Run the installer and make sure it fails. 39 # If it succeeds, we fail. 40 # Arg0: string to print 41 function fail_installer() { 42 echo $1 43 "${INSTALLER}" "${TEMPDIR}" >& /dev/null 44 RETURN=$? 45 if [ $RETURN -eq 0 ]; then 46 echo "Did not fail (which is a failure)" >& 2 47 cleanup_tempdir 48 exit 1 49 else 50 echo "Returns $RETURN" 51 fi 52 } 53 54 # Make sure installer works! 55 # Arg0: string to print 56 function pass_installer() { 57 echo $1 58 "${INSTALLER}" "${TEMPDIR}" >& /dev/null 59 RETURN=$? 60 if [ $RETURN -ne 0 ]; then 61 echo "FAILED; returned $RETURN but should have worked" >& 2 62 cleanup_tempdir 63 exit 1 64 else 65 echo "worked" 66 fi 67 } 68 69 # Make an old-style destination directory, to test updating from old-style 70 # versions to new-style versions. 71 function make_old_dest() { 72 DEST="${TEMPDIR}"/Dest.app 73 rm -rf "${DEST}" 74 mkdir -p "${DEST}"/Contents 75 defaults write "${DEST}/Contents/Info" KSVersion 0 76 cat >"${TEMPDIR}"/ksadmin <<EOF 77 #!/bin/sh 78 if [ "\${1}" = "--ksadmin-version" ] ; then 79 echo "${KSADMIN_VERSION_LIE}" 80 exit 0 81 fi 82 if [ -z "\${FAKE_SYSTEM_TICKET}" ] && [ "\${1}" = "-S" ] ; then 83 echo no system tix! >& 2 84 exit 1 85 fi 86 echo " xc=<KSPathExistenceChecker:0x45 path=${DEST}>" 87 exit 0 88 EOF 89 chmod u+x "${TEMPDIR}"/ksadmin 90 } 91 92 # Make a new-style destination directory, to test updating between new-style 93 # versions. 94 function make_new_dest() { 95 DEST="${TEMPDIR}"/Dest.app 96 rm -rf "${DEST}" 97 defaults write "${DEST}/Contents/Info" CFBundleShortVersionString 0 98 defaults write "${DEST}/Contents/Info" KSVersion 0 99 cat >"${TEMPDIR}"/ksadmin <<EOF 100 #!/bin/sh 101 if [ "\${1}" = "--ksadmin-version" ] ; then 102 echo "${KSADMIN_VERSION_LIE}" 103 exit 0 104 fi 105 if [ -z "\${FAKE_SYSTEM_TICKET}" ] && [ "\${1}" = "-S" ] ; then 106 echo no system tix! >& 2 107 exit 1 108 fi 109 echo " xc=<KSPathExistenceChecker:0x45 path=${DEST}>" 110 exit 0 111 EOF 112 chmod u+x "${TEMPDIR}"/ksadmin 113 } 114 115 # Make a simple source directory - the update that is to be applied 116 function make_src() { 117 chmod ugo+w "${TEMPDIR}" 118 rm -rf "${TEMPDIR}/${APPNAME}" 119 RSRCDIR="${TEMPDIR}/${APPNAME}/Contents/Versions/1/${FWKNAME}/Resources" 120 mkdir -p "${RSRCDIR}" 121 defaults write "${TEMPDIR}/${APPNAME}/Contents/Info" \ 122 CFBundleShortVersionString "1" 123 defaults write "${TEMPDIR}/${APPNAME}/Contents/Info" \ 124 KSProductID "com.google.Chrome" 125 defaults write "${TEMPDIR}/${APPNAME}/Contents/Info" \ 126 KSVersion "2" 127 } 128 129 function make_basic_src_and_dest() { 130 make_src 131 make_new_dest 132 } 133 134 fail_installer "No source anything" 135 136 mkdir "${TEMPDIR}"/"${APPNAME}" 137 fail_installer "No source bundle" 138 139 make_basic_src_and_dest 140 chmod ugo-w "${TEMPDIR}" 141 fail_installer "Writable dest directory" 142 143 make_basic_src_and_dest 144 fail_installer "Was no KSUpdateURL in dest after copy" 145 146 make_basic_src_and_dest 147 defaults write "${TEMPDIR}/${APPNAME}/Contents/Info" KSUpdateURL "http://foobar" 148 export FAKE_SYSTEM_TICKET=1 149 fail_installer "User and system ticket both present" 150 export -n FAKE_SYSTEM_TICKET 151 152 make_src 153 make_old_dest 154 defaults write "${TEMPDIR}/${APPNAME}/Contents/Info" KSUpdateURL "http://foobar" 155 pass_installer "Old-style update" 156 157 make_basic_src_and_dest 158 defaults write "${TEMPDIR}/${APPNAME}/Contents/Info" KSUpdateURL "http://foobar" 159 pass_installer "ALL" 160 161 cleanup_tempdir 162