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