Skip to content

Commit e517a49

Browse files
authored
Merge pull request #1168 from cowlicks/selenium
Selenium tests in Firefox
2 parents 64843e4 + bc624a6 commit e517a49

15 files changed

+334
-240
lines changed

.travis.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ matrix:
1313
fast_finish: true
1414
include:
1515
- python: "2.7"
16-
env: CHROME="google-chrome-stable"
16+
env: BROWSER="google-chrome-stable"
1717
- python: "3.4"
18-
env: CHROME="google-chrome-stable"
18+
env: BROWSER="google-chrome-stable"
1919
- python: "2.7"
20-
env: CHROME_PATH="google-chrome-beta"
20+
env: BROWSER="google-chrome-beta"
21+
- python: "2.7"
22+
env: BROWSER="firefox"
2123
allow_failures:
2224
- python: "2.7"
23-
env: CHROME_PATH="google-chrome-beta"
25+
env: BROWSER="google-chrome-beta"
2426
exclude:
2527
- env: TRAVIS_EXTRA_JOB_WORKAROUND=true
2628
addons:
2729
apt:
2830
sources:
2931
- google-chrome
3032
packages:
33+
- firefox
3134
- google-chrome-stable
3235
- google-chrome-beta
3336
- python-virtualenv

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Developer tools for Privacy Badger for Chrome.",
55
"dependencies": {
66
"eslint": "~3.3.1",
7-
"web-ext": "~1.6.0"
7+
"web-ext": "^1.7.0"
88
},
99
"private": true
1010
}

scripts/setup_travis.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ wget -O /tmp/chromedriver.zip "https://chromedriver.storage.googleapis.com/${lat
66
sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
77
sudo chmod a+x /usr/local/bin/chromedriver
88

9+
# Install geckodriver
10+
wget -O /tmp/geckodriver.tar.gz "https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux64.tar.gz"
11+
sudo tar -xvf /tmp/geckodriver.tar.gz -C /usr/local/bin/
12+
sudo chmod a+x /usr/local/bin/geckodriver
13+
914
# Set the path to the browser binary we want to test against
10-
export BROWSER_BIN=`which ${CHROME_PATH}`
15+
export BROWSER_BIN=`which ${BROWSER}`

scripts/updatepsl.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
# Update the Public Suffix List (psl)
23

34
# stop on errors (nonzero exit codes), uninitialized vars
45
set -eu

tests/firefox_selenium.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# web-ext uses these to launch and install the browser
5+
export WEB_EXT_SOURCE_DIR=`dirname $PWD`
6+
export WEB_EXT_PREF="marionette.defaultPrefs.enabled=true"
7+
export WEB_EXT_FIREFOX="/usr/bin/firefox"
8+
9+
../node_modules/web-ext/bin/web-ext run &
10+
ext_PID=$!
11+
sleep 0.5
12+
13+
geckodriver --connect-existing --marionette-port 2828 &
14+
gecko_PID=$!
15+
16+
cleanstuff () {
17+
kill $gecko_PID
18+
kill $ext_PID
19+
}
20+
21+
trap cleanstuff EXIT
22+
wait

tests/run_selenium_tests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
command -v chromedriver >/dev/null 2>&1 || { echo >&2 "Cannot find chromedriver in PATH. Aborting."; exit 1; }
32

43
pushd .
54
cd ..
@@ -8,6 +7,7 @@ if [ $? != 0 ]; then
87
echo "Linting errors"
98
exit 1
109
fi
10+
1111
make travisbuild # pack the extension
1212
ext_path=`ls -1tr $PWD/*.crx | tail -n 1` # get the last modified crx
1313
popd
@@ -16,11 +16,16 @@ popd
1616
# virtualenv PBTESTENV
1717
# source PBTESTENV/bin/activate
1818
pip install -r sel_requirements.txt
19+
if [ $BROWSER == "firefox" ]; then
20+
# only needed for ff, and only works for python 2
21+
pip install marionette_driver
22+
fi
1923

2024
# TODO: take command line arguments to set the following environment variables
2125
export PB_EXT_PATH=$ext_path # extension on this path will be used in the tests
2226
# if this var is empty, extension base dir will be searched for the last modified .crx.
23-
echo "Chrome path: "$BROWSER_BIN
27+
echo "Browesr path: "$BROWSER_BIN
28+
echo "Extension path: "$PB_EXT_PATH
2429
# export BROWSER_BIN="/path/to/chrome" # Optional.
2530
# If BROWSER_BIN is empty, Selenium will pick the default binary for Chrome.
2631
# To run tests with Chromium (instead of Google Chrome) export BROWSER_BIN="/usr/bin/chromium-browser"

tests/selenium/cookie_test.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515

1616
import window_utils
1717

18-
PB_CHROME_SITE1_URL = "http://eff-tracker-site1-test.s3-website-us-west-2.amazonaws.com"
19-
PB_CHROME_SITE2_URL = "http://eff-tracker-site2-test.s3-website-us-west-2.amazonaws.com"
20-
PB_CHROME_SITE3_URL = "http://eff-tracker-site3-test.s3-website-us-west-2.amazonaws.com"
18+
SITE1_URL = "http://eff-tracker-site1-test.s3-website-us-west-2.amazonaws.com"
19+
SITE2_URL = "http://eff-tracker-site2-test.s3-website-us-west-2.amazonaws.com"
20+
SITE3_URL = "http://eff-tracker-site3-test.s3-website-us-west-2.amazonaws.com"
2121

22-
PB_CHROME_THIRD_PARTY_TRACKER = "eff-tracker-test.s3-website-us-west-2.amazonaws.com"
22+
THIRD_PARTY_TRACKER = "eff-tracker-test.s3-website-us-west-2.amazonaws.com"
2323

24-
PB_CHROME_PU_URL = pbtest.PB_EXT_BG_URL_BASE + "skin/popup.html"
25-
PB_CHROME_FR_URL = pbtest.PB_EXT_BG_URL_BASE + "skin/firstRun.html"
2624

2725
class CookieTest(pbtest.PBSeleniumTest):
2826
"""Basic test to make sure the PB doesn't mess up with the cookies."""
@@ -50,42 +48,41 @@ def FIXMEtest_cookie_tracker_detection(self):
5048
# fixme: check for chrome settings for third party cookies?
5149

5250
# load the first site with the third party code that reads and writes a cookie
53-
self.load_url( PB_CHROME_SITE1_URL )
54-
#window_utils.close_windows_with_url( self.driver, PB_CHROME_FR_URL )
55-
self.load_pb_ui( PB_CHROME_SITE1_URL )
51+
self.load_url( SITE1_URL )
52+
self.load_pb_ui( SITE1_URL )
5653
self.get_tracker_state()
57-
self.assertTrue( self.nonTrackers.has_key( PB_CHROME_THIRD_PARTY_TRACKER ) )
54+
self.assertTrue( self.nonTrackers.has_key( THIRD_PARTY_TRACKER ) )
5855

5956
# go to second site
60-
self.load_url( PB_CHROME_SITE2_URL )
61-
window_utils.close_windows_with_url( self.driver, PB_CHROME_SITE1_URL )
62-
self.load_pb_ui( PB_CHROME_SITE2_URL )
57+
self.load_url( SITE2_URL )
58+
window_utils.close_windows_with_url( self.driver, SITE1_URL )
59+
self.load_pb_ui( SITE2_URL )
6360
self.get_tracker_state()
64-
self.assertTrue( self.nonTrackers.has_key( PB_CHROME_THIRD_PARTY_TRACKER ) )
61+
self.assertTrue( self.nonTrackers.has_key( THIRD_PARTY_TRACKER ) )
6562

6663
# go to third site
67-
self.load_url( PB_CHROME_SITE3_URL )
68-
window_utils.close_windows_with_url( self.driver, PB_CHROME_SITE2_URL )
69-
self.load_pb_ui( PB_CHROME_SITE3_URL )
64+
self.load_url( SITE3_URL )
65+
window_utils.close_windows_with_url( self.driver, SITE2_URL )
66+
self.load_pb_ui( SITE3_URL )
7067
self.get_tracker_state()
71-
self.assertTrue( self.nonTrackers.has_key( PB_CHROME_THIRD_PARTY_TRACKER ) )
68+
self.assertTrue( self.nonTrackers.has_key( THIRD_PARTY_TRACKER ) )
7269

7370
# reloading the first site should now cause the cookie to be blocked
7471
# it can take a long time for the UI to be updated, so retry a number of
7572
# times before giving up. See bug #702.
7673
print("this is checking for a dnt file at a site without https, so we'll just have to wait for the connection to timeout before we proceed")
77-
self.load_url( PB_CHROME_SITE1_URL )
78-
window_utils.close_windows_with_url( self.driver, PB_CHROME_SITE3_URL )
74+
self.load_url( SITE1_URL )
75+
window_utils.close_windows_with_url( self.driver, SITE3_URL )
7976
for i in range(60):
80-
self.load_pb_ui( PB_CHROME_SITE1_URL )
77+
self.load_pb_ui( SITE1_URL )
8178
self.get_tracker_state()
82-
if self.cookieBlocked.has_key( PB_CHROME_THIRD_PARTY_TRACKER ):
79+
if self.cookieBlocked.has_key( THIRD_PARTY_TRACKER ):
8380
print("Popup UI has been updated. Yay!")
8481
break
85-
window_utils.close_windows_with_url( self.driver, PB_CHROME_PU_URL )
82+
window_utils.close_windows_with_url( self.driver, self.popup_url)
8683
print("popup UI has not been updated yet. try again in 10 seconds")
8784
time.sleep(10)
88-
self.assertTrue( self.cookieBlocked.has_key( PB_CHROME_THIRD_PARTY_TRACKER ) )
85+
self.assertTrue( self.cookieBlocked.has_key( THIRD_PARTY_TRACKER ) )
8986

9087
def load_pb_ui(self, target_scheme_and_host ):
9188
"""Show the PB popup as a new tab.
@@ -113,10 +110,10 @@ def load_pb_ui(self, target_scheme_and_host ):
113110
button = self.driver.find_element_by_id("newwindowbutton")
114111
button.click()
115112
window_utils.switch_to_window_with_url( self.driver, "about:blank" )
116-
self.load_url(PB_CHROME_PU_URL)
113+
self.load_url(self.popup_url)
117114

118115
# use the new convenience function to get the popup populated with status information for the correct url
119-
window_utils.switch_to_window_with_url( self.driver, PB_CHROME_PU_URL )
116+
window_utils.switch_to_window_with_url(self.driver, self.popup_url)
120117
target_url = target_scheme_and_host + "/*"
121118
javascript_src = "setTabToUrl('" + target_url + "');"
122119
self.js( javascript_src )

tests/selenium/localstorage_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def check_policy_download(self):
4141
self.assertEqual(PB_POLICY_HASH_LEN, len(policy_hash))
4242

4343
def test_should_init_local_storage_entries(self):
44-
self.load_url(pbtest.PB_CHROME_BG_URL, wait_on_site=3)
44+
self.load_url(self.bg_url, wait_on_site=3)
4545
js = self.js
4646
self.check_policy_download()
4747
self.assertEqual(js("return constants.COOKIE_BLOCK_LIST_URL"),

tests/selenium/options_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env python
22
# -*- coding: UTF-8 -*-
33

4+
import os
45
import unittest
5-
import pbtest
6+
67
from selenium.webdriver.common.action_chains import ActionChains
78
from selenium.webdriver.support.ui import WebDriverWait
89
from selenium.webdriver.support import expected_conditions as EC
910
from selenium.webdriver.common.by import By
1011
from selenium.common.exceptions import NoSuchElementException, TimeoutException
1112

13+
import pbtest
1214

1315
class OptionsPageTest(pbtest.PBSeleniumTest):
1416
"""Make sure the options page works correctly."""
@@ -22,8 +24,8 @@ def hide_tooltip(self, css_selector):
2224
(By.CSS_SELECTOR, css_selector)))
2325

2426
def load_options_page(self):
25-
self.load_url(pbtest.PB_CHROME_BG_URL) # load a dummy page
26-
self.load_url(pbtest.PB_CHROME_OPTIONS_PAGE_URL, wait_on_site=1)
27+
self.load_url(self.bg_url) # load a dummy page
28+
self.load_url(self.options_url, wait_on_site=1)
2729

2830
def add_test_origin(self, origin, action):
2931
"""Add given origin to backend storage."""
@@ -42,6 +44,9 @@ def test_page_title(self):
4244
" expected (%s)"
4345
% (self.driver.title, localized_title))
4446

47+
48+
@unittest.skipIf(os.environ.get('BROWSER') == 'firefox',
49+
"selenium move_to is currently broken in firefox")
4550
def test_should_display_tooltips_on_hover(self):
4651
driver = self.driver
4752
find_el_by_css = self.find_el_by_css # find with WebDriver wait
@@ -109,7 +114,7 @@ def test_removed_origin_display(self):
109114
"""Ensure origin is displayed and removed properly."""
110115
self.add_test_origin("pbtest.org", "block")
111116

112-
self.load_url(pbtest.PB_CHROME_OPTIONS_PAGE_URL)
117+
self.load_url(self.options_url)
113118
origins = self.driver.find_element_by_id("blockedResourcesInner")
114119

115120
# Remove displayed origin.

0 commit comments

Comments
 (0)