Merge branch 'Kingdread-windows-userscripts'

This commit is contained in:
Florian Bruhin 2016-09-11 16:16:31 +02:00
commit 0d84ea9b8a
6 changed files with 40 additions and 20 deletions

View File

@ -157,6 +157,7 @@ Fixed
- The default `sk` keybinding now sets the commandline to `:bind` correctly
- Fixed hang when using multiple spaces in a row with the URL completion
- Fixed crash when closing a window without focusing it
- Userscripts now can access QUTE_FIFO correctly on Windows
v0.8.3 (unreleased)
-------------------

View File

@ -280,15 +280,8 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
This also means the userscript *has* to use >> (append) rather than >
(overwrite) to write to the file!
Attributes:
_oshandle: The oshandle of the temp file.
"""
def __init__(self, win_id, parent=None):
super().__init__(win_id, parent)
self._oshandle = None
def _cleanup(self):
"""Clean up temporary files after the userscript finished."""
if self._cleaned_up:
@ -301,12 +294,7 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
except OSError:
log.procs.exception("Failed to read command file!")
try:
os.close(self._oshandle)
except OSError:
log.procs.exception("Failed to close file handle!")
super()._cleanup()
self._oshandle = None
self.finished.emit()
@pyqtSlot()
@ -323,7 +311,9 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
self._kwargs = kwargs
try:
self._oshandle, self._filepath = tempfile.mkstemp(text=True)
handle = tempfile.NamedTemporaryFile(delete=False)
handle.close()
self._filepath = handle.name
except OSError as e:
message.error(self._win_id, "Error while creating tempfile: "
"{}".format(e))

View File

@ -0,0 +1,6 @@
@echo off
rem This is needed because echo does not exist as an external program on
rem Windows, so we can't call echo(.exe) from qutebrowser, but it's useful for
rem tests. This little file is callable via :spawn and mimics (in a very naive
rem way) the echo command line utility.
echo %*

View File

@ -0,0 +1 @@
echo open -t %QUTE_URL% >> "%QUTE_FIFO%"

View File

@ -36,6 +36,18 @@ from qutebrowser.browser import pdfjs
from helpers import utils
def _get_echo_exe_path():
"""Return the path to an echo-like command, depending on the system.
Return:
Path to the "echo"-utility.
"""
if sys.platform == "win32":
return os.path.join(utils.abs_datapath(), 'userscripts', 'echo.bat')
else:
return 'echo'
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
"""Add a BDD section to the test output."""
@ -224,6 +236,7 @@ def run_command(quteproc, httpbin, tmpdir, command):
command = command.replace('(testdata)', utils.abs_datapath())
command = command.replace('(tmpdir)', str(tmpdir))
command = command.replace('(dirsep)', os.sep)
command = command.replace('(echo-exe)', _get_echo_exe_path())
quteproc.send_cmd(command, count=count, invalid=invalid)

View File

@ -1,7 +1,7 @@
Feature: :spawn
Scenario: Running :spawn
When I run :spawn -v echo "Hello"
When I run :spawn -v (echo-exe) "Hello"
Then the message "Command exited successfully." should be shown
Scenario: Running :spawn with command that does not exist
@ -19,18 +19,18 @@ Feature: :spawn
Then the error "Error while splitting command: No closing quotation" should be shown
Scenario: Running :spawn with url variable
When I run :spawn echo {url}
Then "Executing echo with args ['about:blank'], userscript=False" should be logged
When I run :spawn (echo-exe) {url}
Then "Executing * with args ['about:blank'], userscript=False" should be logged
Scenario: Running :spawn with url variable in fully encoded format
When I open data/title with spaces.html
And I run :spawn echo {url}
Then "Executing echo with args ['http://localhost:(port)/data/title%20with%20spaces.html'], userscript=False" should be logged
And I run :spawn (echo-exe) {url}
Then "Executing * with args ['http://localhost:(port)/data/title%20with%20spaces.html'], userscript=False" should be logged
Scenario: Running :spawn with url variable in pretty decoded format
When I open data/title with spaces.html
And I run :spawn echo {url:pretty}
Then "Executing echo with args ['http://localhost:(port)/data/title with spaces.html'], userscript=False" should be logged
And I run :spawn (echo-exe) {url:pretty}
Then "Executing * with args ['http://localhost:(port)/data/title with spaces.html'], userscript=False" should be logged
@posix
Scenario: Running :spawn with userscript
@ -40,3 +40,12 @@ Feature: :spawn
Then the following tabs should be open:
- about:blank
- about:blank (active)
@windows
Scenario: Running :spawn with userscript on Windows
When I open about:blank
And I run :spawn -u (testdata)/userscripts/open_current_url.bat
And I wait until about:blank is loaded
Then the following tabs should be open:
- about:blank
- about:blank (active)