Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 723012: fix jetpackID which accidentally changed in 1.4 . r=mhammond

This removes the code in packaging.py which accidentally override the code in
__init__.py which converts package.json:id into
harness-options.json:jetpackID . The consequence of that override was that a
"@jetpack" suffix was not appended when necessary, which caused "jetpackID"
to be wrong in 1.4, which caused simple-storage to look in the wrong place
for its saved data.

This also changes the build_xpi() convenience method (used by a couple tests)
to include the id-to-jetpackID conversion step. The lack of that conversion
step is what prompted the addition to packaging.py, as it was the quickest
way to get the tests to pass at the time.

The simple-prefs tests have been enhanced, and new tests were added to assert
that the id-to-jetpackID conversion happens properly for both "jid" and
"jid@jetpack" (i.e. with and without suffix-adding).

Cherry-picked from master: 582a8ea and b1dbb63
  • Loading branch information...
commit 34d7cf81c6487c75b646d87fb727134325c8f118 1 parent 4bc2bdb
KWierso authored February 03, 2012
17  python-lib/cuddlefish/__init__.py
@@ -472,6 +472,15 @@ def get_unique_prefix(jid):
472 472
 
473 473
     return unique_prefix
474 474
 
  475
+def buildJID(target_cfg, harness_guid):
  476
+    if "id" in target_cfg:
  477
+        jid = target_cfg["id"]
  478
+    else:
  479
+        jid = harness_guid
  480
+    if not ("@" in jid or jid.startswith("{")):
  481
+        jid = jid + "@jetpack"
  482
+    return jid
  483
+
475 484
 def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
476 485
         defaults=None, env_root=os.environ.get('CUDDLEFISH_ROOT'),
477 486
         stdout=sys.stdout):
@@ -612,13 +621,7 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
612 621
     else:
613 622
         assert command == "test"
614 623
 
615  
-    if "id" in target_cfg:
616  
-        jid = target_cfg["id"]
617  
-    else:
618  
-        jid = harness_guid
619  
-    if not ("@" in jid or jid.startswith("{")):
620  
-        jid = jid + "@jetpack"
621  
-
  624
+    jid = buildJID(target_cfg, harness_guid)
622 625
 
623 626
     targets = [target]
624 627
     if command == "test":
3  python-lib/cuddlefish/packaging.py
@@ -333,9 +333,6 @@ def add_dep_to_build(dep):
333 333
     if ('preferences' in target_cfg):
334 334
         build['preferences'] = target_cfg.preferences
335 335
 
336  
-    if ('id' in target_cfg):
337  
-        build['jetpackID'] = target_cfg.id
338  
-
339 336
     return build
340 337
 
341 338
 def _get_files_in_dir(path):
1  python-lib/cuddlefish/tests/linker-files/one/package.json
... ...
@@ -1,3 +1,4 @@
1 1
 { "name": "one",
  2
+  "id": "jid1@jetpack",
2 3
   "main": "main"
3 4
 }
2  python-lib/cuddlefish/tests/linker-files/seven/package.json
... ...
@@ -1,4 +1,4 @@
1 1
 {
2 2
     "name": "seven", 
3  
-    "id": "jid1"
  3
+    "id": "jid7"
4 4
 }
5  python-lib/cuddlefish/tests/preferences-files/packages/no-prefs/package.json
... ...
@@ -1,3 +1,6 @@
1 1
 {
2  
-  "loader": "lib/main.js"
  2
+    "id": "jid1-fZHqN9JfrDBa8A",
  3
+    "fullName": "No Prefs Test",
  4
+    "author": "Erik Vold",
  5
+    "loader": "lib/main.js"
3 6
 }
37  python-lib/cuddlefish/tests/test_linker.py
@@ -2,6 +2,7 @@
2 2
 import shutil
3 3
 import zipfile
4 4
 from StringIO import StringIO
  5
+import simplejson as json
5 6
 import unittest
6 7
 import cuddlefish
7 8
 from cuddlefish import packaging, manifest
@@ -131,6 +132,42 @@ def run_in_subdir(self, dirname, f, *args, **kwargs):
131 132
     def assertIn(self, what, inside_what):
132 133
         self.failUnless(what in inside_what, inside_what)
133 134
 
  135
+    def test_jetpackID(self):
  136
+        # this uses "id": "jid7", to which a @jetpack should be appended
  137
+        seven = get_linker_files_dir("seven")
  138
+        def _test(basedir):
  139
+            stdout = StringIO()
  140
+            shutil.copytree(seven, "seven")
  141
+            os.chdir("seven")
  142
+            try:
  143
+                # regrettably, run() always finishes with sys.exit()
  144
+                cuddlefish.run(["xpi", "--no-strip-xpi"],
  145
+                               stdout=stdout)
  146
+            except SystemExit, e:
  147
+                self.failUnlessEqual(e.args[0], 0)
  148
+            zf = zipfile.ZipFile("seven.xpi", "r")
  149
+            hopts = json.loads(zf.read("harness-options.json"))
  150
+            self.failUnlessEqual(hopts["jetpackID"], "jid7@jetpack")
  151
+        self.run_in_subdir("x", _test)
  152
+
  153
+    def test_jetpackID_suffix(self):
  154
+        # this uses "id": "jid1@jetpack", so no suffix should be appended
  155
+        one = get_linker_files_dir("one")
  156
+        def _test(basedir):
  157
+            stdout = StringIO()
  158
+            shutil.copytree(one, "one")
  159
+            os.chdir("one")
  160
+            try:
  161
+                # regrettably, run() always finishes with sys.exit()
  162
+                cuddlefish.run(["xpi", "--no-strip-xpi"],
  163
+                               stdout=stdout)
  164
+            except SystemExit, e:
  165
+                self.failUnlessEqual(e.args[0], 0)
  166
+            zf = zipfile.ZipFile("one.xpi", "r")
  167
+            hopts = json.loads(zf.read("harness-options.json"))
  168
+            self.failUnlessEqual(hopts["jetpackID"], "jid1@jetpack")
  169
+        self.run_in_subdir("x", _test)
  170
+
134 171
     def test_strip_default(self):
135 172
         seven = get_linker_files_dir("seven")
136 173
         # now run 'cfx xpi' in that directory, except put the generated .xpi
19  python-lib/cuddlefish/tests/test_xpi.py
@@ -3,9 +3,10 @@
3 3
 import zipfile
4 4
 import pprint
5 5
 import shutil
  6
+import uuid
6 7
 
7 8
 import simplejson as json
8  
-from cuddlefish import xpi, packaging, manifest
  9
+from cuddlefish import xpi, packaging, manifest, buildJID
9 10
 from cuddlefish.tests import test_packaging
10 11
 from test_linker import up
11 12
 
@@ -34,11 +35,20 @@ def tearDown(self):
34 35
 
35 36
     def testPackageWithSimplePrefs(self):
36 37
         self.makexpi('simple-prefs')
37  
-        assert 'options.xul' in self.xpi.namelist()
  38
+        self.failUnless('options.xul' in self.xpi.namelist())
  39
+        prefs = self.xpi.read('options.xul')
  40
+        self.failUnless('pref="extensions.jid1-fZHqN9JfrDBa8A@jetpack.test"'
  41
+                        in prefs, prefs)
  42
+        self.failUnless('type="bool"' in prefs, prefs)
  43
+        self.failUnless('title="test"' in prefs, prefs)
  44
+        self.failUnlessEqual(self.xpi_harness_options["jetpackID"],
  45
+                             "jid1-fZHqN9JfrDBa8A@jetpack")
38 46
 
39 47
     def testPackageWithNoPrefs(self):
40 48
         self.makexpi('no-prefs')
41  
-        assert 'options.xul' not in self.xpi.namelist()
  49
+        self.failIf('options.xul' in self.xpi.namelist())
  50
+        self.failUnlessEqual(self.xpi_harness_options["jetpackID"],
  51
+                             "jid1-fZHqN9JfrDBa8A@jetpack")
42 52
 
43 53
 
44 54
 class Bug588119Tests(unittest.TestCase):
@@ -272,7 +282,8 @@ def document_dir_files(path):
272 282
 def create_xpi(xpiname, pkg_name='aardvark', dirname='static-files',
273 283
                extra_harness_options={}):
274 284
     configs = test_packaging.get_configs(pkg_name, dirname)
275  
-    options = {'main': configs.target_cfg.main}
  285
+    options = {'main': configs.target_cfg.main,
  286
+               'jetpackID': buildJID(configs.target_cfg, str(uuid.uuid4())), }
276 287
     options.update(configs.build)
277 288
     xpi.build_xpi(template_root_dir=xpi_template_path,
278 289
                   manifest=fake_manifest,

0 notes on commit 34d7cf8

Please sign in to comment.
Something went wrong with that request. Please try again.