Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: third_party/mozprofile/tests/permissions.py

Issue 108313011: Adding mozilla libraries required by Firefox interop test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 # You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 import os
8 import shutil
9 try:
10 import sqlite3
11 except ImportError:
12 from pysqlite2 import dbapi2 as sqlite3
13 import tempfile
14 import unittest
15 from mozprofile.permissions import Permissions
16
17 class PermissionsTest(unittest.TestCase):
18
19 locations = """http://mochi.test:8888 primary,privileged
20 http://127.0.0.1:80 noxul
21 http://127.0.0.1:8888 privileged
22 """
23
24 profile_dir = None
25 locations_file = None
26
27 def setUp(self):
28 self.profile_dir = tempfile.mkdtemp()
29 self.locations_file = tempfile.NamedTemporaryFile()
30 self.locations_file.write(self.locations)
31 self.locations_file.flush()
32
33 def tearDown(self):
34 if self.profile_dir:
35 shutil.rmtree(self.profile_dir)
36 if self.locations_file:
37 self.locations_file.close()
38
39 def test_permissions_db(self):
40 perms = Permissions(self.profile_dir, self.locations_file.name)
41 perms_db_filename = os.path.join(self.profile_dir, 'permissions.sqlite')
42
43 select_stmt = 'select host, type, permission from moz_hosts'
44
45 con = sqlite3.connect(perms_db_filename)
46 cur = con.cursor()
47 cur.execute(select_stmt)
48 entries = cur.fetchall()
49
50 self.assertEqual(len(entries), 3)
51
52 self.assertEqual(entries[0][0], 'mochi.test')
53 self.assertEqual(entries[0][1], 'allowXULXBL')
54 self.assertEqual(entries[0][2], 1)
55
56 self.assertEqual(entries[1][0], '127.0.0.1')
57 self.assertEqual(entries[1][1], 'allowXULXBL')
58 self.assertEqual(entries[1][2], 2)
59
60 self.assertEqual(entries[2][0], '127.0.0.1')
61 self.assertEqual(entries[2][1], 'allowXULXBL')
62 self.assertEqual(entries[2][2], 1)
63
64 perms._locations.add_host('a.b.c', options='noxul')
65
66 cur.execute(select_stmt)
67 entries = cur.fetchall()
68
69 self.assertEqual(len(entries), 4)
70 self.assertEqual(entries[3][0], 'a.b.c')
71 self.assertEqual(entries[3][1], 'allowXULXBL')
72 self.assertEqual(entries[3][2], 2)
73
74 perms.clean_db()
75 # table should be removed
76 cur.execute("select * from sqlite_master where type='table'")
77 entries = cur.fetchall()
78 self.assertEqual(len(entries), 0)
79
80 def test_nw_prefs(self):
81 perms = Permissions(self.profile_dir, self.locations_file.name)
82
83 prefs, user_prefs = perms.network_prefs(False)
84
85 self.assertEqual(len(user_prefs), 0)
86 self.assertEqual(len(prefs), 6)
87
88 self.assertEqual(prefs[0], ('capability.principal.codebase.p1.granted',
89 'UniversalXPConnect'))
90 self.assertEqual(prefs[1], ('capability.principal.codebase.p1.id',
91 'http://mochi.test:8888'))
92 self.assertEqual(prefs[2], ('capability.principal.codebase.p1.subjectNam e', ''))
93
94 self.assertEqual(prefs[3], ('capability.principal.codebase.p2.granted',
95 'UniversalXPConnect'))
96 self.assertEqual(prefs[4], ('capability.principal.codebase.p2.id',
97 'http://127.0.0.1:8888'))
98 self.assertEqual(prefs[5], ('capability.principal.codebase.p2.subjectNam e', ''))
99
100
101 prefs, user_prefs = perms.network_prefs(True)
102 self.assertEqual(len(user_prefs), 2)
103 self.assertEqual(user_prefs[0], ('network.proxy.type', 2))
104 self.assertEqual(user_prefs[1][0], 'network.proxy.autoconfig_url')
105
106 origins_decl = "var origins = ['http://mochi.test:8888', 'http://127.0.0 .1:80', 'http://127.0.0.1:8888'];"
107 self.assertTrue(origins_decl in user_prefs[1][1])
108
109 proxy_check = "if (isHttp || isHttps || isWebSocket || isWebSocketSSL) return 'PROXY mochi.test:8888';"
110 self.assertTrue(proxy_check in user_prefs[1][1])
111
112
113 if __name__ == '__main__':
114 unittest.main()
OLDNEW
« no previous file with comments | « third_party/mozprofile/tests/manifest.ini ('k') | third_party/mozprofile/tests/server_locations.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698