blob: 5facb8569bf9f60e5420f9cd54dd5ae468b1bf95 [file] [log] [blame]
# Copyright 2023 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests events for an extended sequence of pointer moves and clicks."""
# This test generates an extended sequence of pointer move and click events,
# and verifies the corresponding sequence of pointer, mouse, and click events
# dispatched to the HTML elements. The test includes use of pointer capture and
# use of preventDefault() and stopPropagation() on the events, as well as event
# bubbling.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import logging
from cobalt.black_box_tests import black_box_tests
from cobalt.black_box_tests.threaded_web_server import ThreadedWebServer
from selenium.webdriver.common.action_chains import ActionChains
# Time to sleep after a mouse move to give the device time to process it and
# to avoid collapsing with subsequent move events.
_SLEEP_AFTER_MOVE_TIME = 0.5
def find_element_by_id(runner, id_selector):
return runner.webdriver.find_elements_by_css_selector('#' + id_selector)[0]
class PointerTest(black_box_tests.BlackBoxTestCase):
"""Tests pointer and mouse event."""
def test_pointer_events(self):
with ThreadedWebServer(binding_address=self.GetBindingAddress()) as server:
url = server.GetURL(
file_name='testdata/pointer_event_on_cropped_element_test.html')
with self.CreateCobaltRunner(url=url) as runner:
logging.info('JS Test Setup WaitForJSTestsSetup')
runner.WaitForJSTestsSetup()
logging.info('JS Test Setup')
self.assertTrue(runner.webdriver)
upper_element = find_element_by_id(runner, 'upper_element')
lower_element = find_element_by_id(runner, 'lower_element')
end = find_element_by_id(runner, 'end')
actions = ActionChains(runner.webdriver)
actions.move_to_element(lower_element).pause(_SLEEP_AFTER_MOVE_TIME)
actions.click()
actions.move_to_element_with_offset(upper_element, 5,
5).pause(_SLEEP_AFTER_MOVE_TIME)
actions.click()
actions.move_to_element(upper_element).pause(_SLEEP_AFTER_MOVE_TIME)
actions.click()
actions.click(end)
actions.perform()
self.assertTrue(runner.JSTestsSucceeded())