tor-browser

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

test_chrome_element_id.py (3806B)


      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 import os
      6 import sys
      7 
      8 from marionette_driver.by import By
      9 from marionette_driver.errors import NoSuchElementException
     10 from marionette_driver.marionette import WebElement
     11 
     12 from marionette_harness import MarionetteTestCase, parameterized, WindowManagerMixin
     13 
     14 # add this directory to the path
     15 sys.path.append(os.path.dirname(__file__))
     16 
     17 from chrome_handler_mixin import ChromeHandlerMixin
     18 
     19 
     20 PAGE_XHTML = "test.xhtml"
     21 PAGE_XUL = "test_xul.xhtml"
     22 
     23 
     24 class TestElementIDChrome(ChromeHandlerMixin, WindowManagerMixin, MarionetteTestCase):
     25    def setUp(self):
     26        super(TestElementIDChrome, self).setUp()
     27 
     28        self.marionette.set_context("chrome")
     29 
     30    def tearDown(self):
     31        self.close_all_windows()
     32 
     33        super(TestElementIDChrome, self).tearDown()
     34 
     35    @parameterized("XUL", PAGE_XUL)
     36    @parameterized("XHTML", PAGE_XHTML)
     37    def test_id_identical_for_the_same_element(self, chrome_url):
     38        win = self.open_chrome_window(self.chrome_base_url + chrome_url)
     39        self.marionette.switch_to_window(win)
     40 
     41        found_el = self.marionette.find_element(By.ID, "textInput")
     42        self.assertEqual(WebElement, type(found_el))
     43 
     44        found_el_new = self.marionette.find_element(By.ID, "textInput")
     45        self.assertEqual(found_el_new.id, found_el.id)
     46 
     47    @parameterized("XUL", PAGE_XUL)
     48    @parameterized("XHTML", PAGE_XHTML)
     49    def test_id_unique_per_session(self, chrome_url):
     50        win = self.open_chrome_window(self.chrome_base_url + chrome_url)
     51        self.marionette.switch_to_window(win)
     52 
     53        found_el = self.marionette.find_element(By.ID, "textInput")
     54        self.assertEqual(WebElement, type(found_el))
     55 
     56        self.marionette.delete_session()
     57        self.marionette.start_session()
     58 
     59        self.marionette.set_context("chrome")
     60 
     61        # By default the first browser window will be selected again.
     62        # Find and select the custom chrome window.
     63        chrome_window_handle = self.marionette.current_chrome_window_handle
     64        chrome_windows = [
     65            win
     66            for win in self.marionette.chrome_window_handles
     67            if win != chrome_window_handle
     68        ]
     69 
     70        self.marionette.switch_to_window(chrome_windows[0])
     71 
     72        found_el_new = self.marionette.find_element(By.ID, "textInput")
     73        self.assertNotEqual(found_el_new.id, found_el.id)
     74 
     75    @parameterized("XUL", PAGE_XUL)
     76    @parameterized("XHTML", PAGE_XHTML)
     77    def test_id_no_such_element_in_another_chrome_window(self, chrome_url):
     78        original_handle = self.marionette.current_window_handle
     79 
     80        win = self.open_chrome_window(self.chrome_base_url + chrome_url)
     81        self.marionette.switch_to_window(win)
     82 
     83        found_el = self.marionette.find_element(By.ID, "textInput")
     84        self.assertEqual(WebElement, type(found_el))
     85 
     86        self.marionette.switch_to_window(original_handle)
     87 
     88        with self.assertRaises(NoSuchElementException):
     89            found_el.get_property("localName")
     90 
     91    @parameterized("XUL", PAGE_XUL)
     92    @parameterized("XHTML", PAGE_XHTML)
     93    def test_id_removed_when_chrome_window_is_closed(self, chrome_url):
     94        original_handle = self.marionette.current_window_handle
     95 
     96        win = self.open_chrome_window(self.chrome_base_url + chrome_url)
     97        self.marionette.switch_to_window(win)
     98 
     99        found_el = self.marionette.find_element(By.ID, "textInput")
    100        self.assertEqual(WebElement, type(found_el))
    101 
    102        self.marionette.close_chrome_window()
    103        self.marionette.switch_to_window(original_handle)
    104 
    105        with self.assertRaises(NoSuchElementException):
    106            found_el.get_property("localName")