Commit Graph

18 Commits

Author SHA1 Message Date
Florian Bruhin
c225e724ac Merge remote-tracking branch 'origin/pr/4133' 2018-10-05 22:56:53 +02:00
Florian Bruhin
56b8447fb9 Use callback.assert_called_with() 2018-09-27 10:06:50 +02:00
Florian Bruhin
a27a8ada4d Use qtbot.wait_callback 2018-09-26 11:45:45 +02:00
Jesko Dujmovic
25e396faea
Merge branch 'master' into master 2018-09-13 22:06:04 +02:00
Florian Bruhin
f9327731b8 Handle UTF-8 byte order marks in Greasemonkey scripts
See e.g. https://github.com/jerone/UserScripts/issues/135
2018-09-12 23:54:32 +02:00
Jimmy
5252541fe3 greasemonkey: better handle scripts without metadata
Previously calling `script.code()` would fail if the script didn't have
a `name`. This wasn't being hit in practice because the only place that
constructs GreasemonkeyScripts was checking for that condition and add
the filename there as a fallback.

This change make the `name` attribute more explicitly mandatory by
failing with a `ValueError` if it is not provided and make it still
possible to use the filename fallback in that case by adding a
`filename` keyward argument to `__init__()`.

Additionally where `script_meta` is used in `script.code()` a fallback
to and emptry string was added so it doesn't fail for raw javascript
files without greasemonkey metadata.
2018-09-09 20:51:19 +12:00
Florian Bruhin
c9fddfe458 Fix lint 2018-06-09 23:00:57 +02:00
Jimmy
6573a4d616 Tell pylint to shut its fat mouth.
I just want to return something I can refer to the attributes of via dot
syntax without having to pointlessly write the names both when I declare
the data class and when I assign the variables.

Such a stupid warning.
2018-05-20 18:42:40 +12:00
Jimmy
b0d1a137da Greasemonkey: Don't attempt scope isolation on webkit
Since the JSCore used by WebKit 602.1 doesn't fully support Proxy and I
can't think of a way to provide isolation otherwise just revert to the
old behaviour in that case. I am checking for the specific WebKit
version because I'm pretty sure that version just happened to be
released when Proxy support was only partially done, any later release
will presumably have a newer JSCore where it works.

There I changed the indentation of a block in the jinja template which
will have inflated the diff.

I added mocking of `objects.backend` to the `webview` and
`webenginewebview` fixtures, I am pretty sure they are mutually
exclusive so don't expect any issues from that.

Because of the feature detection being at template compile time I had to
tweak the test setup to be done via a fixture instead of the setupClass
functionality that I was using before.
2018-05-20 18:42:40 +12:00
Jimmy
13249329f7 Greasemonkey: skip window scoping test on webkit
The implementation of Proxy in JSCore used by current QtWebkit (webkit
602.1) doesn't support the `set()` handler for whatever reason. So
instead of testing for a specific behaviour that we can't ensure on that
version let's just skip the tests and handle user complaints with
sympathy.
2018-05-20 18:42:40 +12:00
Jimmy
c7a9792b67 Greasemonkey: Add test for window scoping refinements.
Adds a test to codify what I think greasemonkey scripts expect from
their scope chains. Particularly that they can:

1. access the global `window` object
2. access all of the attributes of the global window object as global
   objects themselves
3. see any changes the page made to the global scope
4. write to attributes of `window` and have those attributes, and changes
   to existing attributes, accessable via global scope
5. do number 4 without breaking the pages expectations, that is what
   `unsafeWindow` is for

There are some other points about greasemonkey scripts' environment that
I believe to be true but am not testing in this change:

* changes a page makes to `window` _after_ a greasemonkey script is
  injected will still be visible to the script if it cares to check and
  it hasn't already shadowed them
* said changes will not overwrite changes that the greasemonkey script
  has made.
2018-05-20 18:42:40 +12:00
Jimmy
c5334fb683 Greasemonkey: use UrlPatterns for match directives
The greasemonkey `@match` directive is used to match urls against
chromium url patterns (as opposed to `@include` which treats its
argument as a glob expression). I was using fnmatch for both here
because I am lazy and knew someone else was going to implement chromium
url patterns for me eventually. Now it is done and I should switch to
using them instead. The most common failing case that this will fix is
something matching on `*://*.domain.com/*` because it wouldn't match
the url with no subdomain.

This codepath is only used on webengine 5.7.1 and webkit backends.
2018-04-14 10:31:20 +12:00
Jimmy
919fe45813 Greasemonkey: Add test for @require support.
There's is a lot of asserts in that one test but it tests everything.
2018-03-03 15:02:42 +13:00
Florian Bruhin
6f028e9ad0 Update copyright years 2018-02-05 12:19:50 +01:00
Jimmy
b2f95339ce Greasemonkey: support regexes in @include and @exclude.
Like the spec says, if a value for the @include or @exclude rules starts
and ends with a '/' it should be parsed as a regular expression.
Technically a ECMAScript syntax regular expression, but I am not sure of
the differences and I assume they are far fewer than the similarities.
One that I did see mentioned was that javascript RegExp doesn't support
unicode. Although it apparently does support a 'u' flag now.

Note that code will only be ran for QtWebkit and QWebEngine < 5.8
we rely on the builtin support for metadata it QWebEngine for most
things greasemonkey related. Sadly it seems that they missed the regex
requirement too. I've opened a ticket to track that https://bugreports.qt.io/browse/QTBUG-65484
2018-01-20 13:39:19 +13:00
Florian Bruhin
f033b228b1 Use py.path.local in save_script 2017-12-06 21:21:55 +01:00
Florian Bruhin
2633dcc0d5 Fix lint 2017-12-06 20:18:41 +01:00
Jimmy
92b48e77c7 Greasemonkey: add unit tests for GreasemonkeyManager 2017-11-27 20:10:38 +13:00