Skip to content
Browse files

Bug 785146 - mozprofile should set the version for permissions.sqlite…

…;r=jhammel
  • Loading branch information...
1 parent 06d1926 commit d9e769d5bcdf5420e92fdf3b43f766e9c9a13520 @mihneadb mihneadb committed with k0s
Showing with 57 additions and 0 deletions.
  1. +1 −0 mozprofile/mozprofile/permissions.py
  2. +55 −0 mozprofile/tests/bug785146.py
  3. +1 −0 mozprofile/tests/manifest.ini
View
1 mozprofile/mozprofile/permissions.py
@@ -232,6 +232,7 @@ def write_db(self, locations):
# Open database and create table
permDB = sqlite3.connect(os.path.join(self._profileDir, "permissions.sqlite"))
cursor = permDB.cursor();
+ cursor.execute("PRAGMA schema_version = 3;")
# SQL copied from
# http://mxr.mozilla.org/mozilla-central/source/extensions/cookie/nsPermissionManager.cpp
cursor.execute("""CREATE TABLE IF NOT EXISTS moz_hosts (
View
55 mozprofile/tests/bug785146.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import shutil
+try:
+ import sqlite3
+except ImportError:
+ from pysqlite2 import dbapi2 as sqlite3
+import tempfile
+import unittest
+from mozprofile.permissions import Permissions
+
+class PermissionsTest(unittest.TestCase):
+
+ locations = """http://mochi.test:8888 primary,privileged
+http://127.0.0.1:80 noxul
+http://127.0.0.1:8888 privileged
+"""
+
+ profile_dir = None
+ locations_file = None
+
+ def setUp(self):
+ self.profile_dir = tempfile.mkdtemp()
+ self.locations_file = tempfile.NamedTemporaryFile()
+ self.locations_file.write(self.locations)
+ self.locations_file.flush()
+
+ def tearDown(self):
+ if self.profile_dir:
+ shutil.rmtree(self.profile_dir)
+ if self.locations_file:
+ self.locations_file.close()
+
+ def test_schema_version(self):
+ perms = Permissions(self.profile_dir, self.locations_file.name)
+ perms_db_filename = os.path.join(self.profile_dir, 'permissions.sqlite')
+ perms.write_db(self.locations_file)
+
+ stmt = 'PRAGMA schema_version;'
+
+ con = sqlite3.connect(perms_db_filename)
+ cur = con.cursor()
+ cur.execute(stmt)
+ entries = cur.fetchall()
+
+ schema_version = entries[0][0]
+ self.assertEqual(schema_version, 3)
+
+if __name__ == '__main__':
+ unittest.main()
View
1 mozprofile/tests/manifest.ini
@@ -4,3 +4,4 @@
[permissions.py]
[bug758250.py]
[test_nonce.py]
+[bug785146.py]

0 comments on commit d9e769d

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