Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Tests that PerrmissionsUtils.jsm works as expected, including: |
michael@0 | 6 | // * PermissionsUtils.importfromPrefs() |
michael@0 | 7 | // <ROOT>.[whitelist|blacklist].add preferences are emptied when |
michael@0 | 8 | // converted into permissions on startup. |
michael@0 | 9 | |
michael@0 | 10 | |
michael@0 | 11 | const PREF_ROOT = "testpermissions."; |
michael@0 | 12 | const TEST_PERM = "text-permission"; |
michael@0 | 13 | |
michael@0 | 14 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 15 | Components.utils.import("resource://gre/modules/PermissionsUtils.jsm"); |
michael@0 | 16 | |
michael@0 | 17 | function run_test() { |
michael@0 | 18 | test_importfromPrefs(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | |
michael@0 | 22 | function test_importfromPrefs() { |
michael@0 | 23 | // Create own preferences to test |
michael@0 | 24 | Services.prefs.setCharPref(PREF_ROOT + "whitelist.add.EMPTY", ""); |
michael@0 | 25 | Services.prefs.setCharPref(PREF_ROOT + "whitelist.add.EMPTY2", ","); |
michael@0 | 26 | Services.prefs.setCharPref(PREF_ROOT + "whitelist.add.TEST", "whitelist.example.com"); |
michael@0 | 27 | Services.prefs.setCharPref(PREF_ROOT + "whitelist.add.TEST2", "whitelist2-1.example.com,whitelist2-2.example.com"); |
michael@0 | 28 | Services.prefs.setCharPref(PREF_ROOT + "blacklist.add.EMPTY", ""); |
michael@0 | 29 | Services.prefs.setCharPref(PREF_ROOT + "blacklist.add.TEST", "blacklist.example.com,"); |
michael@0 | 30 | Services.prefs.setCharPref(PREF_ROOT + "blacklist.add.TEST2", ",blacklist2-1.example.com,blacklist2-2.example.com"); |
michael@0 | 31 | |
michael@0 | 32 | // Import them |
michael@0 | 33 | PermissionsUtils.importFromPrefs(PREF_ROOT, TEST_PERM); |
michael@0 | 34 | |
michael@0 | 35 | // Get list of preferences to check |
michael@0 | 36 | let preferences = Services.prefs.getChildList(PREF_ROOT, {}); |
michael@0 | 37 | |
michael@0 | 38 | // Check preferences were emptied |
michael@0 | 39 | for (let pref of preferences) { |
michael@0 | 40 | do_check_eq(Services.prefs.getCharPref(pref), ""); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | // Check they were imported into the permissions manager |
michael@0 | 44 | let whitelisted = ["whitelist.example.com", |
michael@0 | 45 | "whitelist2-1.example.com", |
michael@0 | 46 | "whitelist2-2.example.com"]; |
michael@0 | 47 | let blacklisted = ["blacklist.example.com", |
michael@0 | 48 | "blacklist2-1.example.com", |
michael@0 | 49 | "blacklist2-2.example.com"]; |
michael@0 | 50 | for (let url of whitelisted) { |
michael@0 | 51 | let uri = Services.io.newURI("http://" + url, null, null); |
michael@0 | 52 | do_check_eq(Services.perms.testPermission(uri, TEST_PERM), Services.perms.ALLOW_ACTION); |
michael@0 | 53 | } |
michael@0 | 54 | for (let url of blacklisted) { |
michael@0 | 55 | let uri = Services.io.newURI("http://" + url, null, null); |
michael@0 | 56 | do_check_eq(Services.perms.testPermission(uri, TEST_PERM), Services.perms.DENY_ACTION); |
michael@0 | 57 | } |
michael@0 | 58 | } |