Commit Graph

6609 Commits

Author SHA1 Message Date
toofar 7444179a23 Update parsing of sandbox page on windows in tests
In the linux branch when it was doing:

    header, *lines, empty, result = text.split("\n")
    assert not empty

It was complaining that "empty" was "}", because the windows sandbox
page has JSON at the bottom now. The whole things looks to have changed
completely. I'm actually surprised it was working before, why would it
have been saying seccomp was enabled on windows?

Anyway, I did the debug-dump-text --plain that quteproc is doing in a VM
and tested this with sandboxing off an on. No idea how stable that will
be!

ref: https://github.com/qutebrowser/qutebrowser/issues/7989
2023-11-18 21:27:32 +13:00
toofar 6e534c74e7 Revert "walk_module workaround for PyInstaller"
This reverts commit 64af5f0e26.
2023-10-28 10:44:55 +13:00
toofar fea33d607f Check runtime Qt version only.
Since the bug was fixed in qtbase it shouldn't matter what version of
PyQt (or webengine for that matter) you are running against. So pass
`compiled=False`.

Also expand the docstring of `check_version()` to explain a little more
what the `compiled` kwarg does. Based on a discussion here:
https://github.com/qutebrowser/qutebrowser/pull/7933#issuecomment-1732400960

What's still not clear to me is when the runtime and compiled Qt
versions can differ. I always have to rebuild PyQt when I switch Qt
versions, but maybe I'm doing something wrong there.
2023-09-29 14:07:30 +13:00
toofar 65bfefe926 Use mocker fixture instead of mock.patch
I forgot about that fixture.
2023-09-27 18:59:27 +13:00
toofar 7b603dd6bf Move method to module level.
This avoids having to mess about with static methods. And makes the test a bit
clearer as we aren't passing a class in place of an instance anymore.

Hopefully I put it in the right place. It's above the class where it is used.
Should it be at the top of the file? Bottom of the file? IDK
2023-09-27 08:51:58 +13:00
toofar 5345d53418 Support wildcard mimes in filepicker workaround too
We've seen it in the wild, so it could happen, and it wasn't hard to add
in the end.

ref: #7866
2023-09-27 08:51:23 +13:00
toofar c0be28ebee Add extra suffixes to filepicker
Works around a Qt bug where QFileDialog might not see all the filename
extensions you have registered for a mimetype. There is an issue where
if you have suffixes (filename extensions) registered in your home dir
and in a system dir, it'll only see the ones in your home dir.
So get suffixes from python and proactively add them into the list the
list provided by the website. Duplicating work that Qt would already do,
if it weren't for the bug case we are working around.

Note that this does NOT help with mimetypes like `image/*` which, we
have seen in at least one example (on #7866). If we wanted to handle
that case it it looks like we could get the list from:

    [suffix for suffix, mime in mimetypes.types_map.items() if mime.startswith('image/')]

I added two tests. The first is a simple one but it felt a bit
imcomplete without actually testing that we were passing the right thing
to `super().chooseFiles()`. Not sure how "bad" it is to be mocking
`super()` and what should be instance methods unbound from the class.

Regarding the `qtutils.version_check()`, here we are only interested in
the Qt version check, but that class also checks the PyQt version. The
practical effect of this is that we would probably end up doing the
workaround for Qt 6.7.0 if we run against that with PyQt 6.6.x. But
since we are just adding stuff, it isn't slow and isn't called in a hot
path it doesn't really matter.
2023-09-27 08:51:23 +13:00
Florian Bruhin 690813e1b1 Fix lint 2023-09-26 10:35:22 +02:00
Florian Bruhin f8e7fea0be Merge remote-tracking branch 'origin/pr/7934' 2023-09-26 07:41:02 +02:00
Florian Bruhin a6171337f9 Skip test_real_chromium_version on newer Qt versions
Is wrong on unstable Archlinux env when Qt is newer than PyQt. But no need for this when we have the API anyways.
2023-09-25 18:05:35 +02:00
Florian Bruhin 01883a7ec4 tests: Ignore another spurious libva error 2023-09-25 16:59:56 +02:00
toofar fde4dd8434 Put qt.arg test back to being exact match
I previously changed the assertion to be a subset match, to deal with a qt arg
being added based on the Qt version the tests were being run on. I didn't
notice this fixture that can set setting to avoid that dynamic-ness instead.
2023-09-25 19:06:03 +13:00
toofar 2e961080a8 Make accelerated 2d canvas setting tristate with auto
I would like to be able to disable this workound for new enough chromium
versions (we still need to test that chrome 111 will be fixed, but we
can always bump it up later).

I also wanted to use the declarative mapping `_WEBENGINE_SETTINGS` instead
of adding a new conditional in `_qtwebengine_args`, because that just
seems nicer.

So I changed `_WEBENGINE_SETTINGS` so that the value could also be a
function. The idea is that the function returns on of the other values
based on some feature detection. This also required passing down the
args being used for feature detection in the calling method already.

I feel like that dict is being a bit abused here and if the entries
could be turned into objects with a bit more consistency it might be
nice. But this isn't too bad, right?

Had to change the `test_qt_args` test to be a superset test instead of
exact match because the new `--disable-accelerated-2d-canvas` arg was
showing up in the results based on whatever Qt version you happen to be
running the tests on.
2023-09-23 19:29:45 +12:00
Florian Bruhin 4190a470c5 Add qtutils.is_wayland()
Backported to v3.0.x as simpler fix: b317038a01
2023-09-18 18:09:26 +02:00
Florian Bruhin 96805e7d62 Remove hypothesis health check suppression
See https://github.com/HypothesisWorks/hypothesis/pull/3734
2023-09-11 11:11:26 +02:00
Florian Bruhin 04bd4117ad tests: Fix derp 2023-09-08 19:37:40 +02:00
Florian Bruhin 855be48b02 Fix lint 2023-09-08 19:16:26 +02:00
Florian Bruhin 3fabc8fe37 tests: Ignore false-positive (?) hypothesis health check
See https://github.com/HypothesisWorks/hypothesis/issues/3733
Should fix nightly builds (and the next dependency upgrade).
2023-09-08 12:04:37 +02:00
Florian Bruhin ae2e679dfc tests: Ignore some more irrelevant messages 2023-09-06 16:38:46 +02:00
toofar dec114df89 Merge pull request #7847 from pylbrecht/broken-hints
Allow navigating from file:// to remote origins via hints.

Previously you would have seen a "Your internet access is blocked"
chrome error page.
2023-09-05 22:31:21 +12:00
Philipp Albrecht ff6668f295 Generalize (testdata) substitution in end2end tests
We replace the `(testdata)` placeholder with `testutils.abs_datapath()` in a few end2end
tests. So far we only needed to replace `(testdata)` with an OS path (e.g. in
`tests/end2end/features/spawn.feature`). By introducing `(testdata)` to an end2end test
in `tests/end2end/features/hints.feature`, we required a new use case: replacing
`(testdata)` as part of a valid file:// URI.

```
When I open file://(testdata)/some/file.txt
```

Replacing `(testdata)` in above BDD step with a plain OS path resulted in invalid URIs,
e.g. for the path "C:\\Users" above BDD step results in this invalid URI:

```
When I open file://C:\Users/some/file.txt
```

We deal with this by first isolating the `(testdata)` substitution in a single place.
Having `(testdata)` substitutions in a single place, we simply special-case the substitution
of file:// paths, which will be part of a URI.
Successful substitution for above BDD step looks like the following:

```
When I open file:///C:/Users/some/file.txt
```
2023-09-05 12:20:02 +02:00
toofar e467adac9c Merge pull request #7834 from pylbrecht/purrr
Enforce digit limit (4300) on Count values passed by keypresses to avoid
segfaults due to cats sleeping on numpads.
2023-08-29 17:59:19 +12:00
Philipp Albrecht 43ca14aa53 Allow hinted navigation from file:// to remote origins
As of Qt 6 navigating from local to remote origins requires user interaction. This broke
following links to remote origins via hints from a local file (e.g. `bookmarks.html`),
because hints use JavaScript to open links by default.

Example:

1. Have a local `bookmarks.html`:
   ```html
   <!DOCTYPE html>
   <html>
       <head>
           <meta charset="utf-8">
           <title>My bookmarks</title>
       </head>
       <body>
           <a href="https://example.com/" id="link">some bookmark</a>
       </body>
   </html>
   ```
2. Open that local `bookmarks.html` in qutebrowser (e.g. `:open path/to/bookmarks.html`)
3. Start hinting
4. Follow a link to a bookmark (e.g. https://example.com/)
5. Instead of the link opening, be presented with `Your internet access is blocked`
   error

To fix this, we simply force a user interaction for all hints on file:// URLs (like we
did for `qute://` URLs in 8defe1ae44).

We skip the end2end test for webkit, because webkit does not support URLSearchParams[1]
used in `tests/end2end/data/hints/link_inject.html`

[1] https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
2023-08-28 13:17:08 +02:00
Philipp Albrecht 3974725932 Normalize end2end data directory path
Given the following scenario:
```
When I open file://(testdata)/some/file.html
Then file://(testdata)/some/file.html should be loaded
```
If the end2end data directory is not normalized, the scenario fails because we try to
compare

```
file:///home/palbrecht/dev/qutebrowser/tests/helpers/../end2end/data/hints/link_inject.html?port=50…
```

to

```
file:///home/palbrecht/dev/qutebrowser/tests/end2end/data/hints/link_inject.html?port=50…
```

Normalizing the path resolves the `..` and fixes the issue.
2023-08-28 13:17:08 +02:00
Philipp Albrecht 51aa7abe54 Handle count exceeding string to int conversion
When handling counts during keyparsing we convert the count string to an integer. If the
count is too high (i.e. the count string has too many digits), we run into Python's
integer string conversion length limit[1]:
```
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has
4301 digits; use sys.set_int_max_str_digits() to increase the limit
```

Instead of blowing up with an exception, we now handle this more gracefully by showing
an error message.

Reproducer:
```
$ qutebrowser --temp-basedir ":later 500 fake-key -g $(printf '1%.0s' {1..4301})j"
```

**NOTE:**
I had to rename `_debug_log()`'s `message` argument to `msg`, because pylint yelled at
me for redefined-outer-name[2].

[1] https://docs.python.org/3/library/stdtypes.html#integer-string-conversion-length-limitation
[2] https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/redefined-outer-name.html
2023-08-27 13:31:11 +02:00
Philipp Albrecht 21751603b4 Support opening file:// URLs in end2end tests
This is required to use BDD steps like the following:
```
When I open file://path/to/file.html
```

If we don't treat `file:` as a special scheme, we implicitly convert it to an invalid
URL:
```
http://localhost:48595/file:///path/to/file.html
```
2023-08-23 09:27:31 +02:00
Philipp Albrecht 42dfc82fb8 Use (testdata) in "I open {path}" BDD step 2023-08-23 09:26:07 +02:00
Florian Bruhin 8c2e23d248 Fix QHostInfo unit tests 2023-08-22 17:19:56 +02:00
Florian Bruhin 856d483724 Fix test on QtWebKit 2023-08-18 01:00:30 +02:00
Florian Bruhin 300bf173b8 Fix tests for new navigation request log output 2023-08-17 23:37:48 +02:00
Florian Bruhin a2697feb48 Work around back/forward navigation from qute://bookmark
With Qt 6.3+, user interaction is required to navigate outside of qute:// from a
qute:// page.

Follow-up to 8defe1ae44.
Also see 216a9f9a9b

Fixes #7815

See #7220 - should be revisited once we have a qute-bookmarks:// instead where
we can adjust permissions when registering the URL handler.
2023-08-17 23:00:04 +02:00
Philipp Albrecht 5faae69f77 Skip invalid history items when saving a session
Opening a download in a new tab leaves a "dead" tab (see example of a "dead" tab below)
behind. When saving a session containing such a "dead" tab, we end up with entries in
the session like this one:
```yaml
  - active: true
    history:
    - active: true
      last_visited: '1970-01-01T02:00:00'
      pinned: false
      scroll-pos:
        x: 0
        y: 0
      title: ''
      url: ''
      zoom: 1.0
```

When loading a session containing such a "dead" tab, qutebrowser does not restore any
history of that session and logs the following error:
```
ERROR: Failed to load session default: PyQt6.QtCore.QUrl('') is not valid
```

As pointed out by @The-Compiler in this comment[1], the behavior of
`QWebEngineHistoryItem::isValid()`[2] changed somehow between Qt 6.4 and 6.5.
`QWebEngineHistoryItem::isValid()` now returns `True` for "dead" tabs, even though the
history item is not valid (i.e. `url().isValid()` returns `False`).

To fix this we simply add an additional check if the URL is valid before adding a tab to
the session to be saved.

[1] https://github.com/qutebrowser/qutebrowser/issues/7696#issuecomment-1672854592
[2] https://github.com/qt/qtwebengine/blob/v6.5.2/src/core/api/qwebenginehistory.cpp#L69-L75
2023-08-16 09:39:51 +02:00
Florian Bruhin cbdf18919c Skip too flaky cross-origin focus test 2023-08-15 20:33:58 +02:00
Florian Bruhin a25e7c2b64 Fix remaining references to old commands
Follow-up to #7809, see #7214
2023-08-15 20:15:48 +02:00
Florian Bruhin 3fd8e12949 Merge remote-tracking branch 'origin/pr/7809' 2023-08-15 20:04:30 +02:00
Florian Bruhin b55a9f794b Rewrite cross-origin navigation test to use scrolling
Hopefully makes it more reliable
2023-08-15 19:29:45 +02:00
Florian Bruhin 66254e7e6e Fix bookmark tests, part 2 2023-08-15 16:51:08 +02:00
Florian Bruhin f819a189d4 Fix bookmark tests 2023-08-15 16:32:08 +02:00
Florian Bruhin 37d3f30f8b Fix issues with qute://start searching test 2023-08-15 16:27:22 +02:00
Florian Bruhin ec7664e93f Merge branch 'qt6-kbd-focus' 2023-08-15 16:26:44 +02:00
Florian Bruhin 19609fdb07 Add a test for keyboard focus after cross-origin navigation
Fails without the fix on main on QtWebEngine 6.4 (works on 6.2).
Works fine after the fix.

See #7820
2023-08-15 16:26:34 +02:00
Florian Bruhin f7846fc7aa tests: Don't encode headers set via Flask
See 5ff0a573f4

With that commit, encoding the header ourselves means that we'll actually be
navigating to the path `/b'data/...'` instead of `/data/...`.
2023-08-15 16:22:37 +02:00
Florian Bruhin 0d2afd58f3 Add qtutils.qobj_repr()
Shows objectName() and the metaObject().className() if available.

More debug info for #7820
2023-08-15 14:30:06 +02:00
Florian Bruhin 57421dcd99 Further stabilize urlmark end2end tests 2023-08-14 18:26:06 +02:00
Florian Bruhin 22e662e9b0 tests: Fix log ignore for newer Qt
Seems to show as 50 instead of 65 somehow...
2023-08-14 17:52:30 +02:00
toofar 0f2d34623c Merge remote-tracking branch 'upstream/main' into feat/mac_sandbox_pre_release_pyinstaller
Only conflict was the removal of support for 32bit builds in
build_release.py
2023-08-12 13:49:01 +12:00
toofar 64af5f0e26 walk_module workaround for PyInstaller
Restored from dd2fc8e10bb9d4a1bd0158110173793a18736d6b

Now that we are putting our data files in the qutebrowser/ directory
again pkgutil/importlib is getting confused by that dir existing and
returning us a FileLoader for `qutebrowser.components`, I think that's
what's happening anyway. Should try reverting that and this commit and
see if extensions get loaded right again.

So bring back this workaround of using the toc on the PyInstaller loader
to get the list of component modules for now.

ref: #7803
2023-08-12 13:36:50 +12:00
Philipp Albrecht d5faeef14c Rename :edit-command to :cmd-edit
Group commands related to commands/commandline by prefixing them with `cmd-`. In this
case we additionally renamed the command slightly to fit better with the `cmd-` prefix.
2023-08-11 09:02:17 +02:00
Philipp Albrecht 86925b58cb Rename :repeat-command to :cmd-repeat-last
Group commands related to commands/commandline by prefixing them with `cmd-`. In this
case we additionally renamed the command slightly to fit better with the `cmd-` prefix.
2023-08-11 09:02:12 +02:00
Philipp Albrecht f354d3ab91 Rename :run-with-count to :cmd-run-with-count
Group commands related to commands/commandline by prefixing them with `cmd-`.
2023-08-11 09:02:08 +02:00