tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_restore_loading_tab.py (2116B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 from urllib.parse import quote
      6 
      7 from marionette_harness import MarionetteTestCase, WindowManagerMixin
      8 
      9 
     10 def inline(doc):
     11    return f"data:text/html;charset=utf-8,{quote(doc)}"
     12 
     13 
     14 class TestRestoreLoadingPage(WindowManagerMixin, MarionetteTestCase):
     15    def setUp(self):
     16        super().setUp()
     17        self.delayed_page = self.marionette.absolute_url("slow")
     18 
     19    def do_test(self, html, is_restoring_expected):
     20        self.marionette.navigate(inline(html.format(self.delayed_page)))
     21        link = self.marionette.find_element("id", "link")
     22        link.click()
     23 
     24        self.marionette.restart(in_app=True)
     25 
     26        with self.marionette.using_context("chrome"):
     27            urls = self.marionette.execute_script(
     28                "return gBrowser.tabs.map(t => t.linkedBrowser.currentURI.spec);"
     29            )
     30 
     31        if is_restoring_expected:
     32            self.assertEqual(
     33                len(urls),
     34                2,
     35                msg="The tab opened should be restored",
     36            )
     37            self.assertEqual(
     38                urls[1],
     39                self.delayed_page,
     40                msg="The tab restored is correct",
     41            )
     42        else:
     43            self.assertEqual(
     44                len(urls),
     45                1,
     46                msg="The tab opened should not be restored",
     47            )
     48 
     49        self.close_all_tabs()
     50 
     51    def test_target_blank(self):
     52        self.do_test("<a id='link' href='{}' target='_blank'>click</a>", True)
     53 
     54    def test_target_other(self):
     55        self.do_test("<a id='link' href='{}' target='other'>click</a>", False)
     56 
     57    def test_by_script(self):
     58        self.do_test(
     59            """
     60            <a id='link'>click</a>
     61            <script>
     62            document.getElementById("link").addEventListener(
     63                "click",
     64                () => window.open("{}", "_blank");
     65            )
     66            </script>
     67            """,
     68            False,
     69        )