# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
from unittest import skipIf
from six.moves.urllib.parse import quote
from marionette_driver import By, errors
from marionette_driver.marionette import Alert
from marionette_harness import (
MarionetteTestCase,
WindowManagerMixin,
)
def inline(doc):
return "data:text/html;charset=utf-8,{}".format(quote(doc))
# The element in the following HTML is not interactable because it
# is hidden by an overlay when scrolled into the top of the viewport.
# It should be interactable when scrolled in at the bottom of the
# viewport.
fixed_overlay = inline(
"""
overlay
link
"""
)
obscured_overlay = inline(
"""
link
"""
)
class ClickBaseTestCase(WindowManagerMixin, MarionetteTestCase):
def setUp(self):
super(ClickBaseTestCase, self).setUp()
# Always use a blank new tab for an empty history
self.new_tab = self.open_tab()
self.marionette.switch_to_window(self.new_tab)
def tearDown(self):
self.close_all_tabs()
def test_click(self):
self.marionette.navigate(
inline(
"""
"""
)
)
button = self.marionette.find_element(By.TAG_NAME, "button")
button.click()
self.assertEqual(
1, self.marionette.execute_script("return window.clicks", sandbox=None)
)
def test_click_number_link(self):
test_html = self.marionette.absolute_url("clicks.html")
self.marionette.navigate(test_html)
self.marionette.find_element(By.LINK_TEXT, "333333").click()
self.marionette.find_element(By.ID, "testDiv")
self.assertEqual(self.marionette.title, "Marionette Test")
def test_clicking_an_element_that_is_not_displayed_raises(self):
self.marionette.navigate(
inline(
"""
foo
"""
)
)
with self.assertRaises(errors.ElementNotInteractableException):
self.marionette.find_element(By.TAG_NAME, "p").click()
def test_clicking_on_a_multiline_link(self):
test_html = self.marionette.absolute_url("clicks.html")
self.marionette.navigate(test_html)
self.marionette.find_element(By.ID, "overflowLink").click()
self.marionette.find_element(By.ID, "testDiv")
self.assertEqual(self.marionette.title, "Marionette Test")
def test_click_mathml(self):
self.marionette.navigate(
inline(
"""
"""
)
)
mtext = self.marionette.find_element(By.ID, "target")
mtext.click()
self.assertEqual(
1, self.marionette.execute_script("return window.clicks", sandbox=None)
)
def test_scroll_into_view_near_end(self):
self.marionette.navigate(fixed_overlay)
link = self.marionette.find_element(By.TAG_NAME, "a")
link.click()
self.assertTrue(
self.marionette.execute_script("return window.clicked", sandbox=None)
)
def test_inclusive_descendant(self):
self.marionette.navigate(
inline(
"""
"""
)
)
select = self.marionette.find_element(By.TAG_NAME, "select")
# This tests that the pointer-interactability test does not
# cause an ElementClickInterceptedException.
#
# At a