diff --git a/.gitmodules b/.gitmodules index 8cebe79c8fff..049bbbed911c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "addon-sdk"] - path = addon-sdk - url = https://github.com/mozilla/addon-sdk.git [submodule "translations"] path = translations url = https://git.torproject.org/translation.git diff --git a/addon-sdk b/addon-sdk deleted file mode 160000 index 12f7d53e8b5f..000000000000 --- a/addon-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 12f7d53e8b5fc015a15fa4a30fa588e81e9e9b2e diff --git a/install-dev-dependencies.sh b/install-dev-dependencies.sh index d933b579cb41..9ce7446491be 100755 --- a/install-dev-dependencies.sh +++ b/install-dev-dependencies.sh @@ -20,7 +20,15 @@ if type apt-get >/dev/null ; then # In Debian, `python-` is assumed to be python 2.7, no need to specify - dkg $SUDO_SHIM apt-get install libxml2-dev libxml2-utils libxslt1-dev \ python-dev $BROWSERS zip sqlite3 python-pip libcurl4-openssl-dev xvfb \ - libssl-dev git $CHROMEDRIVER + libssl-dev git curl $CHROMEDRIVER + if ! type geckodriver >/dev/null; then + curl -LO "https://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-linux64.tar.gz" + tar -zxvf "geckodriver-v0.16.1-linux64.tar.gz" + rm -f "geckodriver-v0.16.1-linux64.tar.gz" + $SUDO_SHIM mv geckodriver /usr/bin/geckodriver + $SUDO_SHIM chown root /usr/bin/geckodriver + $SUDO_SHIM chmod 755 /usr/bin/geckodriver + fi elif type brew >/dev/null ; then brew list python &>/dev/null || brew install python brew install libxml2 gnu-sed chromedriver @@ -42,9 +50,16 @@ elif type dnf >/dev/null ; then rm -f "chromedriver_linux$ARCH.zip" $SUDO_SHIM mv chromedriver /usr/bin/chromedriver $SUDO_SHIM chown root /usr/bin/chromedriver - $SUDO_SHIM chmod +x /usr/bin/chromedriver $SUDO_SHIM chmod 755 /usr/bin/chromedriver fi + if ! type geckodriver >/dev/null; then + curl -LO "https://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-macos.tar.gz" + tar -zxvf "geckodriver-v0.16.1-macos.tar.gz" + rm -f "geckodriver-v0.16.1-macos.tar.gz" + $SUDO_SHIM mv geckodriver /usr/bin/geckodriver + $SUDO_SHIM chown root /usr/bin/geckodriver + $SUDO_SHIM chmod 755 /usr/bin/geckodriver + fi # This is needed for Firefox on some systems. See here for more information: # https://github.com/EFForg/https-everywhere/pull/5584#issuecomment-238655443 if [ ! -f /var/lib/dbus/machine-id ]; then diff --git a/test/chromium.sh b/test/chromium.sh index e03696cf881e..29fdc3110dea 100755 --- a/test/chromium.sh +++ b/test/chromium.sh @@ -39,5 +39,5 @@ else ./makecrx.sh echo "running tests" CRX_NAME="`ls -tr pkg/*.crx | tail -1`" - $XVFB_RUN python2.7 test/chromium/script.py $CRX_NAME + $XVFB_RUN python2.7 test/script.py Chrome $CRX_NAME fi diff --git a/test/chromium/script.py b/test/chromium/script.py deleted file mode 100644 index ff76d6d0fc2c..000000000000 --- a/test/chromium/script.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python2.7 -# -# Run Chromium tests for HTTPS Everywhere -# -# This script may be executed as `python script.py [directory of CRX]` -# -# The script is compatible with Python 2. Python 3 is not tested. -# Selenium, WebDriver and Google Chrome (or Chromium) must be installed -# in order for the script to run successfully. A desktop version -# of linux is required for the script to run correctly as well. -# Otherwise, use pyvirtualdisplay. - -import sys, os, platform -from selenium import webdriver -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' - - -chromeOps = webdriver.ChromeOptions() -chromeOps.add_extension(sys.argv[1]) -if os.getuid() == 0: - chromeOps.add_argument("--no-sandbox") - -# Find the path to chromedriver -chromedriver_path = "chromedriver" -if sys.platform.startswith("linux"): - if 'Ubuntu' in platform.linux_distribution(): - chromedriver_path = "/usr/lib/chromium-browser/chromedriver" - elif 'debian' in platform.linux_distribution(): - #Debian is lowercase when platform.linux_distribution() is used. - #This is not a mistake. - chromedriver_path = "/usr/lib/chromium/chromedriver" - -try: - # 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__() - - if "executable needs to be in PATH" in e.__str__(): - print "ChromeDriver isn't installed. Check test/chromium/README.md " \ - "for instructions on how to install ChromeDriver" - - sys.exit(2) - else: - raise e - -print '' - -driver.get('http://libssh.org/robots.txt') - -test_failed = False -if driver.current_url.startswith('https'): - print bcolors.OKGREEN + "Chromium: HTTP to HTTPS redirection successful" + bcolors.ENDC -elif driver.current_url.startswith('http'): - print bcolors.FAIL + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC - test_failed = True - -print '' - -driver.quit() - -if test_failed: - sys.exit(1) diff --git a/test/firefox.sh b/test/firefox.sh index 0ff398cf1b81..9e97b00db7de 100755 --- a/test/firefox.sh +++ b/test/firefox.sh @@ -14,9 +14,6 @@ fi source utils/mktemp.sh -# dummy Jetpack addon that contains tests -TEST_ADDON_PATH=./test/firefox/ - # We'll create a Firefox profile here and install HTTPS Everywhere into it. PROFILE_DIRECTORY="$(mktemp -d)" trap 'rm -r "$PROFILE_DIRECTORY"' EXIT @@ -38,10 +35,6 @@ die() { exit 1 } -if [ ! -f "addon-sdk/bin/activate" ]; then - die "Addon SDK not available. Run git submodule update." -fi - if [ ! -d "$HTTPSE_INSTALL_DIRECTORY" ]; then die "Firefox profile does not have HTTPS Everywhere installed" fi @@ -51,17 +44,6 @@ if [ -z "$XVFB_RUN" -a -n "$(which xvfb-run)" ]; then XVFB_RUN=xvfb-run fi -# Activate the Firefox Addon SDK. -pushd addon-sdk -source bin/activate -popd - -if ! type cfx > /dev/null; then - die "Addon SDK failed to activiate." -fi - -pushd $TEST_ADDON_PATH - # If you just want to run Firefox with the latest code: if [ "$1" == "--justrun" ]; then echo "running firefox" @@ -73,14 +55,11 @@ if [ "$1" == "--justrun" ]; then fi else echo "running tests" + + PATH=/home/user/geckodriver:$PATH if [ -n "$FIREFOX" ]; then - $XVFB_RUN cfx test -b $FIREFOX --profiledir="$PROFILE_DIRECTORY" --verbose + $XVFB_RUN python2.7 test/script.py Firefox "$PROFILE_DIRECTORY" $FIREFOX else - $XVFB_RUN cfx test --profiledir="$PROFILE_DIRECTORY" --verbose + $XVFB_RUN python2.7 test/script.py Firefox "$PROFILE_DIRECTORY" fi fi - -popd - -shasum=$(openssl sha -sha256 "$XPI_NAME") -echo -e "Git commit `git rev-parse HEAD`\n$shasum" diff --git a/test/firefox/lib/main.js b/test/firefox/lib/main.js deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/firefox/package.json b/test/firefox/package.json deleted file mode 100644 index 90d35bce79ee..000000000000 --- a/test/firefox/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "https-everywhere-tests", - "title": "https-everywhere-tests", - "id": "jid1-we5BQOfc6skSMg", - "description": "a basic add-on", - "author": "", - "license": "MPL 2.0", - "version": "0.1" -} diff --git a/test/firefox/test/test-httpse-installed.js b/test/firefox/test/test-httpse-installed.js deleted file mode 100644 index be2fe9709d54..000000000000 --- a/test/firefox/test/test-httpse-installed.js +++ /dev/null @@ -1,38 +0,0 @@ -// Test that HTTPS Everywhere component is installed and accessible - -const { Cc, Ci } = require("chrome"); -var tabs = require("sdk/tabs"); - -let HTTPSEverywhere = Cc["@eff.org/https-everywhere;1"] - .getService(Ci.nsISupports) - .wrappedJSObject; - -exports["test httpse installed"] = function(assert) { - assert.equal(typeof HTTPSEverywhere, "object", - "Test that HTTPSEverywhere is defined"); - assert.equal(typeof HTTPSEverywhere.observe, "function", - "Test that HTTPSEverywhere.observe is a function"); -}; - -exports["test httpse potentiallyApplicableRulesets"] = function(assert) { - let HTTPSRules = HTTPSEverywhere.https_rules; - assert.deepEqual(HTTPSRules.potentiallyApplicableRulesets("www.wikia.com").length, - 1, - "Test that HTTPSE finds one applicable rule for www.wikia.com"); -} - -exports["test sample ruleset"] = function(assert, done) { - tabs.open({ - url: "http://www.freerangekitten.com/", - onOpen: function(tab) { - tab.on('load', function(tab) { - assert.equal(tab.url, "https://www.freerangekitten.com/", - "Test that URLs are rewritten to HTTPS."); - tab.close(); - done(); - }); - } - }); -} - -require("sdk/test").run(exports); diff --git a/test/firefox/test/test-main.js b/test/firefox/test/test-main.js deleted file mode 100644 index 147f98adfafe..000000000000 --- a/test/firefox/test/test-main.js +++ /dev/null @@ -1,12 +0,0 @@ -var main = require("./main"); - -exports["test main"] = function(assert) { - assert.pass("Unit test running!"); -}; - -exports["test main async"] = function(assert, done) { - assert.pass("async Unit test running!"); - done(); -}; - -require("sdk/test").run(exports); diff --git a/test/firefox/test_profile_skeleton/extensions.ini b/test/firefox/test_profile_skeleton/extensions.ini deleted file mode 100644 index a0ca1c2d30e8..000000000000 --- a/test/firefox/test_profile_skeleton/extensions.ini +++ /dev/null @@ -1,7 +0,0 @@ -[ExtensionDirs] -Extension0=/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/ubufox@ubuntu.com -Extension1=/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/{2e1445b0-2682-11e1-bfc2-0800200c9a66} -Extension2=/usr/lib/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/online-accounts@lists.launchpad.net - -[ThemeDirs] -Extension0=/usr/lib/firefox/browser/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd} diff --git a/test/script.py b/test/script.py new file mode 100644 index 000000000000..ec53abd71554 --- /dev/null +++ b/test/script.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python2.7 +# +# Run Selenium tests for HTTPS Everywhere +# +# This script may be executed as `python script.py [directory of CRX]` +# +# The script is compatible with Python 2. Python 3 is not tested. +# Selenium, WebDriver and Google Chrome (or Chromium) must be installed +# in order for the script to run successfully. A desktop version +# of linux is required for the script to run correctly as well. +# Otherwise, use pyvirtualdisplay. + +import sys, os, platform, time +from selenium import webdriver +from selenium.common.exceptions import WebDriverException +from selenium.webdriver.firefox.firefox_binary import FirefoxBinary + +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' + + +if sys.argv[1] == "Chrome": + chromeOps = webdriver.ChromeOptions() + chromeOps.add_extension(sys.argv[2]) + if os.getuid() == 0: + chromeOps.add_argument("--no-sandbox") + + # Find the path to chromedriver + chromedriver_path = "chromedriver" + if sys.platform.startswith("linux"): + if 'Ubuntu' in platform.linux_distribution(): + chromedriver_path = "/usr/lib/chromium-browser/chromedriver" + elif 'debian' in platform.linux_distribution(): + #Debian is lowercase when platform.linux_distribution() is used. + #This is not a mistake. + chromedriver_path = "/usr/lib/chromium/chromedriver" + + try: + # 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__() + + if "executable needs to be in PATH" in e.__str__(): + print "ChromeDriver isn't installed. Check test/chromium/README.md " \ + "for instructions on how to install ChromeDriver" + + sys.exit(2) + else: + raise e + +if sys.argv[1] == "Firefox": + fp = webdriver.FirefoxProfile(sys.argv[2]) + try: + if len(sys.argv) == 4: + binary = FirefoxBinary(sys.argv[3]) + driver = webdriver.Firefox(fp, firefox_binary=binary, log_path=os.devnull) + else: + driver = webdriver.Firefox(fp, log_path=os.devnull) + except WebDriverException as e: + error = e.__str__() + + if "executable needs to be in PATH" in e.__str__(): + print "GeckoDriver isn't installed. Check test/firefox/README.md " \ + "for instructions on how to install GeckoDriver" + + sys.exit(2) + else: + raise e + + # Allow the extension time to load + time.sleep(1) + +print '' + +driver.get('http://freerangekitten.com') + +test_failed = False +if driver.current_url.startswith('https'): + print bcolors.OKGREEN + sys.argv[1] + ": HTTP to HTTPS redirection successful" + bcolors.ENDC +elif driver.current_url.startswith('http'): + print bcolors.FAIL + sys.argv[1] + ": HTTP to HTTPS redirection failed" + bcolors.ENDC + test_failed = True + +print '' + +driver.quit() + +if test_failed: + sys.exit(1)