From 348a50ad690a07afba19824a3631a9976fb2b07d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 6 Feb 2017 08:05:21 +0100 Subject: [PATCH] Fix inserting text with QtWebEngine The insertText event doesn't seem to be available with newer Chromium releases, which means this broke (probably with Qt 5.7.1). Fixes #2183 Fixes #2217 --- pytest.ini | 1 - qutebrowser/javascript/webelem.js | 5 ++--- tests/conftest.py | 5 ----- tests/end2end/features/editor.feature | 1 - tests/end2end/features/yankpaste.feature | 5 +---- 5 files changed, 3 insertions(+), 14 deletions(-) diff --git a/pytest.ini b/pytest.ini index e8fd3dd95..2285053a9 100644 --- a/pytest.ini +++ b/pytest.ini @@ -20,7 +20,6 @@ markers = qtwebengine_flaky: Tests which are flaky (and currently skipped) with QtWebEngine qtwebengine_osx_xfail: Tests which fail on OS X with QtWebEngine js_prompt: Tests needing to display a javascript prompt - issue2183: https://github.com/qutebrowser/qutebrowser/issues/2183 this: Used to mark tests during development qt_log_level_fail = WARNING qt_log_ignore = diff --git a/qutebrowser/javascript/webelem.js b/qutebrowser/javascript/webelem.js index 6e7209914..377a7575c 100644 --- a/qutebrowser/javascript/webelem.js +++ b/qutebrowser/javascript/webelem.js @@ -153,9 +153,8 @@ window._qutebrowser.webelem = (function() { funcs.insert_text = function(id, text) { var elem = elements[id]; - var event = document.createEvent("TextEvent"); - event.initTextEvent("textInput", true, true, null, text); - elem.dispatchEvent(event); + elem.focus(); + document.execCommand("insertText", false, text); }; funcs.element_at_pos = function(x, y) { diff --git a/tests/conftest.py b/tests/conftest.py index bafd1cf74..bcc4d4fe2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -130,11 +130,6 @@ def pytest_collection_modifyitems(config, items): item.add_marker(pytest.mark.skipif( PYQT_VERSION <= js_prompt_pyqt_version, reason='JS prompts are not supported with this PyQt version')) - if item.get_marker('issue2183'): - item.add_marker(pytest.mark.xfail( - config.webengine and qtutils.version_check('5.7.1'), - reason='https://github.com/qutebrowser/qutebrowser/issues/' - '2183')) if deselected: deselected_items.append(item) diff --git a/tests/end2end/features/editor.feature b/tests/end2end/features/editor.feature index 097ffd16f..947dba0b0 100644 --- a/tests/end2end/features/editor.feature +++ b/tests/end2end/features/editor.feature @@ -95,7 +95,6 @@ Feature: Opening external editors And I run :click-element id qute-button Then the javascript message "text: foobar" should be logged - @issue2183 Scenario: Spawning an editor with existing text When I set up a fake editor replacing "foo" by "bar" And I open data/editor.html diff --git a/tests/end2end/features/yankpaste.feature b/tests/end2end/features/yankpaste.feature index 9981f4b98..52c11ed22 100644 --- a/tests/end2end/features/yankpaste.feature +++ b/tests/end2end/features/yankpaste.feature @@ -247,7 +247,6 @@ Feature: Yanking and pasting. #### :insert-text - @issue2183 Scenario: Inserting text into an empty text field When I set general -> log-javascript-console to info And I open data/paste_primary.html @@ -257,7 +256,6 @@ Feature: Yanking and pasting. # Compare Then the javascript message "textarea contents: Hello world" should be logged - @issue2183 Scenario: Inserting text into an empty text field with javascript disabled When I set general -> log-javascript-console to info And I set content -> allow-javascript to false @@ -272,7 +270,6 @@ Feature: Yanking and pasting. # Compare Then the javascript message "textarea contents: Hello world" should be logged - @issue2183 Scenario: Inserting text into a text field at specific position When I set general -> log-javascript-console to info And I open data/paste_primary.html @@ -287,7 +284,7 @@ Feature: Yanking and pasting. # Compare Then the javascript message "textarea contents: onHello worlde two three four" should be logged - @qtwebengine_osx_xfail @issue2183 + @qtwebengine_osx_xfail Scenario: Inserting text into a text field with undo When I set general -> log-javascript-console to info And I open data/paste_primary.html