Skip to content

Commit

Permalink
Fix order of assertEqual() args
Browse files Browse the repository at this point in the history
Should be expected, actual.
  • Loading branch information
ghostwords committed Jul 30, 2021
1 parent abcd0de commit 0baf322
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 43 deletions.
8 changes: 4 additions & 4 deletions tests/selenium/clobbering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_localstorage_clobbering(self):
)
)
self.assertEqual(
self.txt_by_css("#" + selector), expected,
expected, self.txt_by_css("#" + selector),
"localStorage (%s) was not read successfully"
"for some reason" % selector
)
Expand All @@ -63,7 +63,7 @@ def test_localstorage_clobbering(self):
)
)
self.assertEqual(
self.txt_by_css("#" + selector), expected,
expected, self.txt_by_css("#" + selector),
"localStorage (%s) was read despite cookieblocking" % selector
)

Expand All @@ -79,8 +79,8 @@ def verify_referrer_header(expected, failure_message):
self.wait_for_script(
"return document.getElementById('referrer').textContent != '';")
referrer = self.txt_by_css("#referrer")
self.assertEqual(referrer[0:8], "Referer=", "Unexpected page output")
self.assertEqual(referrer[8:], expected, failure_message)
self.assertEqual("Referer=", referrer[0:8], "Unexpected page output")
self.assertEqual(expected, referrer[8:], failure_message)

# verify base case
verify_referrer_header(
Expand Down
2 changes: 1 addition & 1 deletion tests/selenium/cookie_sharing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def test_pixel_cookie_sharing(self):
# check to make sure this domain is caught and correctly recorded in snitch map
self.load_url(self.options_url)
self.assertEqual(
self.get_snitch_map(),
["efforg.github.io"],
self.get_snitch_map(),
"Pixel cookie sharing tracking failed to be detected"
)

Expand Down
28 changes: 14 additions & 14 deletions tests/selenium/dnt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ def test_dnt_policy_check_should_not_set_cookies(self):

# verify that the domain itself doesn't set cookies
self.load_url(TEST_URL)
self.assertEqual(len(self.driver.get_cookies()), 0,
self.assertEqual(0, len(self.driver.get_cookies()),
"No cookies initially")

# directly visit a DNT policy URL known to set cookies
self.load_url(TEST_URL + ".well-known/dnt-policy.txt")
self.assertEqual(len(self.driver.get_cookies()), 1,
self.assertEqual(1, len(self.driver.get_cookies()),
"DNT policy URL set a cookie")

# verify we got a cookie
self.load_url(TEST_URL)
self.assertEqual(len(self.driver.get_cookies()), 1,
self.assertEqual(1, len(self.driver.get_cookies()),
"We still have just one cookie")

# clear cookies and verify
self.driver.delete_all_cookies()
self.load_url(TEST_URL)
self.assertEqual(len(self.driver.get_cookies()), 0,
self.assertEqual(0, len(self.driver.get_cookies()),
"No cookies again")

self.load_url(self.options_url)
Expand All @@ -156,7 +156,7 @@ def test_dnt_policy_check_should_not_set_cookies(self):

# check that we didn't get cookied by the DNT URL
self.load_url(TEST_URL)
self.assertEqual(len(self.driver.get_cookies()), 0,
self.assertEqual(0, len(self.driver.get_cookies()),
"Shouldn't have any cookies after the DNT check")

def test_dnt_policy_check_should_not_send_cookies(self):
Expand All @@ -165,7 +165,7 @@ def test_dnt_policy_check_should_not_send_cookies(self):

# directly visit a DNT policy URL known to set cookies
self.load_url(TEST_URL + ".well-known/dnt-policy.txt")
self.assertEqual(len(self.driver.get_cookies()), 1,
self.assertEqual(1, len(self.driver.get_cookies()),
"DNT policy URL set a cookie")

# how to check we didn't send a cookie along with request?
Expand Down Expand Up @@ -242,9 +242,9 @@ def test_first_party_dnt_header(self):
self.assertTrue(headers is not None, "It seems we failed to get headers")
self.assertIn('Dnt', headers, "DNT header should have been present")
self.assertIn('Sec-Gpc', headers, "GPC header should have been present")
self.assertEqual(headers['Dnt'], "1",
self.assertEqual("1", headers['Dnt'],
'DNT header should have been set to "1"')
self.assertEqual(headers['Sec-Gpc'], "1",
self.assertEqual("1", headers['Sec-Gpc'],
'Sec-Gpc header should have been set to "1"')

def test_no_dnt_header_when_disabled_on_site(self):
Expand Down Expand Up @@ -273,13 +273,13 @@ def test_navigator_object(self):
self.load_url(DntTest.NAVIGATOR_DNT_TEST_URL, wait_for_body_text=True)

self.assertEqual(
self.driver.find_element_by_tag_name('body').text,
'no tracking (navigator.doNotTrack="1")',
self.driver.find_element_by_tag_name('body').text,
"navigator.DoNotTrack should have been set to \"1\""
)
self.assertEqual(
self.js("return navigator.globalPrivacyControl"),
True,
self.js("return navigator.globalPrivacyControl"),
"navigator.globalPrivacyControl should have been set to true"
)

Expand All @@ -290,13 +290,13 @@ def test_navigator_unmodified_when_disabled_on_site(self):

# navigator.doNotTrack defaults to null in Chrome, "unspecified" in Firefox
self.assertEqual(
self.driver.find_element_by_tag_name('body').text[0:5],
'unset',
self.driver.find_element_by_tag_name('body').text[0:5],
"navigator.DoNotTrack should have been left unset"
)
self.assertEqual(
self.js("return navigator.globalPrivacyControl"),
None,
self.js("return navigator.globalPrivacyControl"),
"navigator.globalPrivacyControl should have been left unset"
)

Expand All @@ -309,13 +309,13 @@ def test_navigator_unmodified_when_dnt_disabled(self):

# navigator.doNotTrack defaults to null in Chrome, "unspecified" in Firefox
self.assertEqual(
self.driver.find_element_by_tag_name('body').text[0:5],
'unset',
self.driver.find_element_by_tag_name('body').text[0:5],
"navigator.DoNotTrack should have been left unset"
)
self.assertEqual(
self.js("return navigator.globalPrivacyControl"),
None,
self.js("return navigator.globalPrivacyControl"),
"navigator.globalPrivacyControl should have been left unset"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/selenium/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _check_results():
self.assertFalse(link.get_attribute('onmousedown'),
"Tracking attribute should be missing")

self.assertEqual(link.get_attribute('rel'), "noreferrer noopener")
self.assertEqual("noreferrer noopener", link.get_attribute('rel'))

return True

Expand Down
17 changes: 10 additions & 7 deletions tests/selenium/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def assert_slider_state(self, origin, action, failure_msg):
clicker = self.driver.find_element_by_css_selector(
'div[data-origin="{}"]'.format(origin))
self.assertEqual(
clicker.get_attribute("class"),
"clicker userset",
clicker.get_attribute("class"),
failure_msg
)

switches_div = clicker.find_element_by_css_selector(".switch-container")
self.assertEqual(
switches_div.get_attribute("class"),
"switch-container " + action,
switches_div.get_attribute("class"),
failure_msg
)

Expand Down Expand Up @@ -136,8 +136,8 @@ def test_added_multiple_origins_display(self):

# check tracker count
self.assertEqual(
self.driver.find_element_by_id("options_domain_list_trackers").text,
"Privacy Badger has decided to block 2 potential tracking domains so far",
self.driver.find_element_by_id("options_domain_list_trackers").text,
"Origin tracker count should be 2 after adding origin"
)

Expand Down Expand Up @@ -219,8 +219,8 @@ def test_reset_data(self):

# make sure only two trackers are displayed now
self.assertEqual(
self.driver.find_element_by_id("options_domain_list_trackers").text,
"Privacy Badger has decided to block 2 potential tracking domains so far",
self.driver.find_element_by_id("options_domain_list_trackers").text,
"Origin tracker count should be 2 after clearing and adding origins"
)

Expand All @@ -234,8 +234,11 @@ def test_reset_data(self):
# make sure the same number of trackers are displayed as by default
self.select_domain_list_tab()
error_message = "After resetting data, tracker count should return to default"
self.assertEqual(self.driver.find_element_by_id("options_domain_list_trackers").text,
default_summary_text, error_message)
self.assertEqual(
default_summary_text,
self.driver.find_element_by_id("options_domain_list_trackers").text,
error_message
)

def tracking_user_overwrite(self, original_action, overwrite_action):
"""Ensure preferences are persisted when a user overwrites pb's default behaviour for an origin."""
Expand Down Expand Up @@ -311,7 +314,7 @@ def test_options_ui_open_in_tab(self):
if num_newly_opened_windows:
self.driver.switch_to.window(new_handles.pop())

self.assertEqual(num_newly_opened_windows, 0,
self.assertEqual(0, num_newly_opened_windows,
"Expected to switch to existing options page, "
"opened a new page ({}) instead: {}".format(
self.driver.title, self.driver.current_url))
Expand Down
16 changes: 8 additions & 8 deletions tests/selenium/popup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_trackers_link(self):

self.wait_for_page_to_start_loading(EFF_URL)

self.assertEqual(self.driver.current_url, EFF_URL,
self.assertEqual(EFF_URL, self.driver.current_url,
"EFF website should open after clicking trackers link on popup")

# Verify EFF website contains the linked anchor element.
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_toggling_sliders(self):
self.find_el_by_css('a[href="#tab-tracking-domains"]').click()
new_action = self.get_domain_slider_state(DOMAIN)

self.assertEqual(new_action, "block",
self.assertEqual("block", new_action,
"The domain should be blocked on options page.")

# test toggling some more
Expand All @@ -220,7 +220,7 @@ def test_toggling_sliders(self):
self.find_el_by_css('a[href="#tab-tracking-domains"]').click()
new_action = self.get_domain_slider_state(DOMAIN)

self.assertEqual(new_action, "block",
self.assertEqual("block", new_action,
"The domain should still be blocked on options page.")

def test_reverting_control(self):
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_reverting_control(self):

# assert the action is not what we manually clicked
action = self.get_domain_slider_state(DOMAIN)
self.assertEqual(action, "cookieblock",
self.assertEqual("cookieblock", action,
"Domain's action should have been restored.")

# assert the undo arrow is not displayed
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_donate_button(self):

self.wait_for_page_to_start_loading(EFF_URL)

self.assertEqual(self.driver.current_url, EFF_URL,
self.assertEqual(EFF_URL, self.driver.current_url,
"EFF website should open after clicking donate button on popup")

def test_breakage_warnings(self):
Expand Down Expand Up @@ -411,7 +411,7 @@ def assert_visible(sliders):
sliders = self.driver.find_elements_by_css_selector('div.clicker')

# verify we have the expected number of sliders
self.assertEqual(len(sliders), len(TEST_DOMAINS))
self.assertEqual(len(TEST_DOMAINS), len(sliders))

# verify sliders are hidden
assert_hidden(sliders)
Expand All @@ -432,7 +432,7 @@ def assert_visible(sliders):
assert_visible(sliders)

# verify domain is shown second in the list
self.assertEqual(sliders[1].get_attribute('data-origin'), YLIST_DOMAIN)
self.assertEqual(YLIST_DOMAIN, sliders[1].get_attribute('data-origin'))

# manually block the yellowlisted domain
self.js("$('#block-{}').click()".format(YLIST_DOMAIN.replace(".", "-")))
Expand All @@ -454,7 +454,7 @@ def assert_visible(sliders):
assert_visible(sliders)

# verify breakage warning slider is at the top
self.assertEqual(sliders[0].get_attribute('data-origin'), YLIST_DOMAIN)
self.assertEqual(YLIST_DOMAIN, sliders[0].get_attribute('data-origin'))

# restore the user-set slider to default action
self.driver.find_element_by_css_selector(
Expand Down
2 changes: 1 addition & 1 deletion tests/selenium/service_workers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_returning_to_sw_cached_page(self):
domains = self.get_tab_data_domains()
self.assertIn("efforg.github.io", domains,
"SW page URL was not correctly attributed")
self.assertEqual(len(domains), 1,
self.assertEqual(1, len(domains),
"tabData contains an unexpected number of entries")


Expand Down
4 changes: 2 additions & 2 deletions tests/selenium/storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def test_should_init_storage_entries(self):

self.check_policy_download()
self.assertEqual(
"https://www.eff.org/files/cookieblocklist_new.txt",
self.js(
"return chrome.extension.getBackgroundPage()."
"constants.YELLOWLIST_URL"
),
"https://www.eff.org/files/cookieblocklist_new.txt"
)
)

disabled_sites = self.js(
Expand Down
6 changes: 3 additions & 3 deletions tests/selenium/super_cookie_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def test_async_tracking_attribution_bug(self):

# an iframe from THIRD_PARTY_BASE that writes to localStorage
self.assertEqual(
pbtest.retry_until(partial(self.get_snitch_map_for, THIRD_PARTY_BASE)),
[FIRST_PARTY_BASE],
pbtest.retry_until(partial(self.get_snitch_map_for, THIRD_PARTY_BASE)),
msg="Frame sets localStorage but was not flagged as a tracker.")

# and an image from raw.githubusercontent.com that doesn't do any tracking
Expand All @@ -76,8 +76,8 @@ def test_should_detect_ls_of_third_party_frame(self):
self.driver.refresh()

self.assertEqual(
pbtest.retry_until(partial(self.get_snitch_map_for, THIRD_PARTY_BASE), times=3),
[FIRST_PARTY_BASE]
[FIRST_PARTY_BASE],
pbtest.retry_until(partial(self.get_snitch_map_for, THIRD_PARTY_BASE), times=3)
)

def test_should_not_detect_low_entropy_ls_of_third_party_frame(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/selenium/widgets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def test_activation(self):
# assert all script attributes were copied
script_el = self.driver.find_element_by_css_selector(
'script.' + self.TYPE4_WIDGET_CLASS)
self.assertEqual(script_el.get_attribute('async'), "true")
self.assertEqual(script_el.get_attribute('data-foo'), "bar")
self.assertEqual("true", script_el.get_attribute('async'))
self.assertEqual("bar", script_el.get_attribute('data-foo'))

self.assert_widget("type4")

Expand Down

0 comments on commit 0baf322

Please sign in to comment.