-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chromewebstoreprovider.py
More file actions
189 lines (158 loc) · 6.95 KB
/
test_chromewebstoreprovider.py
File metadata and controls
189 lines (158 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import json
import tempfile
from pathlib import Path
from abxpkg import Binary, ChromeWebstoreProvider
PACKAGED_CHROME_UTILS_PATH = (
Path(__file__).resolve().parent.parent
/ "abxpkg"
/ "js"
/ "chrome"
/ "chrome_utils.js"
)
UBLOCK_WEBSTORE_ID = "cjpalhdlnbpafiamejdnhcphjbkeiagm"
def assert_extension_binary_loaded(loaded) -> None:
assert loaded is not None
assert loaded.is_valid
assert loaded.loaded_binprovider is not None
assert loaded.loaded_binprovider.name == "chromewebstore"
assert loaded.loaded_abspath is not None
assert loaded.loaded_abspath.name == "manifest.json"
assert loaded.loaded_abspath.exists()
assert loaded.loaded_version is not None
assert loaded.loaded_sha256 is not None
manifest = json.loads(loaded.loaded_abspath.read_text(encoding="utf-8"))
assert manifest["version"] == str(loaded.loaded_version)
class TestChromeWebstoreProvider:
def test_install_root_alias_without_explicit_bin_dir_uses_root_extensions(
self,
test_machine,
):
test_machine.require_tool("node")
assert PACKAGED_CHROME_UTILS_PATH.exists(), PACKAGED_CHROME_UTILS_PATH
with tempfile.TemporaryDirectory() as temp_dir:
install_root = Path(temp_dir) / "chromewebstore-root"
provider = ChromeWebstoreProvider.model_validate(
{
"install_root": install_root,
"postinstall_scripts": True,
"min_release_age": 0,
},
).get_provider_with_overrides(
overrides={
"ublock": {
"install_args": [UBLOCK_WEBSTORE_ID, "--name=ublock"],
},
},
)
installed = provider.install("ublock")
assert_extension_binary_loaded(installed)
assert installed is not None
bin_dir = provider.bin_dir
assert bin_dir is not None
assert provider.install_root == install_root
assert bin_dir == install_root / "extensions"
assert installed.loaded_abspath is not None
assert installed.loaded_abspath.is_relative_to(bin_dir)
def test_install_root_and_bin_dir_aliases_install_into_the_requested_paths(
self,
test_machine,
):
test_machine.require_tool("node")
assert PACKAGED_CHROME_UTILS_PATH.exists(), PACKAGED_CHROME_UTILS_PATH
with tempfile.TemporaryDirectory() as temp_dir:
install_root = Path(temp_dir) / "chromewebstore-root"
bin_dir = Path(temp_dir) / "custom-extensions"
provider = ChromeWebstoreProvider.model_validate(
{
"install_root": install_root,
"bin_dir": bin_dir,
"postinstall_scripts": True,
"min_release_age": 0,
},
).get_provider_with_overrides(
overrides={
"ublock": {
"install_args": [UBLOCK_WEBSTORE_ID, "--name=ublock"],
},
},
)
installed = provider.install("ublock")
assert_extension_binary_loaded(installed)
assert installed is not None
assert bin_dir is not None
assert provider.install_root == install_root
assert provider.bin_dir == bin_dir
assert installed.loaded_abspath is not None
assert installed.loaded_abspath.is_relative_to(bin_dir)
def test_provider_direct_methods_exercise_real_lifecycle(self, test_machine):
test_machine.require_tool("node")
assert PACKAGED_CHROME_UTILS_PATH.exists(), PACKAGED_CHROME_UTILS_PATH
with tempfile.TemporaryDirectory() as temp_dir:
provider = ChromeWebstoreProvider(
install_root=Path(temp_dir) / "chromewebstore-root",
bin_dir=Path(temp_dir) / "chromewebstore-root/extensions",
postinstall_scripts=True,
min_release_age=0,
).get_provider_with_overrides(
overrides={
"ublock": {
"install_args": [UBLOCK_WEBSTORE_ID, "--name=ublock"],
},
},
)
provider.setup(
postinstall_scripts=True,
min_release_age=0,
min_version=None,
)
assert provider.load("ublock", quiet=True, no_cache=True) is None
installed = provider.install("ublock", no_cache=True)
assert_extension_binary_loaded(installed)
loaded = provider.load("ublock", no_cache=True)
assert_extension_binary_loaded(loaded)
loaded_or_installed = provider.install("ublock", no_cache=True)
assert_extension_binary_loaded(loaded_or_installed)
updated = provider.update("ublock", no_cache=True)
assert_extension_binary_loaded(updated)
assert provider.uninstall("ublock", no_cache=True) is True
assert provider.load("ublock", quiet=True, no_cache=True) is None
def test_binary_direct_methods_exercise_real_lifecycle(self, test_machine):
test_machine.require_tool("node")
assert PACKAGED_CHROME_UTILS_PATH.exists(), PACKAGED_CHROME_UTILS_PATH
with tempfile.TemporaryDirectory() as temp_dir:
binary = Binary(
name="ublock",
binproviders=[
ChromeWebstoreProvider(
install_root=Path(temp_dir) / "chromewebstore-root",
bin_dir=Path(temp_dir) / "chromewebstore-root/extensions",
postinstall_scripts=True,
min_release_age=0,
),
],
overrides={
"chromewebstore": {
"install_args": [UBLOCK_WEBSTORE_ID, "--name=ublock"],
},
},
postinstall_scripts=True,
min_release_age=0,
)
fresh = test_machine.unloaded_binary(binary)
test_machine.assert_binary_missing(fresh)
installed = fresh.install()
assert_extension_binary_loaded(installed)
loaded = test_machine.unloaded_binary(binary).load(no_cache=True)
assert_extension_binary_loaded(loaded)
loaded_or_installed = test_machine.unloaded_binary(binary).install(
no_cache=True,
)
assert_extension_binary_loaded(loaded_or_installed)
updated = installed.update()
assert_extension_binary_loaded(updated)
removed = updated.uninstall()
assert not removed.is_valid
assert removed.loaded_abspath is None
assert removed.loaded_version is None
assert removed.loaded_sha256 is None
test_machine.assert_binary_missing(binary)