Skip to content

Commit

Permalink
Add black box test for scroll with none pointer event (#1558)
Browse files Browse the repository at this point in the history
This adds the black box tests for two cases:
1. No scrolling when pointer-events:none
2. No scrolling if swipe starts with pointer-events:none, even if
pointer-events is enabled during the swipe

b/238885425
  • Loading branch information
sherryzy authored Sep 20, 2023
1 parent ad5f29f commit 91b35b6
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions cobalt/black_box_tests/black_box_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'http_cache',
'persistent_cookie',
'scroll',
'scroll_with_none_pointer_events',
'service_worker_add_to_cache_test',
'service_worker_cache_keys_test',
'service_worker_controller_activation_test',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>

<html>

<head>
<title>Cobalt scroll test</title>
<script src='black_box_js_test_utils.js'></script>
<style>
.app {
position: absolute;
width: 80rem;
height: 45rem;
overflow: hidden;
padding: 20px;
z-index: 1;
}

.row {
position: relative;
overflow: auto;
height: 20rem;
width: 80rem;
}

.tile {
position: absolute;
height: 10rem;
width: 200rem;
background: linear-gradient(0.25turn, #f4aca9, #ebf8e1, #bce6f3);
}
</style>
</head>

<body>
<div class="app" style="overflow:auto;">
<div id="row" class="row" style="height: 20rem; pointer-events: none;">
<div id="top_one" class="tile">One</div>
</div>
</div>
</body>
<script>
const scroll_container = document.getElementById("row");

function checkState(key) {
assertTrue(scroll_container.scrollLeft == 0);
if (key == 2) {
onEndTest();
}
}

window.onload = () => {
setupFinished();
}

window.onkeydown = (event) => {
if (event.key == 0 || event.key == 2) {
checkState(event.key);
} else if (event.key == 1) {
scroll_container.style.pointerEvents = 'auto';
}
}
</script>

</html>
65 changes: 65 additions & 0 deletions cobalt/black_box_tests/tests/scroll_with_none_pointer_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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 for scroll containers."""

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
from selenium.webdriver.common import keys

# 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/scroll_with_none_pointer_events.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)

row = find_element_by_id(runner, 'row')
actions = ActionChains(runner.webdriver)

# No scrolling when pointer-events:none
actions.click_and_hold(row).pause(_SLEEP_AFTER_MOVE_TIME)
actions.move_by_offset(-100, 0)
actions.release()
actions.perform()
runner.SendKeys(keys.Keys.NUMPAD0)

# No scrolling if swipe starts with pointer-events:none,
# even if pointer-events is enabled during the swipe
actions2 = ActionChains(runner.webdriver)
actions2.click_and_hold(row).pause(_SLEEP_AFTER_MOVE_TIME)
actions2.send_keys(keys.Keys.NUMPAD1).pause(_SLEEP_AFTER_MOVE_TIME)
actions2.move_by_offset(-100, 0)
actions2.release()
actions2.perform()
runner.SendKeys(keys.Keys.NUMPAD2)
self.assertTrue(runner.JSTestsSucceeded())

0 comments on commit 91b35b6

Please sign in to comment.