diff options
Diffstat (limited to 'tests/unit/browser/test_pdfjs.py')
-rw-r--r-- | tests/unit/browser/test_pdfjs.py | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/tests/unit/browser/test_pdfjs.py b/tests/unit/browser/test_pdfjs.py index 9e99c4efa..cb5c26229 100644 --- a/tests/unit/browser/test_pdfjs.py +++ b/tests/unit/browser/test_pdfjs.py @@ -1,19 +1,6 @@ -# Copyright 2015 Daniel Schadt +# SPDX-FileCopyrightText: Daniel Schadt # -# 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 <https://www.gnu.org/licenses/>. +# SPDX-License-Identifier: GPL-3.0-or-later import logging import os.path @@ -206,6 +193,33 @@ def test_is_available(available, mocker): assert pdfjs.is_available() == available +@pytest.mark.parametrize('found_file', [ + "build/pdf.js", + "build/pdf.mjs", +]) +def test_get_pdfjs_js_path(found_file: str, monkeypatch: pytest.MonkeyPatch): + def fake_pdfjs_res(requested): + if requested.endswith(found_file): + return + raise pdfjs.PDFJSNotFound(requested) + + monkeypatch.setattr(pdfjs, 'get_pdfjs_res', fake_pdfjs_res) + assert pdfjs.get_pdfjs_js_path() == found_file + + +def test_get_pdfjs_js_path_none(monkeypatch: pytest.MonkeyPatch): + def fake_pdfjs_res(requested): + raise pdfjs.PDFJSNotFound(requested) + + monkeypatch.setattr(pdfjs, 'get_pdfjs_res', fake_pdfjs_res) + + with pytest.raises( + pdfjs.PDFJSNotFound, + match="Path 'build/pdf.js or build/pdf.mjs' not found" + ): + pdfjs.get_pdfjs_js_path() + + @pytest.mark.parametrize('mimetype, url, enabled, expected', [ # PDF files ('application/pdf', 'http://www.example.com', True, True), |