From 0baf3224df040da05dbdf671a6cc764c4aa203e0 Mon Sep 17 00:00:00 2001 From: Alexei Date: Fri, 30 Jul 2021 13:06:07 -0400 Subject: [PATCH] Fix order of assertEqual() args Should be expected, actual. --- tests/selenium/clobbering_test.py | 8 ++++---- tests/selenium/cookie_sharing_test.py | 2 +- tests/selenium/dnt_test.py | 28 +++++++++++++------------- tests/selenium/google_test.py | 2 +- tests/selenium/options_test.py | 17 +++++++++------- tests/selenium/popup_test.py | 16 +++++++-------- tests/selenium/service_workers_test.py | 2 +- tests/selenium/storage_test.py | 4 ++-- tests/selenium/super_cookie_test.py | 6 +++--- tests/selenium/widgets_test.py | 4 ++-- 10 files changed, 46 insertions(+), 43 deletions(-) diff --git a/tests/selenium/clobbering_test.py b/tests/selenium/clobbering_test.py index 724b83b4bf..2b9160b5b5 100644 --- a/tests/selenium/clobbering_test.py +++ b/tests/selenium/clobbering_test.py @@ -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 ) @@ -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 ) @@ -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( diff --git a/tests/selenium/cookie_sharing_test.py b/tests/selenium/cookie_sharing_test.py index 9d99acdd49..b7a42c5e54 100644 --- a/tests/selenium/cookie_sharing_test.py +++ b/tests/selenium/cookie_sharing_test.py @@ -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" ) diff --git a/tests/selenium/dnt_test.py b/tests/selenium/dnt_test.py index 21cad79785..b9102c6a9b 100644 --- a/tests/selenium/dnt_test.py +++ b/tests/selenium/dnt_test.py @@ -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) @@ -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): @@ -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? @@ -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): @@ -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" ) @@ -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" ) @@ -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" ) diff --git a/tests/selenium/google_test.py b/tests/selenium/google_test.py index 4fe778e44b..c48f85f509 100644 --- a/tests/selenium/google_test.py +++ b/tests/selenium/google_test.py @@ -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 diff --git a/tests/selenium/options_test.py b/tests/selenium/options_test.py index aea0368b7f..358dd1c64f 100644 --- a/tests/selenium/options_test.py +++ b/tests/selenium/options_test.py @@ -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 ) @@ -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" ) @@ -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" ) @@ -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.""" @@ -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)) diff --git a/tests/selenium/popup_test.py b/tests/selenium/popup_test.py index 154916a6e0..7ed31753b6 100644 --- a/tests/selenium/popup_test.py +++ b/tests/selenium/popup_test.py @@ -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. @@ -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 @@ -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): @@ -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 @@ -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): @@ -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) @@ -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(".", "-"))) @@ -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( diff --git a/tests/selenium/service_workers_test.py b/tests/selenium/service_workers_test.py index 00da1f5de2..9370e9e5a4 100644 --- a/tests/selenium/service_workers_test.py +++ b/tests/selenium/service_workers_test.py @@ -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") diff --git a/tests/selenium/storage_test.py b/tests/selenium/storage_test.py index d8e6c640b1..bf6b6ac783 100644 --- a/tests/selenium/storage_test.py +++ b/tests/selenium/storage_test.py @@ -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( diff --git a/tests/selenium/super_cookie_test.py b/tests/selenium/super_cookie_test.py index de6c5dd943..15cf4a24b3 100644 --- a/tests/selenium/super_cookie_test.py +++ b/tests/selenium/super_cookie_test.py @@ -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 @@ -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): diff --git a/tests/selenium/widgets_test.py b/tests/selenium/widgets_test.py index 31997b00a7..5d185c4422 100644 --- a/tests/selenium/widgets_test.py +++ b/tests/selenium/widgets_test.py @@ -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")