[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser-bundle-testsuite/master] Bug 30431: Fix the https-everywhere test



commit 3f07e512d087e40845ce4d52ec4221f98baed878
Author: Alex Catarineu <acat@xxxxxxxxxxxxxx>
Date:   Mon Sep 14 18:26:12 2020 +0200

    Bug 30431: Fix the https-everywhere test
    
    Temptatively fixing this flaky test by waiting until HTTPS Everywhere
    has loaded some rulesets.
    
    Also fix https-everywhere tests for builtin addon.
---
 TBBTestSuite/TestSuite/BrowserBundleTests.pm       | 15 --------
 .../tor_browser_tests/test_https-everywhere.py     | 44 ++++++++++++++++++----
 2 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/TBBTestSuite/TestSuite/BrowserBundleTests.pm b/TBBTestSuite/TestSuite/BrowserBundleTests.pm
index e92fe6d..e35e903 100644
--- a/TBBTestSuite/TestSuite/BrowserBundleTests.pm
+++ b/TBBTestSuite/TestSuite/BrowserBundleTests.pm
@@ -272,27 +272,12 @@ our @tests = (
         type            => 'marionette',
         descr           => 'Check that https everywhere is not doing anything when disabled',
         use_net         => 1,
-        pre             => sub {
-            my ($tbbinfos, $t) = @_;
-            my $hdir = "$tbbinfos->{tmpdir}/https-everywhere";
-            mkdir "$hdir";
-            move($tbbinfos->{ffprofiledir} . '/extensions/https-everywhere-eff@xxxxxxxxxxx',
-                $hdir . '/https-everywhere-eff@xxxxxxxxxxx');
-        },
-        post            => sub {
-            my ($tbbinfos, $t) = @_;
-            my $hdir = "$tbbinfos->{tmpdir}/https-everywhere";
-            move($hdir . '/https-everywhere-eff@xxxxxxxxxxx',
-                $tbbinfos->{ffprofiledir} . '/extensions/https-everywhere-eff@xxxxxxxxxxx');
-        },
     },
     {
         name            => 'https-everywhere',
         type            => 'marionette',
         use_net         => 1,
         descr           => 'Check that https everywhere is working',
-        # Bug 30431: temporarily disable test
-        enable          => sub { undef },
     },
     {
         name            => 'settings',
diff --git a/marionette/tor_browser_tests/test_https-everywhere.py b/marionette/tor_browser_tests/test_https-everywhere.py
index 25d959e..7819771 100644
--- a/marionette/tor_browser_tests/test_https-everywhere.py
+++ b/marionette/tor_browser_tests/test_https-everywhere.py
@@ -1,11 +1,7 @@
-from marionette_driver import By
-from marionette_driver.errors import MarionetteException
-
 from marionette_harness import MarionetteTestCase
-
+from marionette_driver import Wait
 import testsuite
 
-
 class Test(MarionetteTestCase):
 
     def setUp(self):
@@ -17,13 +13,47 @@ class Test(MarionetteTestCase):
         self.HTTP_URL = "http://httpbin.org/";
         self.HTTPS_URL = "https://httpbin.org/";
 
+        self.is_disabled = self.ts.t['test']['name'] == 'https-everywhere-disabled'
+
+        if self.is_disabled:
+            with self.marionette.using_context('chrome'):
+                self.marionette.execute_async_script("""
+                    let [resolve] = arguments;
+                    const { AddonManager } = ChromeUtils.import(
+                        "resource://gre/modules/AddonManager.jsm"
+                    );
+                    AddonManager.getAddonByID("https-everywhere-eff@xxxxxxx")
+                        .then(addon => addon.disable())
+                        .then(resolve);
+                """)
+
+    def tearDown(self):
+        super(Test, self).tearDown()
+        if self.is_disabled:
+            with self.marionette.using_context('chrome'):
+                self.marionette.execute_async_script("""
+                    let [resolve] = arguments;
+                    const { AddonManager } = ChromeUtils.import(
+                        "resource://gre/modules/AddonManager.jsm"
+                    );
+                    AddonManager.getAddonByID("https-everywhere-eff@xxxxxxx")
+                        .then(addon => addon.enable())
+                        .then(resolve);
+                """)
 
     def test_https_everywhere(self):
+        # Wait until .tor.onion rules have been loaded, to make sure HTTPS Everywhere
+        # has loaded correctly.
+        m = self.marionette
+        if not self.is_disabled:
+            with m.using_context('chrome'):
+                Wait(m, timeout=m.timeout.page_load).until(
+                    lambda _: m.execute_script("return OnionAliasStore._onionMap.size;") > 0)
+
         with self.marionette.using_context('content'):
             self.marionette.navigate(self.HTTP_URL)
 
-            if self.ts.t['test']['name'] == 'https-everywhere':
+            if not self.is_disabled:
                 self.assertEqual(self.marionette.get_url(), self.HTTPS_URL)
             else:
                 self.assertEqual(self.marionette.get_url(), self.HTTP_URL)
-



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits