| 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_base64_for_extension_file |
| 9 |
|
| 10 |
from . import ADDON_ID, install_addon, uninstall_addon |
| 11 |
|
| 12 |
|
| 13 |
def test_install_invalid_addon(session): |
| 14 |
response = install_addon(session, "addon", "aGVsbG8=") |
| 15 |
assert_error(response, "unknown error") |
| 16 |
|
| 17 |
|
| 18 |
@pytest.mark.allow_system_access |
| 19 |
@pytest.mark.parametrize("value", [True, False], ids=["required", "not required"]) |
| 20 |
def test_install_unsigned_addon_with_signature(session, use_pref, value): |
| 21 |
# Even though "xpinstall.signatures.required" preference is enabled in Firefox by default, |
| 22 |
# it's disabled for wpt tests, so test both values here. |
| 23 |
use_pref("xpinstall.signatures.required", value) |
| 24 |
|
| 25 |
response = install_addon( |
| 26 |
session, "addon", get_base64_for_extension_file("firefox/unsigned.xpi"), False |
| 27 |
) |
| 28 |
|
| 29 |
if value is True: |
| 30 |
assert_error(response, "unknown error") |
| 31 |
else: |
| 32 |
addon_id = assert_success(response) |
| 33 |
|
| 34 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 35 |
|
| 36 |
try: |
| 37 |
assert addon_id in installed_addon_ids |
| 38 |
assert addon_id == ADDON_ID |
| 39 |
assert is_addon_temporary_installed(session, addon_id) is False |
| 40 |
finally: |
| 41 |
# Clean up the addon. |
| 42 |
uninstall_addon(session, addon_id) |
| 43 |
|
| 44 |
|
| 45 |
@pytest.mark.allow_system_access |
| 46 |
def test_install_unsigned_addon_temporarily(session): |
| 47 |
response = install_addon( |
| 48 |
session, "addon", get_base64_for_extension_file("firefox/unsigned.xpi"), True |
| 49 |
) |
| 50 |
addon_id = assert_success(response) |
| 51 |
|
| 52 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 53 |
|
| 54 |
try: |
| 55 |
assert addon_id in installed_addon_ids |
| 56 |
assert addon_id == ADDON_ID |
| 57 |
assert is_addon_temporary_installed(session, addon_id) is True |
| 58 |
finally: |
| 59 |
# Clean up the addon. |
| 60 |
uninstall_addon(session, addon_id) |
| 61 |
|
| 62 |
|
| 63 |
@pytest.mark.allow_system_access |
| 64 |
@pytest.mark.parametrize("temporary", [True, False]) |
| 65 |
def test_install_signed_addon(session, temporary): |
| 66 |
response = install_addon( |
| 67 |
session, "addon", get_base64_for_extension_file("firefox/signed.xpi"), temporary |
| 68 |
) |
| 69 |
addon_id = assert_success(response) |
| 70 |
|
| 71 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 72 |
|
| 73 |
try: |
| 74 |
assert addon_id in installed_addon_ids |
| 75 |
assert addon_id == ADDON_ID |
| 76 |
assert is_addon_temporary_installed(session, addon_id) is temporary |
| 77 |
finally: |
| 78 |
# Clean up the addon. |
| 79 |
uninstall_addon(session, addon_id) |
| 80 |
|
| 81 |
|
| 82 |
@pytest.mark.allow_system_access |
| 83 |
@pytest.mark.parametrize("allow_private_browsing", [True, False]) |
| 84 |
def test_install_addon_with_private_browsing(session, allow_private_browsing): |
| 85 |
response = install_addon( |
| 86 |
session, |
| 87 |
"addon", |
| 88 |
get_base64_for_extension_file("firefox/signed.xpi"), |
| 89 |
False, |
| 90 |
allow_private_browsing, |
| 91 |
) |
| 92 |
addon_id = assert_success(response) |
| 93 |
|
| 94 |
installed_addon_ids = get_ids_for_installed_addons(session) |
| 95 |
|
| 96 |
try: |
| 97 |
assert addon_id in installed_addon_ids |
| 98 |
assert addon_id == ADDON_ID |
| 99 |
assert ( |
| 100 |
is_addon_private_browsing_allowed(session, addon_id) |
| 101 |
is allow_private_browsing |
| 102 |
) |
| 103 |
finally: |
| 104 |
# Clean up the addon. |
| 105 |
uninstall_addon(session, addon_id) |