Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | import os |
michael@0 | 6 | import unittest |
michael@0 | 7 | import zipfile |
michael@0 | 8 | import pprint |
michael@0 | 9 | import shutil |
michael@0 | 10 | |
michael@0 | 11 | import simplejson as json |
michael@0 | 12 | from cuddlefish import xpi, packaging, manifest, buildJID |
michael@0 | 13 | from cuddlefish.tests import test_packaging |
michael@0 | 14 | from test_linker import up |
michael@0 | 15 | |
michael@0 | 16 | import xml.etree.ElementTree as ElementTree |
michael@0 | 17 | |
michael@0 | 18 | xpi_template_path = os.path.join(test_packaging.static_files_path, |
michael@0 | 19 | 'xpi-template') |
michael@0 | 20 | |
michael@0 | 21 | fake_manifest = '<RDF><!-- Extension metadata is here. --></RDF>' |
michael@0 | 22 | |
michael@0 | 23 | class PrefsTests(unittest.TestCase): |
michael@0 | 24 | def makexpi(self, pkg_name): |
michael@0 | 25 | self.xpiname = "%s.xpi" % pkg_name |
michael@0 | 26 | create_xpi(self.xpiname, pkg_name, 'preferences-files') |
michael@0 | 27 | self.xpi = zipfile.ZipFile(self.xpiname, 'r') |
michael@0 | 28 | options = self.xpi.read('harness-options.json') |
michael@0 | 29 | self.xpi_harness_options = json.loads(options) |
michael@0 | 30 | |
michael@0 | 31 | def setUp(self): |
michael@0 | 32 | self.xpiname = None |
michael@0 | 33 | self.xpi = None |
michael@0 | 34 | |
michael@0 | 35 | def tearDown(self): |
michael@0 | 36 | if self.xpi: |
michael@0 | 37 | self.xpi.close() |
michael@0 | 38 | if self.xpiname and os.path.exists(self.xpiname): |
michael@0 | 39 | os.remove(self.xpiname) |
michael@0 | 40 | |
michael@0 | 41 | def testPackageWithSimplePrefs(self): |
michael@0 | 42 | self.makexpi('simple-prefs') |
michael@0 | 43 | packageName = 'jid1-fZHqN9JfrDBa8A@jetpack' |
michael@0 | 44 | self.failUnless('options.xul' in self.xpi.namelist()) |
michael@0 | 45 | optsxul = self.xpi.read('options.xul').decode("utf-8") |
michael@0 | 46 | self.failUnlessEqual(self.xpi_harness_options["jetpackID"], packageName) |
michael@0 | 47 | self.failUnlessEqual(self.xpi_harness_options["preferencesBranch"], packageName) |
michael@0 | 48 | |
michael@0 | 49 | root = ElementTree.XML(optsxul.encode('utf-8')) |
michael@0 | 50 | |
michael@0 | 51 | xulNamespacePrefix = \ |
michael@0 | 52 | "{http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul}" |
michael@0 | 53 | |
michael@0 | 54 | settings = root.findall(xulNamespacePrefix + 'setting') |
michael@0 | 55 | |
michael@0 | 56 | def assertPref(setting, name, prefType, title): |
michael@0 | 57 | self.failUnlessEqual(setting.get('data-jetpack-id'), packageName) |
michael@0 | 58 | self.failUnlessEqual(setting.get('pref'), |
michael@0 | 59 | 'extensions.' + packageName + '.' + name) |
michael@0 | 60 | self.failUnlessEqual(setting.get('pref-name'), name) |
michael@0 | 61 | self.failUnlessEqual(setting.get('type'), prefType) |
michael@0 | 62 | self.failUnlessEqual(setting.get('title'), title) |
michael@0 | 63 | |
michael@0 | 64 | assertPref(settings[0], 'test', 'bool', u't\u00EBst') |
michael@0 | 65 | assertPref(settings[1], 'test2', 'string', u't\u00EBst') |
michael@0 | 66 | assertPref(settings[2], 'test3', 'menulist', '"><test') |
michael@0 | 67 | assertPref(settings[3], 'test4', 'radio', u't\u00EBst') |
michael@0 | 68 | |
michael@0 | 69 | menuItems = settings[2].findall( |
michael@0 | 70 | '%(0)smenulist/%(0)smenupopup/%(0)smenuitem' % { "0": xulNamespacePrefix }) |
michael@0 | 71 | radios = settings[3].findall( |
michael@0 | 72 | '%(0)sradiogroup/%(0)sradio' % { "0": xulNamespacePrefix }) |
michael@0 | 73 | |
michael@0 | 74 | def assertOption(option, value, label): |
michael@0 | 75 | self.failUnlessEqual(option.get('value'), value) |
michael@0 | 76 | self.failUnlessEqual(option.get('label'), label) |
michael@0 | 77 | |
michael@0 | 78 | assertOption(menuItems[0], "0", "label1") |
michael@0 | 79 | assertOption(menuItems[1], "1", "label2") |
michael@0 | 80 | assertOption(radios[0], "red", "rouge") |
michael@0 | 81 | assertOption(radios[1], "blue", "bleu") |
michael@0 | 82 | |
michael@0 | 83 | prefsjs = self.xpi.read('defaults/preferences/prefs.js').decode("utf-8") |
michael@0 | 84 | exp = [u'pref("extensions.jid1-fZHqN9JfrDBa8A@jetpack.test", false);', |
michael@0 | 85 | u'pref("extensions.jid1-fZHqN9JfrDBa8A@jetpack.test2", "\u00FCnic\u00F8d\u00E9");', |
michael@0 | 86 | u'pref("extensions.jid1-fZHqN9JfrDBa8A@jetpack.test3", "1");', |
michael@0 | 87 | u'pref("extensions.jid1-fZHqN9JfrDBa8A@jetpack.test4", "red");', |
michael@0 | 88 | ] |
michael@0 | 89 | self.failUnlessEqual(prefsjs, "\n".join(exp)+"\n") |
michael@0 | 90 | |
michael@0 | 91 | def testPackageWithPreferencesBranch(self): |
michael@0 | 92 | self.makexpi('preferences-branch') |
michael@0 | 93 | self.failUnless('options.xul' in self.xpi.namelist()) |
michael@0 | 94 | optsxul = self.xpi.read('options.xul').decode("utf-8") |
michael@0 | 95 | self.failUnlessEqual(self.xpi_harness_options["preferencesBranch"], |
michael@0 | 96 | "human-readable") |
michael@0 | 97 | |
michael@0 | 98 | root = ElementTree.XML(optsxul.encode('utf-8')) |
michael@0 | 99 | xulNamespacePrefix = \ |
michael@0 | 100 | "{http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul}" |
michael@0 | 101 | |
michael@0 | 102 | setting = root.find(xulNamespacePrefix + 'setting') |
michael@0 | 103 | self.failUnlessEqual(setting.get('pref'), |
michael@0 | 104 | 'extensions.human-readable.test42') |
michael@0 | 105 | |
michael@0 | 106 | prefsjs = self.xpi.read('defaults/preferences/prefs.js').decode("utf-8") |
michael@0 | 107 | self.failUnlessEqual(prefsjs, |
michael@0 | 108 | 'pref("extensions.human-readable.test42", true);\n') |
michael@0 | 109 | |
michael@0 | 110 | def testPackageWithNoPrefs(self): |
michael@0 | 111 | self.makexpi('no-prefs') |
michael@0 | 112 | self.failIf('options.xul' in self.xpi.namelist()) |
michael@0 | 113 | self.failUnlessEqual(self.xpi_harness_options["jetpackID"], |
michael@0 | 114 | "jid1-fZHqN9JfrDBa8A@jetpack") |
michael@0 | 115 | prefsjs = self.xpi.read('defaults/preferences/prefs.js').decode("utf-8") |
michael@0 | 116 | self.failUnlessEqual(prefsjs, "") |
michael@0 | 117 | |
michael@0 | 118 | def testPackageWithInvalidPreferencesBranch(self): |
michael@0 | 119 | self.makexpi('curly-id') |
michael@0 | 120 | self.failIfEqual(self.xpi_harness_options["preferencesBranch"], |
michael@0 | 121 | "invalid^branch*name") |
michael@0 | 122 | self.failUnlessEqual(self.xpi_harness_options["preferencesBranch"], |
michael@0 | 123 | "{34a1eae1-c20a-464f-9b0e-000000000000}") |
michael@0 | 124 | |
michael@0 | 125 | def testPackageWithCurlyID(self): |
michael@0 | 126 | self.makexpi('curly-id') |
michael@0 | 127 | self.failUnlessEqual(self.xpi_harness_options["jetpackID"], |
michael@0 | 128 | "{34a1eae1-c20a-464f-9b0e-000000000000}") |
michael@0 | 129 | |
michael@0 | 130 | self.failUnless('options.xul' in self.xpi.namelist()) |
michael@0 | 131 | optsxul = self.xpi.read('options.xul').decode("utf-8") |
michael@0 | 132 | |
michael@0 | 133 | root = ElementTree.XML(optsxul.encode('utf-8')) |
michael@0 | 134 | xulNamespacePrefix = \ |
michael@0 | 135 | "{http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul}" |
michael@0 | 136 | |
michael@0 | 137 | setting = root.find(xulNamespacePrefix + 'setting') |
michael@0 | 138 | self.failUnlessEqual(setting.get('pref'), |
michael@0 | 139 | 'extensions.{34a1eae1-c20a-464f-9b0e-000000000000}.test13') |
michael@0 | 140 | |
michael@0 | 141 | prefsjs = self.xpi.read('defaults/preferences/prefs.js').decode("utf-8") |
michael@0 | 142 | self.failUnlessEqual(prefsjs, |
michael@0 | 143 | 'pref("extensions.{34a1eae1-c20a-464f-9b0e-000000000000}.test13", 26);\n') |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | class Bug588119Tests(unittest.TestCase): |
michael@0 | 147 | def makexpi(self, pkg_name): |
michael@0 | 148 | self.xpiname = "%s.xpi" % pkg_name |
michael@0 | 149 | create_xpi(self.xpiname, pkg_name, 'bug-588119-files') |
michael@0 | 150 | self.xpi = zipfile.ZipFile(self.xpiname, 'r') |
michael@0 | 151 | options = self.xpi.read('harness-options.json') |
michael@0 | 152 | self.xpi_harness_options = json.loads(options) |
michael@0 | 153 | |
michael@0 | 154 | def setUp(self): |
michael@0 | 155 | self.xpiname = None |
michael@0 | 156 | self.xpi = None |
michael@0 | 157 | |
michael@0 | 158 | def tearDown(self): |
michael@0 | 159 | if self.xpi: |
michael@0 | 160 | self.xpi.close() |
michael@0 | 161 | if self.xpiname and os.path.exists(self.xpiname): |
michael@0 | 162 | os.remove(self.xpiname) |
michael@0 | 163 | |
michael@0 | 164 | def testPackageWithImplicitIcon(self): |
michael@0 | 165 | self.makexpi('implicit-icon') |
michael@0 | 166 | assert 'icon.png' in self.xpi.namelist() |
michael@0 | 167 | |
michael@0 | 168 | def testPackageWithImplicitIcon64(self): |
michael@0 | 169 | self.makexpi('implicit-icon') |
michael@0 | 170 | assert 'icon64.png' in self.xpi.namelist() |
michael@0 | 171 | |
michael@0 | 172 | def testPackageWithExplicitIcon(self): |
michael@0 | 173 | self.makexpi('explicit-icon') |
michael@0 | 174 | assert 'icon.png' in self.xpi.namelist() |
michael@0 | 175 | |
michael@0 | 176 | def testPackageWithExplicitIcon64(self): |
michael@0 | 177 | self.makexpi('explicit-icon') |
michael@0 | 178 | assert 'icon64.png' in self.xpi.namelist() |
michael@0 | 179 | |
michael@0 | 180 | def testPackageWithNoIcon(self): |
michael@0 | 181 | self.makexpi('no-icon') |
michael@0 | 182 | assert 'icon.png' not in self.xpi.namelist() |
michael@0 | 183 | |
michael@0 | 184 | def testIconPathNotInHarnessOptions(self): |
michael@0 | 185 | self.makexpi('implicit-icon') |
michael@0 | 186 | assert 'icon' not in self.xpi_harness_options |
michael@0 | 187 | |
michael@0 | 188 | def testIcon64PathNotInHarnessOptions(self): |
michael@0 | 189 | self.makexpi('implicit-icon') |
michael@0 | 190 | assert 'icon64' not in self.xpi_harness_options |
michael@0 | 191 | |
michael@0 | 192 | class ExtraHarnessOptions(unittest.TestCase): |
michael@0 | 193 | def setUp(self): |
michael@0 | 194 | self.xpiname = None |
michael@0 | 195 | self.xpi = None |
michael@0 | 196 | |
michael@0 | 197 | def tearDown(self): |
michael@0 | 198 | if self.xpi: |
michael@0 | 199 | self.xpi.close() |
michael@0 | 200 | if self.xpiname and os.path.exists(self.xpiname): |
michael@0 | 201 | os.remove(self.xpiname) |
michael@0 | 202 | |
michael@0 | 203 | def testOptions(self): |
michael@0 | 204 | pkg_name = "extra-options" |
michael@0 | 205 | self.xpiname = "%s.xpi" % pkg_name |
michael@0 | 206 | create_xpi(self.xpiname, pkg_name, "bug-669274-files", |
michael@0 | 207 | extra_harness_options={"builderVersion": "futuristic"}) |
michael@0 | 208 | self.xpi = zipfile.ZipFile(self.xpiname, 'r') |
michael@0 | 209 | options = self.xpi.read('harness-options.json') |
michael@0 | 210 | hopts = json.loads(options) |
michael@0 | 211 | self.failUnless("builderVersion" in hopts) |
michael@0 | 212 | self.failUnlessEqual(hopts["builderVersion"], "futuristic") |
michael@0 | 213 | |
michael@0 | 214 | def testBadOptionName(self): |
michael@0 | 215 | pkg_name = "extra-options" |
michael@0 | 216 | self.xpiname = "%s.xpi" % pkg_name |
michael@0 | 217 | self.failUnlessRaises(xpi.HarnessOptionAlreadyDefinedError, |
michael@0 | 218 | create_xpi, |
michael@0 | 219 | self.xpiname, pkg_name, "bug-669274-files", |
michael@0 | 220 | extra_harness_options={"main": "already in use"}) |
michael@0 | 221 | |
michael@0 | 222 | class SmallXPI(unittest.TestCase): |
michael@0 | 223 | def setUp(self): |
michael@0 | 224 | self.root = up(os.path.abspath(__file__), 4) |
michael@0 | 225 | def get_linker_files_dir(self, name): |
michael@0 | 226 | return os.path.join(up(os.path.abspath(__file__)), "linker-files", name) |
michael@0 | 227 | def get_pkg(self, name): |
michael@0 | 228 | d = self.get_linker_files_dir(name) |
michael@0 | 229 | return packaging.get_config_in_dir(d) |
michael@0 | 230 | |
michael@0 | 231 | def get_basedir(self): |
michael@0 | 232 | return os.path.join(".test_tmp", self.id()) |
michael@0 | 233 | def make_basedir(self): |
michael@0 | 234 | basedir = self.get_basedir() |
michael@0 | 235 | if os.path.isdir(basedir): |
michael@0 | 236 | here = os.path.abspath(os.getcwd()) |
michael@0 | 237 | assert os.path.abspath(basedir).startswith(here) # safety |
michael@0 | 238 | shutil.rmtree(basedir) |
michael@0 | 239 | os.makedirs(basedir) |
michael@0 | 240 | return basedir |
michael@0 | 241 | |
michael@0 | 242 | def test_contents(self): |
michael@0 | 243 | target_cfg = self.get_pkg("three") |
michael@0 | 244 | package_path = [self.get_linker_files_dir("three-deps")] |
michael@0 | 245 | pkg_cfg = packaging.build_config(self.root, target_cfg, |
michael@0 | 246 | packagepath=package_path) |
michael@0 | 247 | deps = packaging.get_deps_for_targets(pkg_cfg, |
michael@0 | 248 | [target_cfg.name, "addon-sdk"]) |
michael@0 | 249 | addon_sdk_dir = pkg_cfg.packages["addon-sdk"].lib[0] |
michael@0 | 250 | m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=False) |
michael@0 | 251 | used_files = list(m.get_used_files(True)) |
michael@0 | 252 | here = up(os.path.abspath(__file__)) |
michael@0 | 253 | def absify(*parts): |
michael@0 | 254 | fn = os.path.join(here, "linker-files", *parts) |
michael@0 | 255 | return os.path.abspath(fn) |
michael@0 | 256 | expected = [absify(*parts) for parts in |
michael@0 | 257 | [("three", "lib", "main.js"), |
michael@0 | 258 | ("three-deps", "three-a", "lib", "main.js"), |
michael@0 | 259 | ("three-deps", "three-a", "lib", "subdir", "subfile.js"), |
michael@0 | 260 | ("three", "data", "msg.txt"), |
michael@0 | 261 | ("three", "data", "subdir", "submsg.txt"), |
michael@0 | 262 | ("three-deps", "three-b", "lib", "main.js"), |
michael@0 | 263 | ("three-deps", "three-c", "lib", "main.js"), |
michael@0 | 264 | ("three-deps", "three-c", "lib", "sub", "foo.js") |
michael@0 | 265 | ]] |
michael@0 | 266 | |
michael@0 | 267 | add_addon_sdk= lambda path: os.path.join(addon_sdk_dir, path) |
michael@0 | 268 | expected.extend([add_addon_sdk(module) for module in [ |
michael@0 | 269 | os.path.join("sdk", "self.js"), |
michael@0 | 270 | os.path.join("sdk", "core", "promise.js"), |
michael@0 | 271 | os.path.join("sdk", "net", "url.js"), |
michael@0 | 272 | os.path.join("sdk", "util", "object.js"), |
michael@0 | 273 | os.path.join("sdk", "util", "array.js") |
michael@0 | 274 | ]]) |
michael@0 | 275 | |
michael@0 | 276 | missing = set(expected) - set(used_files) |
michael@0 | 277 | extra = set(used_files) - set(expected) |
michael@0 | 278 | |
michael@0 | 279 | self.failUnlessEqual(list(missing), []) |
michael@0 | 280 | self.failUnlessEqual(list(extra), []) |
michael@0 | 281 | used_deps = m.get_used_packages() |
michael@0 | 282 | |
michael@0 | 283 | build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name, |
michael@0 | 284 | used_deps, |
michael@0 | 285 | include_tests=False) |
michael@0 | 286 | options = {'main': target_cfg.main} |
michael@0 | 287 | options.update(build) |
michael@0 | 288 | basedir = self.make_basedir() |
michael@0 | 289 | xpi_name = os.path.join(basedir, "contents.xpi") |
michael@0 | 290 | xpi.build_xpi(template_root_dir=xpi_template_path, |
michael@0 | 291 | manifest=fake_manifest, |
michael@0 | 292 | xpi_path=xpi_name, |
michael@0 | 293 | harness_options=options, |
michael@0 | 294 | limit_to=used_files) |
michael@0 | 295 | x = zipfile.ZipFile(xpi_name, "r") |
michael@0 | 296 | names = x.namelist() |
michael@0 | 297 | expected = ["components/", |
michael@0 | 298 | "components/harness.js", |
michael@0 | 299 | # the real template also has 'bootstrap.js', but the fake |
michael@0 | 300 | # one in tests/static-files/xpi-template doesn't |
michael@0 | 301 | "harness-options.json", |
michael@0 | 302 | "install.rdf", |
michael@0 | 303 | "defaults/preferences/prefs.js", |
michael@0 | 304 | "resources/", |
michael@0 | 305 | "resources/addon-sdk/", |
michael@0 | 306 | "resources/addon-sdk/lib/", |
michael@0 | 307 | "resources/addon-sdk/lib/sdk/", |
michael@0 | 308 | "resources/addon-sdk/lib/sdk/self.js", |
michael@0 | 309 | "resources/addon-sdk/lib/sdk/core/", |
michael@0 | 310 | "resources/addon-sdk/lib/sdk/util/", |
michael@0 | 311 | "resources/addon-sdk/lib/sdk/net/", |
michael@0 | 312 | "resources/addon-sdk/lib/sdk/core/promise.js", |
michael@0 | 313 | "resources/addon-sdk/lib/sdk/util/object.js", |
michael@0 | 314 | "resources/addon-sdk/lib/sdk/util/array.js", |
michael@0 | 315 | "resources/addon-sdk/lib/sdk/net/url.js", |
michael@0 | 316 | "resources/three/", |
michael@0 | 317 | "resources/three/lib/", |
michael@0 | 318 | "resources/three/lib/main.js", |
michael@0 | 319 | "resources/three/data/", |
michael@0 | 320 | "resources/three/data/msg.txt", |
michael@0 | 321 | "resources/three/data/subdir/", |
michael@0 | 322 | "resources/three/data/subdir/submsg.txt", |
michael@0 | 323 | "resources/three-a/", |
michael@0 | 324 | "resources/three-a/lib/", |
michael@0 | 325 | "resources/three-a/lib/main.js", |
michael@0 | 326 | "resources/three-a/lib/subdir/", |
michael@0 | 327 | "resources/three-a/lib/subdir/subfile.js", |
michael@0 | 328 | "resources/three-b/", |
michael@0 | 329 | "resources/three-b/lib/", |
michael@0 | 330 | "resources/three-b/lib/main.js", |
michael@0 | 331 | "resources/three-c/", |
michael@0 | 332 | "resources/three-c/lib/", |
michael@0 | 333 | "resources/three-c/lib/main.js", |
michael@0 | 334 | "resources/three-c/lib/sub/", |
michael@0 | 335 | "resources/three-c/lib/sub/foo.js", |
michael@0 | 336 | # notably absent: three-a/lib/unused.js |
michael@0 | 337 | "locale/", |
michael@0 | 338 | "locale/fr-FR.json", |
michael@0 | 339 | "locales.json", |
michael@0 | 340 | ] |
michael@0 | 341 | # showing deltas makes failures easier to investigate |
michael@0 | 342 | missing = set(expected) - set(names) |
michael@0 | 343 | extra = set(names) - set(expected) |
michael@0 | 344 | self.failUnlessEqual((list(missing), list(extra)), ([], [])) |
michael@0 | 345 | self.failUnlessEqual(sorted(names), sorted(expected)) |
michael@0 | 346 | |
michael@0 | 347 | # check locale files |
michael@0 | 348 | localedata = json.loads(x.read("locales.json")) |
michael@0 | 349 | self.failUnlessEqual(sorted(localedata["locales"]), sorted(["fr-FR"])) |
michael@0 | 350 | content = x.read("locale/fr-FR.json") |
michael@0 | 351 | locales = json.loads(content) |
michael@0 | 352 | # Locale files are merged into one. |
michael@0 | 353 | # Conflicts are silently resolved by taking last package translation, |
michael@0 | 354 | # so that we get "No" translation from three-c instead of three-b one. |
michael@0 | 355 | self.failUnlessEqual(locales, json.loads(u''' |
michael@0 | 356 | { |
michael@0 | 357 | "No": "Nein", |
michael@0 | 358 | "one": "un", |
michael@0 | 359 | "What?": "Quoi?", |
michael@0 | 360 | "Yes": "Oui", |
michael@0 | 361 | "plural": { |
michael@0 | 362 | "other": "other", |
michael@0 | 363 | "one": "one" |
michael@0 | 364 | }, |
michael@0 | 365 | "uft8_value": "\u00e9" |
michael@0 | 366 | }''')) |
michael@0 | 367 | |
michael@0 | 368 | def test_scantests(self): |
michael@0 | 369 | target_cfg = self.get_pkg("three") |
michael@0 | 370 | package_path = [self.get_linker_files_dir("three-deps")] |
michael@0 | 371 | pkg_cfg = packaging.build_config(self.root, target_cfg, |
michael@0 | 372 | packagepath=package_path) |
michael@0 | 373 | |
michael@0 | 374 | deps = packaging.get_deps_for_targets(pkg_cfg, |
michael@0 | 375 | [target_cfg.name, "addon-sdk"]) |
michael@0 | 376 | m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=True) |
michael@0 | 377 | self.failUnlessEqual(sorted(m.get_all_test_modules()), |
michael@0 | 378 | sorted(["three/tests/test-one", "three/tests/test-two"])) |
michael@0 | 379 | # the current __init__.py code omits limit_to=used_files for 'cfx |
michael@0 | 380 | # test', so all test files are included in the XPI. But the test |
michael@0 | 381 | # runner will only execute the tests that m.get_all_test_modules() |
michael@0 | 382 | # tells us about (which are put into the .allTestModules property of |
michael@0 | 383 | # harness-options.json). |
michael@0 | 384 | used_deps = m.get_used_packages() |
michael@0 | 385 | |
michael@0 | 386 | build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name, |
michael@0 | 387 | used_deps, |
michael@0 | 388 | include_tests=True) |
michael@0 | 389 | options = {'main': target_cfg.main} |
michael@0 | 390 | options.update(build) |
michael@0 | 391 | basedir = self.make_basedir() |
michael@0 | 392 | xpi_name = os.path.join(basedir, "contents.xpi") |
michael@0 | 393 | xpi.build_xpi(template_root_dir=xpi_template_path, |
michael@0 | 394 | manifest=fake_manifest, |
michael@0 | 395 | xpi_path=xpi_name, |
michael@0 | 396 | harness_options=options, |
michael@0 | 397 | limit_to=None) |
michael@0 | 398 | x = zipfile.ZipFile(xpi_name, "r") |
michael@0 | 399 | names = x.namelist() |
michael@0 | 400 | self.failUnless("resources/addon-sdk/lib/sdk/deprecated/unit-test.js" in names, names) |
michael@0 | 401 | self.failUnless("resources/addon-sdk/lib/sdk/deprecated/unit-test-finder.js" in names, names) |
michael@0 | 402 | self.failUnless("resources/addon-sdk/lib/sdk/test/harness.js" in names, names) |
michael@0 | 403 | self.failUnless("resources/addon-sdk/lib/sdk/test/runner.js" in names, names) |
michael@0 | 404 | # all files are copied into the XPI, even the things that don't look |
michael@0 | 405 | # like tests. |
michael@0 | 406 | self.failUnless("resources/three/tests/test-one.js" in names, names) |
michael@0 | 407 | self.failUnless("resources/three/tests/test-two.js" in names, names) |
michael@0 | 408 | self.failUnless("resources/three/tests/nontest.js" in names, names) |
michael@0 | 409 | |
michael@0 | 410 | def test_scantests_filter(self): |
michael@0 | 411 | target_cfg = self.get_pkg("three") |
michael@0 | 412 | package_path = [self.get_linker_files_dir("three-deps")] |
michael@0 | 413 | pkg_cfg = packaging.build_config(self.root, target_cfg, |
michael@0 | 414 | packagepath=package_path) |
michael@0 | 415 | deps = packaging.get_deps_for_targets(pkg_cfg, |
michael@0 | 416 | [target_cfg.name, "addon-sdk"]) |
michael@0 | 417 | FILTER = ".*one.*" |
michael@0 | 418 | m = manifest.build_manifest(target_cfg, pkg_cfg, deps, scan_tests=True, |
michael@0 | 419 | test_filter_re=FILTER) |
michael@0 | 420 | self.failUnlessEqual(sorted(m.get_all_test_modules()), |
michael@0 | 421 | sorted(["three/tests/test-one"])) |
michael@0 | 422 | # the current __init__.py code omits limit_to=used_files for 'cfx |
michael@0 | 423 | # test', so all test files are included in the XPI. But the test |
michael@0 | 424 | # runner will only execute the tests that m.get_all_test_modules() |
michael@0 | 425 | # tells us about (which are put into the .allTestModules property of |
michael@0 | 426 | # harness-options.json). |
michael@0 | 427 | used_deps = m.get_used_packages() |
michael@0 | 428 | |
michael@0 | 429 | build = packaging.generate_build_for_target(pkg_cfg, target_cfg.name, |
michael@0 | 430 | used_deps, |
michael@0 | 431 | include_tests=True) |
michael@0 | 432 | options = {'main': target_cfg.main} |
michael@0 | 433 | options.update(build) |
michael@0 | 434 | basedir = self.make_basedir() |
michael@0 | 435 | xpi_name = os.path.join(basedir, "contents.xpi") |
michael@0 | 436 | xpi.build_xpi(template_root_dir=xpi_template_path, |
michael@0 | 437 | manifest=fake_manifest, |
michael@0 | 438 | xpi_path=xpi_name, |
michael@0 | 439 | harness_options=options, |
michael@0 | 440 | limit_to=None) |
michael@0 | 441 | x = zipfile.ZipFile(xpi_name, "r") |
michael@0 | 442 | names = x.namelist() |
michael@0 | 443 | self.failUnless("resources/addon-sdk/lib/sdk/deprecated/unit-test.js" in names, names) |
michael@0 | 444 | self.failUnless("resources/addon-sdk/lib/sdk/deprecated/unit-test-finder.js" in names, names) |
michael@0 | 445 | self.failUnless("resources/addon-sdk/lib/sdk/test/harness.js" in names, names) |
michael@0 | 446 | self.failUnless("resources/addon-sdk/lib/sdk/test/runner.js" in names, names) |
michael@0 | 447 | # get_all_test_modules() respects the filter. But all files are still |
michael@0 | 448 | # copied into the XPI. |
michael@0 | 449 | self.failUnless("resources/three/tests/test-one.js" in names, names) |
michael@0 | 450 | self.failUnless("resources/three/tests/test-two.js" in names, names) |
michael@0 | 451 | self.failUnless("resources/three/tests/nontest.js" in names, names) |
michael@0 | 452 | |
michael@0 | 453 | |
michael@0 | 454 | def document_dir(name): |
michael@0 | 455 | if name in ['packages', 'xpi-template']: |
michael@0 | 456 | dirname = os.path.join(test_packaging.static_files_path, name) |
michael@0 | 457 | document_dir_files(dirname) |
michael@0 | 458 | elif name == 'xpi-output': |
michael@0 | 459 | create_xpi('test-xpi.xpi') |
michael@0 | 460 | document_zip_file('test-xpi.xpi') |
michael@0 | 461 | os.remove('test-xpi.xpi') |
michael@0 | 462 | else: |
michael@0 | 463 | raise Exception('unknown dir: %s' % name) |
michael@0 | 464 | |
michael@0 | 465 | def normpath(path): |
michael@0 | 466 | """ |
michael@0 | 467 | Make a platform-specific relative path use '/' as a separator. |
michael@0 | 468 | """ |
michael@0 | 469 | |
michael@0 | 470 | return path.replace(os.path.sep, '/') |
michael@0 | 471 | |
michael@0 | 472 | def document_zip_file(path): |
michael@0 | 473 | zip = zipfile.ZipFile(path, 'r') |
michael@0 | 474 | for name in sorted(zip.namelist()): |
michael@0 | 475 | contents = zip.read(name) |
michael@0 | 476 | lines = contents.splitlines() |
michael@0 | 477 | if len(lines) == 1 and name.endswith('.json') and len(lines[0]) > 75: |
michael@0 | 478 | # Ideally we would json-decode this, but it results |
michael@0 | 479 | # in an annoying 'u' before every string literal, |
michael@0 | 480 | # since json decoding makes all strings unicode. |
michael@0 | 481 | contents = eval(contents) |
michael@0 | 482 | contents = pprint.pformat(contents) |
michael@0 | 483 | lines = contents.splitlines() |
michael@0 | 484 | contents = "\n ".join(lines) |
michael@0 | 485 | print "%s:\n %s" % (normpath(name), contents) |
michael@0 | 486 | zip.close() |
michael@0 | 487 | |
michael@0 | 488 | def document_dir_files(path): |
michael@0 | 489 | filename_contents_tuples = [] |
michael@0 | 490 | for dirpath, dirnames, filenames in os.walk(path): |
michael@0 | 491 | relpath = dirpath[len(path)+1:] |
michael@0 | 492 | for filename in filenames: |
michael@0 | 493 | abspath = os.path.join(dirpath, filename) |
michael@0 | 494 | contents = open(abspath, 'r').read() |
michael@0 | 495 | contents = "\n ".join(contents.splitlines()) |
michael@0 | 496 | relfilename = os.path.join(relpath, filename) |
michael@0 | 497 | filename_contents_tuples.append((normpath(relfilename), contents)) |
michael@0 | 498 | filename_contents_tuples.sort() |
michael@0 | 499 | for filename, contents in filename_contents_tuples: |
michael@0 | 500 | print "%s:" % filename |
michael@0 | 501 | print " %s" % contents |
michael@0 | 502 | |
michael@0 | 503 | def create_xpi(xpiname, pkg_name='aardvark', dirname='static-files', |
michael@0 | 504 | extra_harness_options={}): |
michael@0 | 505 | configs = test_packaging.get_configs(pkg_name, dirname) |
michael@0 | 506 | options = {'main': configs.target_cfg.main, |
michael@0 | 507 | 'jetpackID': buildJID(configs.target_cfg), } |
michael@0 | 508 | options.update(configs.build) |
michael@0 | 509 | xpi.build_xpi(template_root_dir=xpi_template_path, |
michael@0 | 510 | manifest=fake_manifest, |
michael@0 | 511 | xpi_path=xpiname, |
michael@0 | 512 | harness_options=options, |
michael@0 | 513 | extra_harness_options=extra_harness_options) |
michael@0 | 514 | |
michael@0 | 515 | if __name__ == '__main__': |
michael@0 | 516 | unittest.main() |