From a1704ee6aa07e8bca7a1c4cf965f40a8255ffbc8 Mon Sep 17 00:00:00 2001 From: Mikolaj Boc Date: Wed, 22 Feb 2023 09:50:54 +0100 Subject: Correctly focus WASM windows on show MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since first requestActivate may happen before the window div is actually displayed on-screen, we need to sync Qt's activation state with DOM as soon as DOM element becomes visible. Focusing an invisible element is impossible. Fixes: QTBUG-79934 Change-Id: I04cf9b4ead006c9b8b135b3b6967d7938c581833 Reviewed-by: Morten Johan Sørvig --- tests/manual/wasm/qwasmwindow/qwasmwindow.py | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/manual/wasm/qwasmwindow/qwasmwindow.py') diff --git a/tests/manual/wasm/qwasmwindow/qwasmwindow.py b/tests/manual/wasm/qwasmwindow/qwasmwindow.py index a80e394cc22..04e16112209 100644 --- a/tests/manual/wasm/qwasmwindow/qwasmwindow.py +++ b/tests/manual/wasm/qwasmwindow/qwasmwindow.py @@ -29,6 +29,7 @@ class WidgetTestCase(unittest.TestCase): screen = Screen(self._driver, ScreenPosition.FIXED, x=0, y=0, width=600, height=600) window = Window(screen, x=100, y=100, width=200, height=200) + window.set_visible(True) self.assertEqual(window.rect, Rect(x=100, y=100, width=200, height=200)) window.drag(Handle.TOP_LEFT, direction=UP(10) + LEFT(10)) @@ -62,6 +63,7 @@ class WidgetTestCase(unittest.TestCase): screen = Screen(self._driver, ScreenPosition.FIXED, x=200, y=200, width=300, height=300) window = Window(screen, x=300, y=300, width=100, height=100) + window.set_visible(True) self.assertEqual(window.rect, Rect(x=300, y=300, width=100, height=100)) frame_rect_before_resize = window.frame_rect @@ -76,6 +78,7 @@ class WidgetTestCase(unittest.TestCase): screen = Screen(self._driver, ScreenPosition.FIXED, x=200, y=200, width=300, height=300) window = Window(screen, x=300, y=300, width=100, height=100) + window.set_visible(True) self.assertEqual(window.rect, Rect(x=300, y=300, width=100, height=100)) window.drag(Handle.TOP_WINDOW_BAR, direction=UP(30)) @@ -91,6 +94,7 @@ class WidgetTestCase(unittest.TestCase): screen = Screen(self._driver, ScreenPosition.RELATIVE, x=200, y=200, width=300, height=300) window = Window(screen, x=300, y=300, width=100, height=100) + window.set_visible(True) self.assertEqual(window.rect, Rect(x=300, y=300, width=100, height=100)) window.drag(Handle.TOP_WINDOW_BAR, direction=LEFT(300)) @@ -102,6 +106,7 @@ class WidgetTestCase(unittest.TestCase): container_width=500, container_height=7000) screen.scroll_to() window = Window(screen, x=300, y=2100, width=100, height=100) + window.set_visible(True) self.assertEqual(window.rect, Rect(x=300, y=2100, width=100, height=100)) window.drag(Handle.TOP_WINDOW_BAR, direction=LEFT(300)) @@ -111,6 +116,7 @@ class WidgetTestCase(unittest.TestCase): screen = Screen(self._driver, ScreenPosition.RELATIVE, x=200, y=200, width=300, height=300) window = Window(screen, x=300, y=300, width=100, height=100, title='Maximize') + window.set_visible(True) self.assertEqual(window.rect, Rect(x=300, y=300, width=100, height=100)) window.maximize() @@ -122,6 +128,9 @@ class WidgetTestCase(unittest.TestCase): windows = [Window(screen, x=50, y=50, width=100, height=100, title='First'), Window(screen, x=400, y=400, width=100, height=100, title='Second'), Window(screen, x=50, y=400, width=100, height=100, title='Third')] + for window in windows: + window.set_visible(True) + self.assertEqual(windows[0].rect, Rect(x=50, y=50, width=100, height=100)) self.assertEqual(windows[1].rect, Rect(x=400, y=400, width=100, height=100)) self.assertEqual(windows[2].rect, Rect(x=50, y=400, width=100, height=100)) @@ -140,6 +149,9 @@ class WidgetTestCase(unittest.TestCase): windows = [Window(screen, x=50, y=50, width=150, height=150, title='First'), Window(screen, x=400, y=400, width=150, height=150, title='Second'), Window(screen, x=50, y=400, width=150, height=150, title='Third')] + for window in windows: + window.set_visible(True) + self.assertEqual(windows[0].rect, Rect(x=50, y=50, width=150, height=150)) self.assertEqual(windows[1].rect, Rect(x=400, y=400, width=150, height=150)) self.assertEqual(windows[2].rect, Rect(x=50, y=400, width=150, height=150)) @@ -152,6 +164,21 @@ class WidgetTestCase(unittest.TestCase): self.assertEqual(windows[1].rect, Rect(x=400, y=420, width=150, height=130)) self.assertEqual(windows[2].rect, Rect(x=50, y=400, width=170, height=130)) + def test_newly_created_window_gets_keyboard_focus(self): + screen = Screen(self._driver, ScreenPosition.FIXED, + x=0, y=0, width=800, height=800) + window = Window(screen, x=0, y=0, width=800, height=800, title='root') + window.set_visible(True) + + ActionChains(self._driver).key_down('c').key_up('c').perform() + + events = window.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') + def tearDown(self): self._driver.quit() @@ -227,6 +254,20 @@ class Window: geo = self.__window_information()["frameGeometry"] return Rect(geo['x'], geo['y'], geo['width'], geo['height']) + @property + def events(self): + events = self.driver.execute_script( + f''' + return testSupport.events(); + ''' + ) + return [*filter(lambda e: e['windowTitle'] == self.title, events)] + + def set_visible(self, visible): + info = self.__window_information() + self.driver.execute_script( + f'''instance.setWindowVisible({info['id']}, {'true' if visible else 'false'});''') + def drag(self, handle, direction): ActionChains(self.driver) \ .move_to_element_with_offset(self.element, *self.at(handle)['offset']) \ -- cgit v1.2.3