| 1 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
import unittest |
| 6 |
from itertools import chain |
| 7 |
|
| 8 |
import mozunit |
| 9 |
|
| 10 |
import mozpack.path as mozpath |
| 11 |
from mozpack.chrome.manifest import ( |
| 12 |
ManifestBinaryComponent, |
| 13 |
ManifestComponent, |
| 14 |
ManifestContent, |
| 15 |
ManifestLocale, |
| 16 |
ManifestResource, |
| 17 |
ManifestSkin, |
| 18 |
) |
| 19 |
from mozpack.copier import FileRegistry |
| 20 |
from mozpack.errors import ErrorMessage |
| 21 |
from mozpack.files import GeneratedFile, ManifestFile |
| 22 |
from mozpack.packager.formats import FlatFormatter, JarFormatter, OmniJarFormatter |
| 23 |
from mozpack.test.test_files import bar_xpt, foo2_xpt, foo_xpt |
| 24 |
from test_errors import TestErrors |
| 25 |
|
| 26 |
CONTENTS = { |
| 27 |
"bases": { |
| 28 |
# base_path: is_addon? |
| 29 |
"": False, |
| 30 |
"app": False, |
| 31 |
"addon0": "unpacked", |
| 32 |
"addon1": True, |
| 33 |
"app/chrome/addons/addon2": True, |
| 34 |
}, |
| 35 |
"manifests": [ |
| 36 |
ManifestContent("chrome/f", "oo", "oo/"), |
| 37 |
ManifestContent("chrome/f", "bar", "oo/bar/"), |
| 38 |
ManifestResource("chrome/f", "foo", "resource://bar/"), |
| 39 |
ManifestBinaryComponent("components", "foo.so"), |
| 40 |
ManifestContent("app/chrome", "content", "foo/"), |
| 41 |
ManifestComponent("app/components", "{foo-id}", "foo.js"), |
| 42 |
ManifestContent("addon0/chrome", "addon0", "foo/bar/"), |
| 43 |
ManifestContent("addon1/chrome", "addon1", "foo/bar/"), |
| 44 |
ManifestContent("app/chrome/addons/addon2/chrome", "addon2", "foo/bar/"), |
| 45 |
], |
| 46 |
"files": { |
| 47 |
"chrome/f/oo/bar/baz": GeneratedFile(b"foobarbaz"), |
| 48 |
"chrome/f/oo/baz": GeneratedFile(b"foobaz"), |
| 49 |
"chrome/f/oo/qux": GeneratedFile(b"fooqux"), |
| 50 |
"components/foo.so": GeneratedFile(b"foo.so"), |
| 51 |
"components/foo.xpt": foo_xpt, |
| 52 |
"components/bar.xpt": bar_xpt, |
| 53 |
"foo": GeneratedFile(b"foo"), |
| 54 |
"app/chrome/foo/foo": GeneratedFile(b"appfoo"), |
| 55 |
"app/components/foo.js": GeneratedFile(b"foo.js"), |
| 56 |
"addon0/chrome/foo/bar/baz": GeneratedFile(b"foobarbaz"), |
| 57 |
"addon0/components/foo.xpt": foo2_xpt, |
| 58 |
"addon0/components/bar.xpt": bar_xpt, |
| 59 |
"addon1/chrome/foo/bar/baz": GeneratedFile(b"foobarbaz"), |
| 60 |
"addon1/components/foo.xpt": foo2_xpt, |
| 61 |
"addon1/components/bar.xpt": bar_xpt, |
| 62 |
"app/chrome/addons/addon2/chrome/foo/bar/baz": GeneratedFile(b"foobarbaz"), |
| 63 |
"app/chrome/addons/addon2/components/foo.xpt": foo2_xpt, |
| 64 |
"app/chrome/addons/addon2/components/bar.xpt": bar_xpt, |
| 65 |
}, |
| 66 |
} |
| 67 |
|
| 68 |
FILES = CONTENTS["files"] |
| 69 |
|
| 70 |
RESULT_FLAT = { |
| 71 |
"chrome.manifest": [ |
| 72 |
"manifest chrome/chrome.manifest", |
| 73 |
"manifest components/components.manifest", |
| 74 |
], |
| 75 |
"chrome/chrome.manifest": [ |
| 76 |
"manifest f/f.manifest", |
| 77 |
], |
| 78 |
"chrome/f/f.manifest": [ |
| 79 |
"content oo oo/", |
| 80 |
"content bar oo/bar/", |
| 81 |
"resource foo resource://bar/", |
| 82 |
], |
| 83 |
"chrome/f/oo/bar/baz": FILES["chrome/f/oo/bar/baz"], |
| 84 |
"chrome/f/oo/baz": FILES["chrome/f/oo/baz"], |
| 85 |
"chrome/f/oo/qux": FILES["chrome/f/oo/qux"], |
| 86 |
"components/components.manifest": [ |
| 87 |
"binary-component foo.so", |
| 88 |
"interfaces bar.xpt", |
| 89 |
"interfaces foo.xpt", |
| 90 |
], |
| 91 |
"components/foo.so": FILES["components/foo.so"], |
| 92 |
"components/foo.xpt": foo_xpt, |
| 93 |
"components/bar.xpt": bar_xpt, |
| 94 |
"foo": FILES["foo"], |
| 95 |
"app/chrome.manifest": [ |
| 96 |
"manifest chrome/chrome.manifest", |
| 97 |
"manifest components/components.manifest", |
| 98 |
], |
| 99 |
"app/chrome/chrome.manifest": [ |
| 100 |
"content content foo/", |
| 101 |
], |
| 102 |
"app/chrome/foo/foo": FILES["app/chrome/foo/foo"], |
| 103 |
"app/components/components.manifest": [ |
| 104 |
"component {foo-id} foo.js", |
| 105 |
], |
| 106 |
"app/components/foo.js": FILES["app/components/foo.js"], |
| 107 |
} |
| 108 |
|
| 109 |
for addon in ("addon0", "addon1", "app/chrome/addons/addon2"): |
| 110 |
RESULT_FLAT.update( |
| 111 |
{ |
| 112 |
mozpath.join(addon, p): f |
| 113 |
for p, f in { |
| 114 |
"chrome.manifest": [ |
| 115 |
"manifest chrome/chrome.manifest", |
| 116 |
"manifest components/components.manifest", |
| 117 |
], |
| 118 |
"chrome/chrome.manifest": [ |
| 119 |
"content %s foo/bar/" % mozpath.basename(addon) |
| 120 |
], |
| 121 |
"chrome/foo/bar/baz": FILES[mozpath.join(addon, "chrome/foo/bar/baz")], |
| 122 |
"components/components.manifest": [ |
| 123 |
"interfaces bar.xpt", |
| 124 |
"interfaces foo.xpt", |
| 125 |
], |
| 126 |
"components/bar.xpt": bar_xpt, |
| 127 |
"components/foo.xpt": foo2_xpt, |
| 128 |
}.items() |
| 129 |
} |
| 130 |
) |
| 131 |
|
| 132 |
RESULT_JAR = { |
| 133 |
p: RESULT_FLAT[p] |
| 134 |
for p in ( |
| 135 |
"chrome.manifest", |
| 136 |
"chrome/chrome.manifest", |
| 137 |
"components/components.manifest", |
| 138 |
"components/foo.so", |
| 139 |
"components/foo.xpt", |
| 140 |
"components/bar.xpt", |
| 141 |
"foo", |
| 142 |
"app/chrome.manifest", |
| 143 |
"app/components/components.manifest", |
| 144 |
"app/components/foo.js", |
| 145 |
"addon0/chrome.manifest", |
| 146 |
"addon0/components/components.manifest", |
| 147 |
"addon0/components/foo.xpt", |
| 148 |
"addon0/components/bar.xpt", |
| 149 |
) |
| 150 |
} |
| 151 |
|
| 152 |
RESULT_JAR.update( |
| 153 |
{ |
| 154 |
"chrome/f/f.manifest": [ |
| 155 |
"content oo jar:oo.jar!/", |
| 156 |
"content bar jar:oo.jar!/bar/", |
| 157 |
"resource foo resource://bar/", |
| 158 |
], |
| 159 |
"chrome/f/oo.jar": { |
| 160 |
"bar/baz": FILES["chrome/f/oo/bar/baz"], |
| 161 |
"baz": FILES["chrome/f/oo/baz"], |
| 162 |
"qux": FILES["chrome/f/oo/qux"], |
| 163 |
}, |
| 164 |
"app/chrome/chrome.manifest": [ |
| 165 |
"content content jar:foo.jar!/", |
| 166 |
], |
| 167 |
"app/chrome/foo.jar": { |
| 168 |
"foo": FILES["app/chrome/foo/foo"], |
| 169 |
}, |
| 170 |
"addon0/chrome/chrome.manifest": [ |
| 171 |
"content addon0 jar:foo.jar!/bar/", |
| 172 |
], |
| 173 |
"addon0/chrome/foo.jar": { |
| 174 |
"bar/baz": FILES["addon0/chrome/foo/bar/baz"], |
| 175 |
}, |
| 176 |
"addon1.xpi": { |
| 177 |
mozpath.relpath(p, "addon1"): f |
| 178 |
for p, f in RESULT_FLAT.items() |
| 179 |
if p.startswith("addon1/") |
| 180 |
}, |
| 181 |
"app/chrome/addons/addon2.xpi": { |
| 182 |
mozpath.relpath(p, "app/chrome/addons/addon2"): f |
| 183 |
for p, f in RESULT_FLAT.items() |
| 184 |
if p.startswith("app/chrome/addons/addon2/") |
| 185 |
}, |
| 186 |
} |
| 187 |
) |
| 188 |
|
| 189 |
RESULT_OMNIJAR = { |
| 190 |
p: RESULT_FLAT[p] |
| 191 |
for p in ( |
| 192 |
"components/foo.so", |
| 193 |
"foo", |
| 194 |
) |
| 195 |
} |
| 196 |
|
| 197 |
RESULT_OMNIJAR.update({p: RESULT_JAR[p] for p in RESULT_JAR if p.startswith("addon")}) |
| 198 |
|
| 199 |
RESULT_OMNIJAR.update( |
| 200 |
{ |
| 201 |
"omni.foo": { |
| 202 |
"components/components.manifest": [ |
| 203 |
"interfaces bar.xpt", |
| 204 |
"interfaces foo.xpt", |
| 205 |
], |
| 206 |
}, |
| 207 |
"chrome.manifest": [ |
| 208 |
"manifest components/components.manifest", |
| 209 |
], |
| 210 |
"components/components.manifest": [ |
| 211 |
"binary-component foo.so", |
| 212 |
], |
| 213 |
"app/omni.foo": { |
| 214 |
p: RESULT_FLAT["app/" + p] |
| 215 |
for p in chain( |
| 216 |
( |
| 217 |
"chrome.manifest", |
| 218 |
"chrome/chrome.manifest", |
| 219 |
"chrome/foo/foo", |
| 220 |
"components/components.manifest", |
| 221 |
"components/foo.js", |
| 222 |
), |
| 223 |
( |
| 224 |
mozpath.relpath(p, "app") |
| 225 |
for p in RESULT_FLAT.keys() |
| 226 |
if p.startswith("app/chrome/addons/addon2/") |
| 227 |
), |
| 228 |
) |
| 229 |
}, |
| 230 |
} |
| 231 |
) |
| 232 |
|
| 233 |
RESULT_OMNIJAR["omni.foo"].update( |
| 234 |
{ |
| 235 |
p: RESULT_FLAT[p] |
| 236 |
for p in ( |
| 237 |
"chrome.manifest", |
| 238 |
"chrome/chrome.manifest", |
| 239 |
"chrome/f/f.manifest", |
| 240 |
"chrome/f/oo/bar/baz", |
| 241 |
"chrome/f/oo/baz", |
| 242 |
"chrome/f/oo/qux", |
| 243 |
"components/foo.xpt", |
| 244 |
"components/bar.xpt", |
| 245 |
) |
| 246 |
} |
| 247 |
) |
| 248 |
|
| 249 |
RESULT_OMNIJAR_WITH_SUBPATH = { |
| 250 |
k.replace("omni.foo", "bar/omni.foo"): v for k, v in RESULT_OMNIJAR.items() |
| 251 |
} |
| 252 |
|
| 253 |
CONTENTS_WITH_BASE = { |
| 254 |
"bases": { |
| 255 |
mozpath.join("base/root", b) if b else "base/root": a |
| 256 |
for b, a in CONTENTS["bases"].items() |
| 257 |
}, |
| 258 |
"manifests": [ |
| 259 |
m.move(mozpath.join("base/root", m.base)) for m in CONTENTS["manifests"] |
| 260 |
], |
| 261 |
"files": {mozpath.join("base/root", p): f for p, f in CONTENTS["files"].items()}, |
| 262 |
} |
| 263 |
|
| 264 |
EXTRA_CONTENTS = { |
| 265 |
"extra/file": GeneratedFile(b"extra file"), |
| 266 |
} |
| 267 |
|
| 268 |
CONTENTS_WITH_BASE["files"].update(EXTRA_CONTENTS) |
| 269 |
|
| 270 |
|
| 271 |
def result_with_base(results): |
| 272 |
result = {mozpath.join("base/root", p): v for p, v in results.items()} |
| 273 |
result.update(EXTRA_CONTENTS) |
| 274 |
return result |
| 275 |
|
| 276 |
|
| 277 |
RESULT_FLAT_WITH_BASE = result_with_base(RESULT_FLAT) |
| 278 |
RESULT_JAR_WITH_BASE = result_with_base(RESULT_JAR) |
| 279 |
RESULT_OMNIJAR_WITH_BASE = result_with_base(RESULT_OMNIJAR) |
| 280 |
|
| 281 |
|
| 282 |
def fill_formatter(formatter, contents): |
| 283 |
for base, is_addon in sorted(contents["bases"].items()): |
| 284 |
formatter.add_base(base, is_addon) |
| 285 |
|
| 286 |
for manifest in contents["manifests"]: |
| 287 |
formatter.add_manifest(manifest) |
| 288 |
|
| 289 |
for k, v in sorted(contents["files"].items()): |
| 290 |
if k.endswith(".xpt"): |
| 291 |
formatter.add_interfaces(k, v) |
| 292 |
else: |
| 293 |
formatter.add(k, v) |
| 294 |
|
| 295 |
|
| 296 |
def get_contents(registry, read_all=False, mode="rt"): |
| 297 |
result = {} |
| 298 |
for k, v in registry: |
| 299 |
if isinstance(v, FileRegistry): |
| 300 |
result[k] = get_contents(v) |
| 301 |
elif isinstance(v, ManifestFile) or read_all: |
| 302 |
if "b" in mode: |
| 303 |
result[k] = v.open().read() |
| 304 |
else: |
| 305 |
result[k] = v.open().read().decode().splitlines() |
| 306 |
else: |
| 307 |
result[k] = v |
| 308 |
return result |
| 309 |
|
| 310 |
|
| 311 |
class TestFormatters(TestErrors, unittest.TestCase): |
| 312 |
maxDiff = None |
| 313 |
|
| 314 |
def test_bases(self): |
| 315 |
formatter = FlatFormatter(FileRegistry()) |
| 316 |
formatter.add_base("") |
| 317 |
formatter.add_base("addon0", addon=True) |
| 318 |
formatter.add_base("browser") |
| 319 |
self.assertEqual(formatter._get_base("platform.ini"), ("", "platform.ini")) |
| 320 |
self.assertEqual( |
| 321 |
formatter._get_base("browser/application.ini"), |
| 322 |
("browser", "application.ini"), |
| 323 |
) |
| 324 |
self.assertEqual( |
| 325 |
formatter._get_base("addon0/install.rdf"), ("addon0", "install.rdf") |
| 326 |
) |
| 327 |
|
| 328 |
def do_test_contents(self, formatter, contents): |
| 329 |
for f in contents["files"]: |
| 330 |
# .xpt files are merged, so skip them. |
| 331 |
if not f.endswith(".xpt"): |
| 332 |
self.assertTrue(formatter.contains(f)) |
| 333 |
|
| 334 |
def test_flat_formatter(self): |
| 335 |
registry = FileRegistry() |
| 336 |
formatter = FlatFormatter(registry) |
| 337 |
|
| 338 |
fill_formatter(formatter, CONTENTS) |
| 339 |
self.assertEqual(get_contents(registry), RESULT_FLAT) |
| 340 |
self.do_test_contents(formatter, CONTENTS) |
| 341 |
|
| 342 |
def test_jar_formatter(self): |
| 343 |
registry = FileRegistry() |
| 344 |
formatter = JarFormatter(registry) |
| 345 |
|
| 346 |
fill_formatter(formatter, CONTENTS) |
| 347 |
self.assertEqual(get_contents(registry), RESULT_JAR) |
| 348 |
self.do_test_contents(formatter, CONTENTS) |
| 349 |
|
| 350 |
def test_omnijar_formatter(self): |
| 351 |
registry = FileRegistry() |
| 352 |
formatter = OmniJarFormatter(registry, "omni.foo") |
| 353 |
|
| 354 |
fill_formatter(formatter, CONTENTS) |
| 355 |
self.assertEqual(get_contents(registry), RESULT_OMNIJAR) |
| 356 |
self.do_test_contents(formatter, CONTENTS) |
| 357 |
|
| 358 |
def test_flat_formatter_with_base(self): |
| 359 |
registry = FileRegistry() |
| 360 |
formatter = FlatFormatter(registry) |
| 361 |
|
| 362 |
fill_formatter(formatter, CONTENTS_WITH_BASE) |
| 363 |
self.assertEqual(get_contents(registry), RESULT_FLAT_WITH_BASE) |
| 364 |
self.do_test_contents(formatter, CONTENTS_WITH_BASE) |
| 365 |
|
| 366 |
def test_jar_formatter_with_base(self): |
| 367 |
registry = FileRegistry() |
| 368 |
formatter = JarFormatter(registry) |
| 369 |
|
| 370 |
fill_formatter(formatter, CONTENTS_WITH_BASE) |
| 371 |
self.assertEqual(get_contents(registry), RESULT_JAR_WITH_BASE) |
| 372 |
self.do_test_contents(formatter, CONTENTS_WITH_BASE) |
| 373 |
|
| 374 |
def test_omnijar_formatter_with_base(self): |
| 375 |
registry = FileRegistry() |
| 376 |
formatter = OmniJarFormatter(registry, "omni.foo") |
| 377 |
|
| 378 |
fill_formatter(formatter, CONTENTS_WITH_BASE) |
| 379 |
self.assertEqual(get_contents(registry), RESULT_OMNIJAR_WITH_BASE) |
| 380 |
self.do_test_contents(formatter, CONTENTS_WITH_BASE) |
| 381 |
|
| 382 |
def test_omnijar_formatter_with_subpath(self): |
| 383 |
registry = FileRegistry() |
| 384 |
formatter = OmniJarFormatter(registry, "bar/omni.foo") |
| 385 |
|
| 386 |
fill_formatter(formatter, CONTENTS) |
| 387 |
self.assertEqual(get_contents(registry), RESULT_OMNIJAR_WITH_SUBPATH) |
| 388 |
self.do_test_contents(formatter, CONTENTS) |
| 389 |
|
| 390 |
def test_omnijar_is_resource(self): |
| 391 |
def is_resource(base, path): |
| 392 |
registry = FileRegistry() |
| 393 |
f = OmniJarFormatter( |
| 394 |
registry, |
| 395 |
"omni.foo", |
| 396 |
non_resources=[ |
| 397 |
"defaults/messenger/mailViews.dat", |
| 398 |
"defaults/foo/*", |
| 399 |
"*/dummy", |
| 400 |
], |
| 401 |
) |
| 402 |
f.add_base("") |
| 403 |
f.add_base("app") |
| 404 |
f.add(mozpath.join(base, path), GeneratedFile(b"")) |
| 405 |
if f.copier.contains(mozpath.join(base, path)): |
| 406 |
return False |
| 407 |
self.assertTrue(f.copier.contains(mozpath.join(base, "omni.foo"))) |
| 408 |
self.assertTrue(f.copier[mozpath.join(base, "omni.foo")].contains(path)) |
| 409 |
return True |
| 410 |
|
| 411 |
for base in ["", "app/"]: |
| 412 |
self.assertTrue(is_resource(base, "chrome")) |
| 413 |
self.assertTrue(is_resource(base, "chrome/foo/bar/baz.properties")) |
| 414 |
self.assertFalse(is_resource(base, "chrome/icons/foo.png")) |
| 415 |
self.assertTrue(is_resource(base, "components/foo.js")) |
| 416 |
self.assertFalse(is_resource(base, "components/foo.so")) |
| 417 |
self.assertTrue(is_resource(base, "res/foo.css")) |
| 418 |
self.assertFalse(is_resource(base, "res/cursors/foo.png")) |
| 419 |
self.assertFalse(is_resource(base, "res/MainMenu.nib/foo")) |
| 420 |
self.assertTrue(is_resource(base, "defaults/pref/foo.js")) |
| 421 |
self.assertFalse(is_resource(base, "defaults/pref/channel-prefs.js")) |
| 422 |
self.assertTrue(is_resource(base, "defaults/preferences/foo.js")) |
| 423 |
self.assertFalse(is_resource(base, "defaults/preferences/channel-prefs.js")) |
| 424 |
self.assertTrue(is_resource(base, "modules/foo.jsm")) |
| 425 |
self.assertTrue(is_resource(base, "greprefs.js")) |
| 426 |
self.assertTrue(is_resource(base, "hyphenation/foo")) |
| 427 |
self.assertTrue(is_resource(base, "default.locale")) |
| 428 |
self.assertFalse(is_resource(base, "foo")) |
| 429 |
self.assertFalse(is_resource(base, "foo/bar/greprefs.js")) |
| 430 |
self.assertTrue(is_resource(base, "defaults/messenger/foo.dat")) |
| 431 |
self.assertFalse(is_resource(base, "defaults/messenger/mailViews.dat")) |
| 432 |
self.assertTrue(is_resource(base, "defaults/pref/foo.js")) |
| 433 |
self.assertFalse(is_resource(base, "defaults/foo/bar.dat")) |
| 434 |
self.assertFalse(is_resource(base, "defaults/foo/bar/baz.dat")) |
| 435 |
self.assertTrue(is_resource(base, "chrome/foo/bar/baz/dummy_")) |
| 436 |
self.assertFalse(is_resource(base, "chrome/foo/bar/baz/dummy")) |
| 437 |
self.assertTrue(is_resource(base, "chrome/foo/bar/dummy_")) |
| 438 |
self.assertFalse(is_resource(base, "chrome/foo/bar/dummy")) |
| 439 |
|
| 440 |
def test_chrome_override(self): |
| 441 |
registry = FileRegistry() |
| 442 |
f = FlatFormatter(registry) |
| 443 |
f.add_base("") |
| 444 |
f.add_manifest(ManifestContent("chrome", "foo", "foo/unix")) |
| 445 |
# A more specific entry for a given chrome name can override a more |
| 446 |
# generic one. |
| 447 |
f.add_manifest(ManifestContent("chrome", "foo", "foo/win", "os=WINNT")) |
| 448 |
f.add_manifest(ManifestContent("chrome", "foo", "foo/osx", "os=Darwin")) |
| 449 |
|
| 450 |
# Chrome with the same name overrides the previous registration. |
| 451 |
with self.assertRaises(ErrorMessage) as e: |
| 452 |
f.add_manifest(ManifestContent("chrome", "foo", "foo/")) |
| 453 |
|
| 454 |
self.assertEqual( |
| 455 |
str(e.exception), |
| 456 |
'error: "content foo foo/" overrides ' '"content foo foo/unix"', |
| 457 |
) |
| 458 |
|
| 459 |
# Chrome with the same name and same flags overrides the previous |
| 460 |
# registration. |
| 461 |
with self.assertRaises(ErrorMessage) as e: |
| 462 |
f.add_manifest(ManifestContent("chrome", "foo", "foo/", "os=WINNT")) |
| 463 |
|
| 464 |
self.assertEqual( |
| 465 |
str(e.exception), |
| 466 |
'error: "content foo foo/ os=WINNT" overrides ' |
| 467 |
'"content foo foo/win os=WINNT"', |
| 468 |
) |
| 469 |
|
| 470 |
# We may start with the more specific entry first |
| 471 |
f.add_manifest(ManifestContent("chrome", "bar", "bar/win", "os=WINNT")) |
| 472 |
# Then adding a more generic one overrides it. |
| 473 |
with self.assertRaises(ErrorMessage) as e: |
| 474 |
f.add_manifest(ManifestContent("chrome", "bar", "bar/unix")) |
| 475 |
|
| 476 |
self.assertEqual( |
| 477 |
str(e.exception), |
| 478 |
'error: "content bar bar/unix" overrides ' '"content bar bar/win os=WINNT"', |
| 479 |
) |
| 480 |
|
| 481 |
# Adding something more specific still works. |
| 482 |
f.add_manifest( |
| 483 |
ManifestContent("chrome", "bar", "bar/win", "os=WINNT osversion>=7.0") |
| 484 |
) |
| 485 |
|
| 486 |
# Variations of skin/locales are allowed. |
| 487 |
f.add_manifest( |
| 488 |
ManifestSkin("chrome", "foo", "classic/1.0", "foo/skin/classic/") |
| 489 |
) |
| 490 |
f.add_manifest(ManifestSkin("chrome", "foo", "modern/1.0", "foo/skin/modern/")) |
| 491 |
|
| 492 |
f.add_manifest(ManifestLocale("chrome", "foo", "en-US", "foo/locale/en-US/")) |
| 493 |
f.add_manifest(ManifestLocale("chrome", "foo", "ja-JP", "foo/locale/ja-JP/")) |
| 494 |
|
| 495 |
# But same-skin/locale still error out. |
| 496 |
with self.assertRaises(ErrorMessage) as e: |
| 497 |
f.add_manifest( |
| 498 |
ManifestSkin("chrome", "foo", "classic/1.0", "foo/skin/classic/foo") |
| 499 |
) |
| 500 |
|
| 501 |
self.assertEqual( |
| 502 |
str(e.exception), |
| 503 |
'error: "skin foo classic/1.0 foo/skin/classic/foo" overrides ' |
| 504 |
'"skin foo classic/1.0 foo/skin/classic/"', |
| 505 |
) |
| 506 |
|
| 507 |
with self.assertRaises(ErrorMessage) as e: |
| 508 |
f.add_manifest( |
| 509 |
ManifestLocale("chrome", "foo", "en-US", "foo/locale/en-US/foo") |
| 510 |
) |
| 511 |
|
| 512 |
self.assertEqual( |
| 513 |
str(e.exception), |
| 514 |
'error: "locale foo en-US foo/locale/en-US/foo" overrides ' |
| 515 |
'"locale foo en-US foo/locale/en-US/"', |
| 516 |
) |
| 517 |
|
| 518 |
# Duplicating existing manifest entries is not an error. |
| 519 |
f.add_manifest(ManifestContent("chrome", "foo", "foo/unix")) |
| 520 |
|
| 521 |
self.assertEqual( |
| 522 |
self.get_output(), |
| 523 |
[ |
| 524 |
'warning: "content foo foo/unix" is duplicated. Skipping.', |
| 525 |
], |
| 526 |
) |
| 527 |
|
| 528 |
|
| 529 |
if __name__ == "__main__": |
| 530 |
mozunit.main() |