Add keyboard input testcase to the QWasmWindow test

The test checks whether correct windows get correct keyboard input,
having been activated with mouse clicks.

Also fixes the event propagation error found. Key events would propagate
to parent windows, which is something that should not happen with
window managers.

Change-Id: I18bae8c14cce5ccae151c2a00c84ffdba3b4587f
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
This commit is contained in:
Mikolaj Boc 2023-02-22 09:50:54 +01:00
parent 603d6351cc
commit b2093aad39
2 changed files with 50 additions and 0 deletions

View File

@ -129,6 +129,7 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport,
const auto keyCallback = std::function([this](emscripten::val event) {
if (processKey(*KeyEvent::fromWebWithDeadKeyTranslation(event, m_deadKeySupport)))
event.call<void>("preventDefault");
event.call<void>("stopPropagation");
});
m_keyDownCallback =

View File

@ -429,6 +429,55 @@ class WidgetTestCase(unittest.TestCase):
self.assertEqual(w1_w1_w1.color_at(0, 0), Color(r=255, g=255, b=0))
def test_keyboard_input(self):
screen = Screen(self._driver, ScreenPosition.FIXED,
x=0, y=0, width=800, height=800)
bottom = Window(parent=screen, rect=Rect(x=0, y=0, width=800, height=800), title='root')
w1 = Window(parent=screen, rect=Rect(x=100, y=100, width=600, height=600), title='w1')
w1_w1 = Window(parent=w1, rect=Rect(x=100, y=100, width=400, height=400), title='w1_w1')
w1_w1_w1 = Window(parent=w1_w1, rect=Rect(x=100, y=100, width=100, height=100), title='w1_w1_w1')
Window(parent=w1_w1, rect=Rect(x=150, y=150, width=100, height=100), title='w1_w1_w2')
w1_w1_w1.click(0, 0)
ActionChains(self._driver).key_down('c').key_up('c').perform()
events = w1_w1_w1.events
self.assertEqual(len(events), 2)
self.assertEqual(events[-2]['type'], 'keyPress')
self.assertEqual(events[-2]['key'], 'c')
self.assertEqual(events[-1]['type'], 'keyRelease')
self.assertEqual(events[-1]['key'], 'c')
self.assertEqual(len(w1_w1.events), 0)
self.assertEqual(len(w1.events), 0)
w1_w1.click(0, 0)
ActionChains(self._driver).key_down('b').key_up('b').perform()
events = w1_w1.events
self.assertEqual(len(events), 2)
self.assertEqual(events[-2]['type'], 'keyPress')
self.assertEqual(events[-2]['key'], 'b')
self.assertEqual(events[-1]['type'], 'keyRelease')
self.assertEqual(events[-1]['key'], 'b')
self.assertEqual(len(w1_w1_w1.events), 2)
self.assertEqual(len(w1.events), 0)
w1.click(0, 0)
ActionChains(self._driver).key_down('a').key_up('a').perform()
events = w1.events
self.assertEqual(len(events), 2)
self.assertEqual(events[-2]['type'], 'keyPress')
self.assertEqual(events[-2]['key'], 'a')
self.assertEqual(events[-1]['type'], 'keyRelease')
self.assertEqual(events[-1]['key'], 'a')
self.assertEqual(len(w1_w1_w1.events), 2)
self.assertEqual(len(w1_w1.events), 2)
def tearDown(self):
self._driver.quit()