| 1 |
import pytest |
| 2 |
from support.addons import ( |
| 3 |
get_ids_for_installed_addons, |
| 4 |
is_addon_private_browsing_allowed, |
| 5 |
is_addon_temporary_installed, |
| 6 |
) |
| 7 |
from tests.support.asserts import assert_error, assert_success |
| 8 |
from tests.support.helpers import get_extension_path |
| 9 |
|
| 10 |
from . import ADDON_ID, install_addon, uninstall_addon |
| 11 |
|
| 12 |
|
| 13 |
def test_install_invalid_addon(session): |
| 14 |
response = install_addon(session, "path", get_extension_path("firefox/invalid.xpi")) |
| 15 |
assert_error(response, "unknown error") |
| 16 |
|
| 17 |
|
| 18 |
def test_install_nonexistent_addon(session): |
| 19 |
response = install_addon(session, "path", get_extension_path("does-not-exist.xpi")) |
| 20 |
assert_error(response, "unknown error") |
| 21 |
|
| 22 |
|
| 23 |
@pytest.mark.allow_system_access |
| 24 |
@pytest.mark.parametrize("value", [True, False], ids=["required", "not required"]) |
| 25 |
def test_install_unsigned_addon_with_signature(session, use_pref, value): |
| 26 |
# Even though "xpinstall.signatures.required" preference is enabled in Firefox by default, |
| 27 |
# it's disabled for wpt tests, so test both values here. |
| 28 |
use_pref("xpinstall.signatures.required", value) |
| 29 |
|
| 30 |
response = install_addon( |
| 31 |
session, "path", get_extension_path("firefox/unsigned.xpi"), False |
| 32 |
) |
| 33 |
|
| 34 |
if value is True: |
| 35 |
assert_error(response, "unknown error") |
| 36 |
else: |
| 37 |
addon_id = assert_success(response) |
| 38 |
|
| 39 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 40 |
|
| 41 |
try: |
| 42 |
assert addon_id in installed_addon_ids |
| 43 |
assert addon_id == ADDON_ID |
| 44 |
assert is_addon_temporary_installed(session, addon_id) is False |
| 45 |
finally: |
| 46 |
# Clean up the addon. |
| 47 |
uninstall_addon(session, addon_id) |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.allow_system_access |
| 51 |
def test_temporary_install_unsigned_addon(session): |
| 52 |
response = install_addon( |
| 53 |
session, "path", get_extension_path("firefox/unsigned.xpi"), True |
| 54 |
) |
| 55 |
addon_id = assert_success(response) |
| 56 |
|
| 57 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 58 |
|
| 59 |
try: |
| 60 |
assert addon_id in installed_addon_ids |
| 61 |
assert addon_id == ADDON_ID |
| 62 |
assert is_addon_temporary_installed(session, addon_id) is True |
| 63 |
finally: |
| 64 |
# Clean up the addon. |
| 65 |
uninstall_addon(session, addon_id) |
| 66 |
|
| 67 |
|
| 68 |
@pytest.mark.allow_system_access |
| 69 |
@pytest.mark.parametrize("temporary", [True, False]) |
| 70 |
def test_install_signed_addon(session, temporary): |
| 71 |
response = install_addon( |
| 72 |
session, "path", get_extension_path("firefox/signed.xpi"), temporary |
| 73 |
) |
| 74 |
addon_id = assert_success(response) |
| 75 |
|
| 76 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 77 |
|
| 78 |
try: |
| 79 |
assert addon_id in installed_addon_ids |
| 80 |
assert addon_id == ADDON_ID |
| 81 |
assert is_addon_temporary_installed(session, addon_id) is temporary |
| 82 |
finally: |
| 83 |
# Clean up the addon. |
| 84 |
uninstall_addon(session, addon_id) |
| 85 |
|
| 86 |
|
| 87 |
@pytest.mark.allow_system_access |
| 88 |
def test_install_mixed_separator_windows(session): |
| 89 |
os = session.capabilities["platformName"] |
| 90 |
|
| 91 |
# Only makes sense to test on Windows. |
| 92 |
if os == "windows": |
| 93 |
# Ensure the base path has only \ |
| 94 |
addon_path = get_extension_path("firefox").replace("/", "\\") |
| 95 |
addon_path += "/signed.xpi" |
| 96 |
|
| 97 |
response = install_addon(session, "path", addon_path, False) |
| 98 |
addon_id = assert_success(response) |
| 99 |
|
| 100 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 101 |
|
| 102 |
try: |
| 103 |
assert addon_id in installed_addon_ids |
| 104 |
assert addon_id == ADDON_ID |
| 105 |
assert is_addon_temporary_installed(session, addon_id) is False |
| 106 |
finally: |
| 107 |
# Clean up the addon. |
| 108 |
uninstall_addon(session, addon_id) |
| 109 |
|
| 110 |
|
| 111 |
@pytest.mark.allow_system_access |
| 112 |
@pytest.mark.parametrize("allow_private_browsing", [True, False]) |
| 113 |
def test_install_addon_with_private_browsing(session, allow_private_browsing): |
| 114 |
response = install_addon( |
| 115 |
session, |
| 116 |
"path", |
| 117 |
get_extension_path("firefox/signed.xpi"), |
| 118 |
False, |
| 119 |
allow_private_browsing, |
| 120 |
) |
| 121 |
addon_id = assert_success(response) |
| 122 |
|
| 123 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 124 |
|
| 125 |
try: |
| 126 |
assert addon_id in installed_addon_ids |
| 127 |
assert addon_id == ADDON_ID |
| 128 |
assert ( |
| 129 |
is_addon_private_browsing_allowed(session, addon_id) |
| 130 |
is allow_private_browsing |
| 131 |
) |
| 132 |
finally: |
| 133 |
# Clean up the addon. |
| 134 |
uninstall_addon(session, addon_id) |