testing/mozbase/mozprofile/tests/addonid.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 import os
michael@0 4 import tempfile
michael@0 5 import unittest
michael@0 6 import shutil
michael@0 7 from mozprofile import addons
michael@0 8
michael@0 9
michael@0 10 here = os.path.dirname(os.path.abspath(__file__))
michael@0 11
michael@0 12
michael@0 13 class AddonIDTest(unittest.TestCase):
michael@0 14 """ Test finding the addon id in a variety of install.rdf styles """
michael@0 15
michael@0 16 def make_install_rdf(self, filecontents):
michael@0 17 path = tempfile.mkdtemp()
michael@0 18 f = open(os.path.join(path, "install.rdf"), "w")
michael@0 19 f.write(filecontents)
michael@0 20 f.close()
michael@0 21 return path
michael@0 22
michael@0 23 def test_addonID(self):
michael@0 24 testlist = self.get_test_list()
michael@0 25 for t in testlist:
michael@0 26 try:
michael@0 27 p = self.make_install_rdf(t)
michael@0 28 a = addons.AddonManager(os.path.join(p, "profile"))
michael@0 29 addon_id = a.addon_details(p)['id']
michael@0 30 self.assertEqual(addon_id, "winning", "We got the addon id")
michael@0 31 finally:
michael@0 32 shutil.rmtree(p)
michael@0 33
michael@0 34 def test_addonID_xpi(self):
michael@0 35 a = addons.AddonManager("profile")
michael@0 36 addon = a.addon_details(os.path.join(here, "addons", "empty.xpi"))
michael@0 37 self.assertEqual(addon['id'], "test-empty@quality.mozilla.org", "We got the addon id")
michael@0 38
michael@0 39 def get_test_list(self):
michael@0 40 """ This just returns a hardcoded list of install.rdf snippets for testing.
michael@0 41 When adding snippets for testing, remember that the id we're looking for
michael@0 42 is "winning" (no quotes). So, make sure you have that id in your snippet
michael@0 43 if you want it to pass.
michael@0 44 """
michael@0 45 tests = [
michael@0 46 """<?xml version="1.0"?>
michael@0 47 <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
michael@0 48 xmlns:em="http://www.mozilla.org/2004/em-rdf#">
michael@0 49 <Description about="urn:mozilla:install-manifest">
michael@0 50 <em:id>winning</em:id>
michael@0 51 <em:name>MozMill</em:name>
michael@0 52 <em:version>2.0a</em:version>
michael@0 53 <em:creator>Adam Christian</em:creator>
michael@0 54 <em:description>A testing extension based on the Windmill Testing Framework client source</em:description>
michael@0 55 <em:unpack>true</em:unpack>
michael@0 56 <em:targetApplication>
michael@0 57 <!-- Firefox -->
michael@0 58 <Description>
michael@0 59 <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
michael@0 60 <em:minVersion>3.5</em:minVersion>
michael@0 61 <em:maxVersion>8.*</em:maxVersion>
michael@0 62 </Description>
michael@0 63 </em:targetApplication>
michael@0 64 <em:targetApplication>
michael@0 65 <!-- Thunderbird -->
michael@0 66 <Description>
michael@0 67 <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
michael@0 68 <em:minVersion>3.0a1pre</em:minVersion>
michael@0 69 <em:maxVersion>3.2*</em:maxVersion>
michael@0 70 </Description>
michael@0 71 </em:targetApplication>
michael@0 72 <em:targetApplication>
michael@0 73 <!-- Sunbird -->
michael@0 74 <Description>
michael@0 75 <em:id>{718e30fb-e89b-41dd-9da7-e25a45638b28}</em:id>
michael@0 76 <em:minVersion>0.6a1</em:minVersion>
michael@0 77 <em:maxVersion>1.0pre</em:maxVersion>
michael@0 78 </Description>
michael@0 79 </em:targetApplication>
michael@0 80 <em:targetApplication>
michael@0 81 <!-- SeaMonkey -->
michael@0 82 <Description>
michael@0 83 <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
michael@0 84 <em:minVersion>2.0a1</em:minVersion>
michael@0 85 <em:maxVersion>2.1*</em:maxVersion>
michael@0 86 </Description>
michael@0 87 </em:targetApplication>
michael@0 88 <em:targetApplication>
michael@0 89 <!-- Songbird -->
michael@0 90 <Description>
michael@0 91 <em:id>songbird@songbirdnest.com</em:id>
michael@0 92 <em:minVersion>0.3pre</em:minVersion>
michael@0 93 <em:maxVersion>1.3.0a</em:maxVersion>
michael@0 94 </Description>
michael@0 95 </em:targetApplication>
michael@0 96 <em:targetApplication>
michael@0 97 <Description>
michael@0 98 <em:id>toolkit@mozilla.org</em:id>
michael@0 99 <em:minVersion>1.9.1</em:minVersion>
michael@0 100 <em:maxVersion>2.0*</em:maxVersion>
michael@0 101 </Description>
michael@0 102 </em:targetApplication>
michael@0 103 </Description>
michael@0 104 </RDF>""",
michael@0 105 """<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
michael@0 106 xmlns:em="http://www.mozilla.org/2004/em-rdf#">
michael@0 107 <Description about="urn:mozilla:install-manifest">
michael@0 108 <em:targetApplication>
michael@0 109 <!-- Firefox -->
michael@0 110 <Description>
michael@0 111 <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
michael@0 112 <em:minVersion>3.5</em:minVersion>
michael@0 113 <em:maxVersion>8.*</em:maxVersion>
michael@0 114 </Description>
michael@0 115 </em:targetApplication>
michael@0 116 <em:id>winning</em:id>
michael@0 117 <em:name>MozMill</em:name>
michael@0 118 <em:version>2.0a</em:version>
michael@0 119 <em:creator>Adam Christian</em:creator>
michael@0 120 <em:description>A testing extension based on the Windmill Testing Framework client source</em:description>
michael@0 121 <em:unpack>true</em:unpack>
michael@0 122 </Description>
michael@0 123 </RDF>""",
michael@0 124 """<RDF xmlns="http://www.mozilla.org/2004/em-rdf#"
michael@0 125 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
michael@0 126 <rdf:Description about="urn:mozilla:install-manifest">
michael@0 127 <id>winning</id>
michael@0 128 <name>foo</name>
michael@0 129 <version>42</version>
michael@0 130 <description>A testing extension based on the Windmill Testing Framework client source</description>
michael@0 131 </rdf:Description>
michael@0 132 </RDF>""",
michael@0 133 """<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
michael@0 134 xmlns:foobar="http://www.mozilla.org/2004/em-rdf#">
michael@0 135 <Description about="urn:mozilla:install-manifest">
michael@0 136 <foobar:targetApplication>
michael@0 137 <!-- Firefox -->
michael@0 138 <Description>
michael@0 139 <foobar:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</foobar:id>
michael@0 140 <foobar:minVersion>3.5</foobar:minVersion>
michael@0 141 <foobar:maxVersion>8.*</foobar:maxVersion>
michael@0 142 </Description>
michael@0 143 </foobar:targetApplication>
michael@0 144 <foobar:id>winning</foobar:id>
michael@0 145 <foobar:name>MozMill</foobar:name>
michael@0 146 <foobar:version>2.0a</foobar:version>
michael@0 147 <foobar:creator>Adam Christian</foobar:creator>
michael@0 148 <foobar:description>A testing extension based on the Windmill Testing Framework client source</foobar:description>
michael@0 149 <foobar:unpack>true</foobar:unpack>
michael@0 150 </Description>
michael@0 151 </RDF>"""]
michael@0 152 return tests
michael@0 153
michael@0 154 if __name__ == '__main__':
michael@0 155 unittest.main()

mercurial