Commit Graph

15746 Commits

Author SHA1 Message Date
Jimmy
749b29e599 tests: Don't pretend to be using webkit if unavailable
Since `objects.backend` was being set to usertypes.Backend.QtWebKit by
default some feature detection code was calling
`version.qWebKitVersion()` which was failing because the import of
`PyQt5.QtWebKit` was failing in version.

This should not change behavior where both backends are available on if
any tests fail because they are expecting their environment to say they
are on webkit when they either aren't actually using any webkit features
or all mocked webkit features then they should probably be changed to
patch `objects.backend` or not depend on it.
2018-05-21 20:59:27 +12:00
Jimmy
d162e01422 Greasemonkey: remove extra window scope IIFE
Also change the block scoped `window` declaration to be const because it
seemed like a good idea. The real window seems to just silently ignore
attempts to overwrite it.
2018-05-20 18:42:40 +12: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
19242b6cb2 Greasemonkey: fix scoping function decleration.
Apparently making a function like `function foo() {};` in block scope is
illegal. It should be named via assignment.

Switched to an IIFE anyway because it doesn't need a name.
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
23bfe6daa2 Greasemonkey: fix window proxy for new attributes
Previously scripts were failing to find attributes that they assigned to
window and then tried to use from the global scope. Eg

    window.newthing = function() {...};
    newthing(...);  // newthing is not defined error

This wasn't the case for things that already existed in the global scope
and were just being overwritten.

This change just overrides the `Proxy.has()` function which seems to fix
it. Probably the `while` implementation was failing to pick up new
attributes because of the lack.

I also tweaked some comments and variable names and const-ness to be a
little more production ready.
2018-05-20 18:42:40 +12:00
Jimmy
ab50ad735b Greasemonkey: isolates scripts' writes to window
Since the global namespace of javascript in the browser is accessible
there where issues with scripts clobbering things that the page expected
to be attributes of window pages clobbering things that userscripts
saved to `window`. The latter was occuring with OneeChan. OneeChan was
setting `window.$` to a function that took a css selector and the 4chan
catalog script was setting `window.$` to some object. Since OneeChan was
set to run at document-start this broke OneeChan, switching it to
document-end broke scripts on 4chan.

I used OneeChan and 4chan-X on 4chan as the test case for this and
TamperMonkey as a guide for what is the correct way to handle scoping. I
didn't manage to pick apart just how TamperMonkey does what it does (I
think it might just be the environment that Chrome provides extensions
actually) but I got close to the same behaviour.

TamperMonkey provides a `window` object that appears to be what the
global window looked like before the webpage modified it. The global
scope though does have the pages modifications accessible. If the script
assigns something to an attribute `window` it can see that attribute in
the global scope. This implementation differs from that one in that, to
the scipt, `window` and the global scope always look the same, and that
is the same as the global scope looks in the environment provided by
TamperMonkey.

I am using the ES6 `Proxy` feature to allow the `window` object to look
like the actual (unsafe) one while allowing writing to it that doesn't
clobber the unsafe one. I am then using the ES4 `with` function to make
attributes of that window (proxy) object visible in the scope chain.
There may be other ways to do this without using `with` by using nested
functions and setting `this` creatively. There are notes around
alleging `with` to be various states of uncool[1].

I also ran into an issue where a userscript calling
`window.addEventListener(...)` would fail with `TypeError: Illegal
Execution` which is apparently due to `this` not being set correctly. I
looked at the functions which threw that error and those that didn't and
am using whether they have a `prototype` attribute or not to tell
whether I need to bind them with `window` as `this`. I am not sure how
correct that is but it worked for all the cases I ran into.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with
2018-05-20 18:42:40 +12:00
Florian Bruhin
046c0a7ea2 Merge remote-tracking branch 'origin/pr/3914' 2018-05-17 17:53:47 +02:00
Florian Bruhin
d208c48532 Update changelog 2018-05-17 17:53:15 +02:00
Florian Bruhin
dacca0d2ed Remove double settings 2018-05-17 15:54:26 +02:00
Florian Bruhin
6ccd69dad2 Fix reload for JavaScript support on Qt 5.11 2018-05-17 15:54:17 +02:00
Florian Bruhin
d8569a36f9 Update changelog 2018-05-17 14:24:29 +02:00
Florian Bruhin
44d26f77a5 Add workaround for the "split page" Qt bug (QTBUG-68224)
Fixes #3920
2018-05-17 14:21:14 +02:00
Florian Bruhin
6eadff4a10 Add Python executable to :version 2018-05-14 22:13:15 +02:00
pyup-bot
6784356d9d Update hypothesis from 3.56.5 to 3.56.9 2018-05-14 18:48:20 +02:00
pyup-bot
b0105b0157 Update python-dateutil from 2.7.2 to 2.7.3 2018-05-14 18:48:18 +02:00
pyup-bot
553a91c012 Update python-dateutil from 2.7.2 to 2.7.3 2018-05-14 18:48:17 +02:00
pyup-bot
b0f83615b6 Update wheel from 0.31.0 to 0.31.1 2018-05-14 18:48:15 +02:00
pyup-bot
0c674c7110 Update flake8-builtins from 1.3.1 to 1.4.1 2018-05-14 18:48:14 +02:00
Florian Bruhin
48c44e1b4d Fix and update docs 2018-05-08 15:22:49 +02:00
Florian Bruhin
20efaeff19 Improve configuration docs 2018-05-08 14:57:56 +02:00
Florian Bruhin
d194a8ddb0
Merge pull request #3898 from qutebrowser/pyup-scheduled-update-2018-05-07
Scheduled weekly dependency update for week 18
2018-05-08 14:21:23 +02:00
Florian Bruhin
c8d539a4c6 Update changelog 2018-05-08 11:46:07 +02:00
Florian Bruhin
8531f89ca3 Merge remote-tracking branch 'origin/pr/3789' 2018-05-08 11:45:20 +02:00
Florian Bruhin
4fee9b9637 Update changelog 2018-05-08 11:44:06 +02:00
Florian Bruhin
89a1c43b4c Merge remote-tracking branch 'origin/pr/3790' 2018-05-08 11:43:30 +02:00
Florian Bruhin
a39858c436 Update changelog 2018-05-08 11:41:14 +02:00
Florian Bruhin
b718c8b43a Merge remote-tracking branch 'origin/pr/3899' 2018-05-08 11:40:43 +02:00
Florian Bruhin
b28bfbe8f5 Update docs 2018-05-08 11:39:35 +02:00
Florian Bruhin
70c7a42a63 Merge remote-tracking branch 'origin/pr/3900' 2018-05-08 11:37:52 +02:00
Florian Bruhin
648b1219a2 Filter flake8-builtins 1.4.0
See https://github.com/gforcada/flake8-builtins/issues/36
2018-05-08 11:34:17 +02:00
Florian Bruhin
d005088b6b Add missing fake_args fixture 2018-05-08 11:26:45 +02:00
Jay Kamat
906da44d70
Simplify visited link clearing by looping over connections 2018-05-07 14:10:20 -07:00
Jay Kamat
ca48f9f100
Clear url from visitedLinks if a single url is deleted 2018-05-07 13:48:38 -07:00
Jay Kamat
d0b2360745
Clear visited links db when running :history-clear on webengine 2018-05-07 13:35:41 -07:00
Pol Van Aubel
f1b481dcc7 Short options for --debug and --debug-flags 2018-05-07 22:35:32 +02:00
Pol Van Aubel
431a52da6c Short options for --basedir and --temp-basedir 2018-05-07 22:10:08 +02:00
pyup-bot
b109fc569f Update pytest-mock from 1.9.0 to 1.10.0 2018-05-07 18:39:22 +02:00
pyup-bot
fcd98443f9 Update flask from 1.0.1 to 1.0.2 2018-05-07 18:39:21 +02:00
pyup-bot
e455d8c13a Update pep8-naming from 0.5.0 to 0.6.1 2018-05-07 18:39:19 +02:00
pyup-bot
d4e5a2eb7f Update flake8-builtins from 1.3.1 to 1.4.0 2018-05-07 18:39:18 +02:00
pyup-bot
a4424f2863 Update attrs from 17.4.0 to 18.1.0 2018-05-07 18:39:17 +02:00
pyup-bot
9e33f1a275 Update attrs from 17.4.0 to 18.1.0 2018-05-07 18:39:15 +02:00
pyup-bot
470c392ee0 Update attrs from 17.4.0 to 18.1.0 2018-05-07 18:39:13 +02:00
Florian Bruhin
b9fc068af5 Add a log-requests debug-flag 2018-05-07 10:23:56 +02:00
Florian Bruhin
7762017f00 Release v1.3.0 2018-05-03 19:25:04 +02:00
Florian Bruhin
2ba40acf74 Update changelog for v1.3.0 2018-05-03 19:25:04 +02:00
Florian Bruhin
388c155ebb Add test for #3753 2018-05-03 18:02:20 +02:00