Commit Graph

72 Commits

Author SHA1 Message Date
Florian Bruhin
94542c5f78 Merge branch 'greasemonkey-quirks' 2019-02-25 09:56:18 +01:00
Florian Bruhin
8642b6e8ce Fix JSTester.run_file() for new pkg_resources
Read the file via open() instead of utils.read_file.
2019-02-25 09:28:25 +01:00
Florian Bruhin
0e11b85474 Re-enable stylesheet tests for Qt 5.12
This partially reverts commit 0953596ed6.
This reverts commit 0aa342eae6.
2019-02-25 09:28:25 +01:00
Florian Bruhin
6dd978ae05 GreaseMonkey: Force document-end for known-broken scripts
See #4322
2019-02-23 12:52:30 +01:00
Jay Kamat
3e816f5f8b
Update copyright for 2019 2019-02-22 21:45:08 -08:00
Florian Bruhin
0953596ed6 Skip remaining tests which are broken on Qt 5.12
See #4320, #4244
2018-12-11 18:36:52 +01:00
Florian Bruhin
0aa342eae6 Mark test_appendchild as xfail on Qt 5.12
See #4244
2018-12-11 11:05:06 +01:00
Florian Bruhin
f6c36ccbee Rename openurl to load_url
We still call the :open command openurl, but in the tab API and in
TabbedBrowser it's now called load_url.
2018-11-30 08:31:03 +01:00
Florian Bruhin
c225e724ac Merge remote-tracking branch 'origin/pr/4133' 2018-10-05 22:56:53 +02:00
Florian Bruhin
718376f154 Refactor JS escaping
This renames javascript.convert_js_arg() to javascript.to_js() and uses that
instead of string_escape() where possible.
2018-09-27 16:36:28 +02:00
Florian Bruhin
905863f74e Fix lint 2018-09-27 10:08:50 +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
Florian Bruhin
4932cc4d24 Merge remote-tracking branch 'origin/pr/3804' 2018-05-03 13:33:08 +02:00
Florian Bruhin
d2207f66f1 Skip test_set_error entirely
See #3771
2018-04-16 17:14:14 +02: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
Florian Bruhin
2249a88e3a Make test_simple_js_webengine work correctly 2018-03-27 07:29:43 +02:00
Florian Bruhin
6dbd6d1ddf Move test_qt_javascript.py 2018-03-27 07:14:05 +02:00
Florian Bruhin
a5f1022330 Log document.body in JS tests 2018-03-20 11:56:46 +01:00
Florian Bruhin
85d3d4baba Mark test_set_error as flaky 2018-03-20 10:25:03 +01:00
Florian Bruhin
561295238d Another try at stabilizing test_set_error 2018-03-20 08:58:48 +01:00
Florian Bruhin
81827a3150 Try to stabilize stylesheet tests 2018-03-20 07:05:03 +01:00
Florian Bruhin
ea1e52ea7c Load page before loading stylesheets
If we don't do this, when doing:

   self.config_stub.val.content.user_stylesheets = css_path

then _update_stylesheet gets called before the stylesheet QWebEngineScript did
run (as there was no load yet), so we get:

  [:2] Uncaught TypeError: Cannot read property 'stylesheet' of undefined!

Instead, load the page first and then update the stylesheet.
This tests that live updating works properly, and also makes sure we don't run
into the problem described above.
2018-03-19 21:44:47 +01:00
Florian Bruhin
b588f54a53 Fail javascript tests on logging messages 2018-03-19 20:43:55 +01:00
Florian Bruhin
1162e640c5 Remove unused imports 2018-03-19 19:42:56 +01:00
Florian Bruhin
0ea7a1457d Make test_position_caret work again
The tests only work properly with QtWebKit (and aren't needed on QtWebEngine).
Also, for some reason the scrolled_down tests only work without Xvfb.
2018-03-19 19:38:21 +01:00
Florian Bruhin
f5d7605ae0 Add a :scroll-to-anchor command
Fixes #2784
2018-03-19 19:18:33 +01:00
Florian Bruhin
460bd86579 Initial attempt at using the tab API for tests/unit/javascript 2018-03-19 18:18:21 +01:00
Florian Bruhin
232fd19422 Fix unit tests after refactoring 2018-03-19 09:53:35 +01: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
430126dcc8 pylint: Re-enable ungrouped-imports 2017-12-15 23:08:53 +01: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
Florian Bruhin
6a90cebe85 Get rid of backslash 2017-11-19 14:29:22 +01:00
Jay Kamat
6338810396
Increase timeouts for javascript tests 2017-11-17 21:42:24 -05:00
Jay Kamat
6c241f96ed
Add test for appendChild #2723
Does some of #3295
2017-11-17 17:52:35 -05:00
Jay Kamat
92a6e61b52
Use importorskip to skip stylesheet tests on webkit only systems 2017-11-15 02:05:34 -05:00
Jay Kamat
28572ce3b1
Fix stylesheet tests crashing when no QtWebEngine available 2017-11-14 00:00:53 -05:00
Jay Kamat
5913552dfe
Fix style issues in stylesheet tests 2017-11-13 19:57:11 -05:00