commit fe257166a6e9a5bb4100a24674f98eed86822572 Author: Alex Catarineu acat@torproject.org Date: Mon Jun 29 19:41:47 2020 +0200
Bug 40003: Add test for 'Implement Onion-Location' TB patch --- TBBTestSuite/TestSuite/BrowserBundleTests.pm | 6 + .../tor_browser_tests/test_onion_location.py | 135 +++++++++++++++++++++ 2 files changed, 141 insertions(+)
diff --git a/TBBTestSuite/TestSuite/BrowserBundleTests.pm b/TBBTestSuite/TestSuite/BrowserBundleTests.pm index 834641e..5a642ef 100644 --- a/TBBTestSuite/TestSuite/BrowserBundleTests.pm +++ b/TBBTestSuite/TestSuite/BrowserBundleTests.pm @@ -482,6 +482,12 @@ our @tests = ( use_net => 1, descr => 'Check onion security expectations', }, + { + name => 'onion_location', + type => 'marionette', + use_net => 1, + descr => 'Check that Onion-Location header handling works correctly', + }, );
sub set_test_prefs { diff --git a/marionette/tor_browser_tests/test_onion_location.py b/marionette/tor_browser_tests/test_onion_location.py new file mode 100644 index 0000000..1188250 --- /dev/null +++ b/marionette/tor_browser_tests/test_onion_location.py @@ -0,0 +1,135 @@ +from marionette_driver import By, Wait +from marionette_driver.errors import MarionetteException, NoSuchElementException, TimeoutException + +from marionette_harness import MarionetteTestCase, WindowManagerMixin + + +class Test(WindowManagerMixin, MarionetteTestCase): + + def test_onion_location(self): + m = self.marionette + m.timeout.implicit = 10 + + self.assertEqual(None, m.get_pref( + 'privacy.prioritizeonions.showNotification')) + + with m.using_context('content'): + m.navigate('https://www.torproject.org/') + + with m.using_context('chrome'): + # Check whether the urlbar badge is displayed + self.assertTrue(m.find_element( + 'id', 'onion-location-box').is_displayed()) + + # Check whether the notification is displayed the first time + notification = m.find_element('id', 'onion-location-notification') + self.assertTrue(notification.is_displayed()) + self.assertFalse(m.get_pref( + 'privacy.prioritizeonions.showNotification')) + always_prioritize = notification.find_element( + 'css selector', '.popup-notification-primary-button') + self.assertEqual(always_prioritize.get_attribute( + 'label'), 'Always Prioritize Onions') + + # Check learn more link + notification.find_element( + 'css selector', '.popup-notification-learnmore-link').click() + with m.using_context('content'): + Wait(m, timeout=m.timeout.page_load).until( + lambda _: len(m.window_handles) > 1) + m.switch_to_window(m.window_handles[1]) + Wait(m, timeout=m.timeout.page_load).until( + lambda _: m.get_url() != "about:blank") + self.assertEqual( + m.get_url(), "https://tb-manual.torproject.org/onion-services/") + m.close() + m.switch_to_window(m.window_handles[0]) + + with m.using_context('chrome'): + # Close the notification and check that it's not displayed anymore. + notification = m.find_element('id', 'onion-location-notification') + not_now = notification.find_element( + 'css selector', '.popup-notification-secondary-button') + self.assertEqual(not_now.get_attribute('label'), 'Not Now') + not_now.click() + try: + self.assertFalse(m.find_element( + 'id', 'onion-location-notification').is_displayed()) + except NoSuchElementException: + pass + + # Show the notification again + m.set_pref('privacy.prioritizeonions.showNotification', None) + new_tab = self.open_tab() + m.switch_to_window(new_tab) + m.close() + m.switch_to_window(self.start_tab) + + # Click "Always prioritize" in the notification + notification = m.find_element('id', 'onion-location-notification') + notification.find_element( + 'css selector', '.popup-notification-primary-button').click() + self.assertTrue(m.get_pref('privacy.prioritizeonions.enabled')) + + with m.using_context('content'): + m.switch_to_window(m.window_handles[1]) + self.assertEqual( + m.get_url(), 'about:preferences#privacy-onionservices') + m.close() + m.switch_to_window(self.start_tab) + + # Check that the original page is redirected to .onion + Wait(m, timeout=m.timeout.page_load).until( + lambda _: m.get_url() != 'https://www.torproject.org/') + self.assertEqual( + m.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html') + + # Check that auto-redirects work + m.navigate('https://www.torproject.org/') + self.assertEqual(m.get_url(), 'https://www.torproject.org/') + Wait(m, timeout=m.timeout.page_load).until( + lambda _: m.get_url() != 'https://www.torproject.org/') + self.assertEqual( + m.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html') + + # Go to preferences and disable auto-redirects + new_tab = self.open_tab() + m.switch_to_window(new_tab) + m.navigate('about:preferences#privacy-onionservices') + m.find_element('id', 'onionServicesRadioAsk').click() + self.assertFalse(m.get_pref( + 'privacy.prioritizeonions.enabled')) + m.close() + m.switch_to_window(self.start_tab) + m.navigate('https://www.torproject.org/') + try: + Wait(m, timeout=5).until(lambda _: m.get_url() + != 'https://www.torproject.org/') + self.assertTrue(False, "Should not redirect") + except TimeoutException: + pass + + # Check that the page is redirected when clicking on the urlbar badge + with m.using_context('chrome'): + self.assertTrue(m.find_element( + 'id', 'onion-location-box').is_displayed()) + m.find_element('id', 'onion-location-box').click() + with m.using_context('content'): + Wait(m, timeout=5).until(lambda _: m.get_url() + != 'https://www.torproject.org/') + self.assertEqual( + m.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html') + + # Check learn more link + with m.using_context('content'): + m.navigate('about:preferences#privacy-onionservices') + m.find_element('id', 'onionServicesLearnMore').click() + Wait(m, timeout=m.timeout.page_load).until( + lambda _: len(m.window_handles) > 1) + m.switch_to_window(m.window_handles[1]) + Wait(m, timeout=m.timeout.page_load).until( + lambda _: m.get_url() != "about:blank") + self.assertEqual( + m.get_url(), "https://tb-manual.torproject.org/onion-services/") + m.close() + m.switch_to_window(m.window_handles[0])