diff --git a/.travis.yml b/.travis.yml index a5eacafc5f4b..ff1d674bb72b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ language: python python: - "2.7" -cache: pip +cache: + directories: + - $HOME/.cache/pip addons: apt: packages: diff --git a/install-dev-dependencies.sh b/install-dev-dependencies.sh index 6646c50ce4d4..110b57770cf3 100755 --- a/install-dev-dependencies.sh +++ b/install-dev-dependencies.sh @@ -32,7 +32,7 @@ pip install --user --no-allow-insecure --no-allow-external -r requirements.txt cd https-everywhere-checker pip install --user -r requirements.txt cd - -cd test/chrome +cd test/chromium pip install --user -r requirements.txt cd - diff --git a/test.sh b/test.sh index 3a255e25b36d..441bd3557157 100755 --- a/test.sh +++ b/test.sh @@ -3,10 +3,16 @@ # Get into the project-root. This script may be executed as `test.sh` # or as .git/hooks/pre-push, so we need to find the directory containing -# test.sh before we can proceed. If $0 is not a symlink, `readlink` will -# print nothing; if it is a symlink it will print the link target. +# test.sh before we can proceed. -cd $(dirname $0)/$(dirname $(readlink $0)) +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi ./test/rules.sh ./test/firefox.sh $@ diff --git a/test/chromium.sh b/test/chromium.sh index 23c439f19129..e3d76b73f954 100755 --- a/test/chromium.sh +++ b/test/chromium.sh @@ -1,15 +1,16 @@ -#!/bin/bash +#!/bin/bash -ex # Run Chromium tests for HTTPS Everywhere -# -# Get into the project-root. This script may be executed as `chromium.sh` -# or as ./test/chromium.sh, so we need to find the directory -# containing firefox.sh before we can proceed. If $0 is not a symlink, -# `readlink` will print nothing; if it is a symlink it will print the -# link target. -set -o errexit -o xtrace +# Get to the repo root directory, even when we're symlinked as a hook. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi -cd $(dirname $0)/$(dirname $(readlink $0))../ # If you just want to run Chromium with the latest code: if [ "$1" == "--justrun" ]; then diff --git a/test/chromium/script.py b/test/chromium/script.py index 5f9e6e44031a..78cc693c5169 100644 --- a/test/chromium/script.py +++ b/test/chromium/script.py @@ -15,52 +15,61 @@ from selenium.common.exceptions import WebDriverException class bcolors: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + chromeOps = webdriver.ChromeOptions() chromeOps.add_extension(sys.argv[1]) -chromeOps.add_argument("--disable-setuid-sandbox") -chromdriver_path = "chromedriver" +if 'TRAVIS' in os.environ.keys(): + # For TravisCI, we manually copy chromedriver to the local path. + chromedriver_path = os.path.abspath("test/chromium/chromedriver") -if 'TRAVIS' in os.environ: - chromeOps.add_argument('--no-sandbox') - chromdriver_path = os.path.abspath("test/chromium/chromedriver") + # Travis has setuid restrictions. I think this becomes unnecessary in M42+? + chromeOps.add_argument('--disable-setuid-sandbox') +elif sys.platform.startswith("linux"): + chromedriver_path = "/usr/lib/chromium-browser/chromedriver" +else: + # Let's hope it's in the user's path. + chromedriver_path = "chromedriver" -# First argument is optional, if not specified will search path. try: - driver = webdriver.Chrome(chromdriver_path, chrome_options=chromeOps) + # First argument is optional, if not specified will search path. + driver = webdriver.Chrome(chromedriver_path, chrome_options=chromeOps) except WebDriverException as e: - error = e.__str__() + error = e.__str__() - if "executable needs to be in PATH" in e.__str__(): - print "ChromeDriver isn't installed. Check test/chrome/README.md\ -for instructions on how to install ChromeDriver" + if "executable needs to be in PATH" in e.__str__(): + print "ChromeDriver isn't installed. Check test/chrome/README.md " \ + "for instructions on how to install ChromeDriver" - sys.exit(2) - else: - raise e + sys.exit(2) + else: + raise e -print '' #New line +print '' driver.get('http://libssh.org/robots.txt') -#Page Loaded - +test_failed = False if driver.current_url.startswith('https'): - print bcolors.OKGREEN + "HTTP to HTTPS redirection successful" + bcolors.ENDC + print bcolors.OKGREEN + "Chromium: HTTP to HTTPS redirection successful" + bcolors.ENDC elif driver.current_url.startswith('http'): - print bcolors.FAIL + "HTTP to HTTPS redirection failed" + bcolors.ENDC - sys.exit(1) + print bcolors.FAIL + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC + test_failed = True -print '' #New line +print '' driver.quit() + + +if test_failed: + sys.exit(1) diff --git a/test/firefox.sh b/test/firefox.sh index 67758dc2fbd9..3856a5c01d3c 100755 --- a/test/firefox.sh +++ b/test/firefox.sh @@ -1,12 +1,16 @@ #!/bin/bash -ex # Run Firefox tests for HTTPS Everywhere -# -# Get into the project-root. This script may be executed as `firefox.sh` -# or as ./test/firefox.sh, so we need to find the directory containing -# firefox.sh before we can proceed. If $0 is not a symlink, `readlink` -# will print nothing; if it is a symlink it will print the link target. -cd $(dirname $0)/$(dirname $(readlink $0))../ +# Get to the repo root directory, even when we're symlinked as a hook. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi + source utils/mktemp.sh diff --git a/test/rules.sh b/test/rules.sh index cac08eec3d62..2e2286496088 100755 --- a/test/rules.sh +++ b/test/rules.sh @@ -1,10 +1,18 @@ -#!/bin/bash +#!/bin/bash -ex # # Test that all rulesets modified after a certain date have sufficient test # coverage, according to the ruleset checker. # -cd $(dirname $0)/$(dirname $(readlink $0))../ +# Get to the repo root directory, even when we're symlinked as a hook. +if [ -n "$GIT_DIR" ] +then + # $GIT_DIR is set, so we're running as a hook. + cd $GIT_DIR +else + # Git command exists? Cool, let's CD to the right place. + git rev-parse && cd "$(git rev-parse --show-toplevel)" +fi source utils/mktemp.sh