summaryrefslogtreecommitdiff
path: root/tests/unit/config/test_websettings.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-12-18 22:32:59 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-12-20 16:53:17 +0100
commit4151680e9388f5266677e77596f9989867a48fbd (patch)
tree681b7347c36bf30846693e03d130b6531a0cbdb9 /tests/unit/config/test_websettings.py
parent7330eb57be46a8fcb37366719069ef0e0b68899c (diff)
downloadqutebrowser-4151680e9388f5266677e77596f9989867a48fbd.tar.gz
qutebrowser-4151680e9388f5266677e77596f9989867a48fbd.zip
Refactor user agent handling
We now use a format string for the user_agent setting and parse both backend's default user agents to get the needed information. Fixes #513
Diffstat (limited to 'tests/unit/config/test_websettings.py')
-rw-r--r--tests/unit/config/test_websettings.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/unit/config/test_websettings.py b/tests/unit/config/test_websettings.py
new file mode 100644
index 000000000..916c8d609
--- /dev/null
+++ b/tests/unit/config/test_websettings.py
@@ -0,0 +1,92 @@
+# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2019 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+#
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
+
+import pytest
+
+from qutebrowser.config import websettings
+from qutebrowser.misc import objects
+from qutebrowser.utils import usertypes
+
+
+@pytest.mark.parametrize([
+ 'user_agent', 'os_info', 'webkit_version',
+ 'upstream_browser_key', 'upstream_browser_version', 'qt_key'
+], [
+ (
+ # QtWebEngine, Linux
+ # (no differences other than Chrome version with older Qt Versions)
+ ("Mozilla/5.0 (X11; Linux x86_64) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
+ "QtWebEngine/5.14.0 Chrome/77.0.3865.98 Safari/537.36"),
+ "X11; Linux x86_64",
+ "537.36",
+ "Chrome", "77.0.3865.98",
+ "QtWebEngine",
+ ), (
+ # QtWebKit, Linux
+ ("Mozilla/5.0 (X11; Linux x86_64) "
+ "AppleWebKit/602.1 (KHTML, like Gecko) "
+ "qutebrowser/1.8.3 "
+ "Version/10.0 Safari/602.1"),
+ "X11; Linux x86_64",
+ "602.1",
+ "Version", "10.0",
+ "Qt",
+ ), (
+ # QtWebEngine, macOS
+ ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
+ "QtWebEngine/5.13.2 Chrome/73.0.3683.105 Safari/537.36"),
+ "Macintosh; Intel Mac OS X 10_12_6",
+ "537.36",
+ "Chrome", "73.0.3683.105",
+ "QtWebEngine",
+ ), (
+ # QtWebEngine, Windows
+ ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
+ "QtWebEngine/5.12.5 Chrome/69.0.3497.128 Safari/537.36"),
+ "Windows NT 10.0; Win64; x64",
+ "537.36",
+ "Chrome", "69.0.3497.128",
+ "QtWebEngine",
+ )
+])
+def test_parse_user_agent(user_agent, os_info, webkit_version,
+ upstream_browser_key, upstream_browser_version,
+ qt_key):
+ parsed = websettings.UserAgent.parse(user_agent)
+ assert parsed.os_info == os_info
+ assert parsed.webkit_version == webkit_version
+ assert parsed.upstream_browser_key == upstream_browser_key
+ assert parsed.upstream_browser_version == upstream_browser_version
+ assert parsed.qt_key == qt_key
+
+
+def test_user_agent(monkeypatch, config_stub, qapp):
+ webenginesettings = pytest.importorskip(
+ "qutebrowser.browser.webengine.webenginesettings")
+ monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebEngine)
+ webenginesettings.init_user_agent()
+
+ config_stub.val.content.headers.user_agent = 'test {qt_key}'
+ assert websettings.user_agent() == 'test QtWebEngine'
+
+ config_stub.val.content.headers.user_agent = 'test2 {qt_key}'
+ assert websettings.user_agent() == 'test2 QtWebEngine'