# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os import unittest
import mozunit from buildconfig import topobjdir from mozunit import MockedOpen
import mozpack.path as mozpath from mozbuild.preprocessor import Preprocessor from mozpack.chrome.manifest import (
ManifestBinaryComponent,
ManifestContent,
ManifestResource,
) from mozpack.errors import ErrorMessage, errors from mozpack.files import GeneratedFile from mozpack.packager import (
CallDeque,
Component,
SimpleManifestSink,
SimplePackager,
preprocess_manifest,
)
we_manifest = GeneratedFile(
b'{"manifest_version": 2, "name": "Test WebExtension", "version": "1.0"}'
) # hybrid and hybrid2 are both bootstrapped extensions with # embedded webextensions, they differ in the order in which # the manifests are added to the packager. with errors.context("manifest", 20):
packager.add("hybrid/install.rdf", install_rdf)
with errors.context("manifest", 21):
packager.add("hybrid/webextension/manifest.json", we_manifest)
with errors.context("manifest", 22):
packager.add("hybrid2/webextension/manifest.json", we_manifest)
with errors.context("manifest", 23):
packager.add("hybrid2/install.rdf", install_rdf)
with errors.context("manifest", 24):
packager.add("webextension/manifest.json", we_manifest)
non_we_manifest = GeneratedFile(b'{"not a webextension": true}') with errors.context("manifest", 25):
packager.add("nonwebextension/manifest.json", non_we_manifest)
def test_simple_packager_manifest_consistency(self):
formatter = MockFormatter() # bar/ is detected as an addon because of install.rdf, but top-level # includes a manifest inside bar/.
packager = SimplePackager(formatter)
packager.add( "base.manifest",
GeneratedFile(
b"manifest foo/bar.manifest\n" b"manifest bar/baz.manifest\n"
),
)
packager.add("foo/bar.manifest", GeneratedFile(b"resource bar bar"))
packager.add("bar/baz.manifest", GeneratedFile(b"resource baz baz"))
packager.add("bar/install.rdf", GeneratedFile(b""))
with self.assertRaises(ErrorMessage) as e:
packager.close()
self.assertEqual(
str(e.exception), 'error: "bar/baz.manifest" is included from "base.manifest", ' 'which is outside "bar"',
)
# bar/ is detected as a separate base because of chrome.manifest that # is included nowhere, but top-level includes another manifest inside # bar/.
packager = SimplePackager(formatter)
packager.add( "base.manifest",
GeneratedFile(
b"manifest foo/bar.manifest\n" b"manifest bar/baz.manifest\n"
),
)
packager.add("foo/bar.manifest", GeneratedFile(b"resource bar bar"))
packager.add("bar/baz.manifest", GeneratedFile(b"resource baz baz"))
packager.add("bar/chrome.manifest", GeneratedFile(b"resource baz baz"))
with self.assertRaises(ErrorMessage) as e:
packager.close()
self.assertEqual(
str(e.exception), 'error: "bar/baz.manifest" is included from "base.manifest", ' 'which is outside "bar"',
)
# bar/ is detected as a separate base because of chrome.manifest that # is included nowhere, but chrome.manifest includes baz.manifest from # the same directory. This shouldn't error out.
packager = SimplePackager(formatter)
packager.add("base.manifest", GeneratedFile(b"manifest foo/bar.manifest\n"))
packager.add("foo/bar.manifest", GeneratedFile(b"resource bar bar"))
packager.add("bar/baz.manifest", GeneratedFile(b"resource baz baz"))
packager.add("bar/chrome.manifest", GeneratedFile(b"manifest baz.manifest"))
packager.close()
class TestComponent(unittest.TestCase): def do_split(self, string, name, options):
n, o = Component._split_component_and_options(string)
self.assertEqual(name, n)
self.assertEqual(options, o)
def test_component_split_component_and_options(self):
self.do_split("component", "component", {})
self.do_split("trailingspace ", "trailingspace", {})
self.do_split(" leadingspace", "leadingspace", {})
self.do_split(" trim ", "trim", {})
self.do_split(' trim key="value"', "trim", {"key": "value"})
self.do_split(' trim empty=""', "trim", {"empty": ""})
self.do_split(' trim space=" "', "trim", {"space": " "})
self.do_split( 'component key="value" key2="second" ', "component",
{"key": "value", "key2": "second"},
)
self.do_split( 'trim key=" value with spaces " key2="spaces again"', "trim",
{"key": " value with spaces ", "key2": "spaces again"},
)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.