browser/components/preferences/tests/browser_chunk_permissions.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
michael@0 5 Components.utils.import("resource://gre/modules/NetUtil.jsm");
michael@0 6 Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm");
michael@0 7
michael@0 8 const ABOUT_PERMISSIONS_SPEC = "about:permissions";
michael@0 9
michael@0 10 const TEST_URI_1 = NetUtil.newURI("http://mozilla.com/");
michael@0 11 const TEST_URI_2 = NetUtil.newURI("http://mozilla.org/");
michael@0 12 const TEST_URI_3 = NetUtil.newURI("http://wikipedia.org/");
michael@0 13
michael@0 14 // values from DefaultPermissions object
michael@0 15 const PERM_UNKNOWN = 0;
michael@0 16 const PERM_ALLOW = 1;
michael@0 17 const PERM_DENY = 2;
michael@0 18
michael@0 19 // used to set permissions on test sites
michael@0 20 const TEST_PERMS = {
michael@0 21 "password": PERM_ALLOW,
michael@0 22 "cookie": PERM_ALLOW,
michael@0 23 "geo": PERM_UNKNOWN,
michael@0 24 "indexedDB": PERM_UNKNOWN,
michael@0 25 "popup": PERM_DENY
michael@0 26 };
michael@0 27
michael@0 28 function test() {
michael@0 29 waitForExplicitFinish();
michael@0 30 registerCleanupFunction(cleanUp);
michael@0 31 setup(function() {
michael@0 32 runNextTest();
michael@0 33 });
michael@0 34 }
michael@0 35
michael@0 36 function setup(aCallback) {
michael@0 37 // add test history visit
michael@0 38 addVisits(TEST_URI_1, function() {
michael@0 39 // set permissions ourselves to avoid problems with different defaults
michael@0 40 // from test harness configuration
michael@0 41 for (let type in TEST_PERMS) {
michael@0 42 if (type == "password") {
michael@0 43 Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true);
michael@0 44 } else {
michael@0 45 // set permissions on a site without history visits to test enumerateServices
michael@0 46 Services.perms.add(TEST_URI_2, type, TEST_PERMS[type]);
michael@0 47 }
michael@0 48 }
michael@0 49
michael@0 50 Services.perms.add(TEST_URI_3, "popup", TEST_PERMS["popup"]);
michael@0 51 aCallback();
michael@0 52 });
michael@0 53 }
michael@0 54
michael@0 55 function cleanUp() {
michael@0 56 for (let type in TEST_PERMS) {
michael@0 57 if (type != "password") {
michael@0 58 Services.perms.remove(TEST_URI_1.host, type);
michael@0 59 Services.perms.remove(TEST_URI_2.host, type);
michael@0 60 Services.perms.remove(TEST_URI_3.host, type);
michael@0 61 }
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 function runNextTest() {
michael@0 66 if (gTestIndex == tests.length) {
michael@0 67 waitForClearHistory(finish);
michael@0 68 return;
michael@0 69 }
michael@0 70
michael@0 71 let nextTest = tests[gTestIndex++];
michael@0 72 info(nextTest.desc);
michael@0 73
michael@0 74 function preinit_observer() {
michael@0 75 Services.obs.removeObserver(preinit_observer, "browser-permissions-preinit");
michael@0 76 nextTest.preInit();
michael@0 77 }
michael@0 78 Services.obs.addObserver(preinit_observer, "browser-permissions-preinit", false);
michael@0 79
michael@0 80 function init_observer() {
michael@0 81 Services.obs.removeObserver(init_observer, "browser-permissions-initialized");
michael@0 82 nextTest.run();
michael@0 83 }
michael@0 84 Services.obs.addObserver(init_observer, "browser-permissions-initialized", false);
michael@0 85
michael@0 86 // open about:permissions
michael@0 87 let tab = gBrowser.selectedTab = gBrowser.addTab("about:permissions");
michael@0 88 registerCleanupFunction(function() {
michael@0 89 gBrowser.removeTab(tab);
michael@0 90 });
michael@0 91 }
michael@0 92
michael@0 93 var gSitesList;
michael@0 94
michael@0 95 var gTestIndex = 0;
michael@0 96 var tests = [
michael@0 97 // 'preInit' occurs after opening about:permissions, before sites-list is populated
michael@0 98 // 'run' occurs after sites-list is populated
michael@0 99 {
michael@0 100 desc: "test filtering before sites-list is fully constructed.",
michael@0 101 preInit: function() {
michael@0 102 let sitesFilter = gBrowser.contentDocument.getElementById("sites-filter");
michael@0 103 sitesFilter.value = TEST_URI_2.host;
michael@0 104 sitesFilter.doCommand();
michael@0 105 },
michael@0 106 run: function() {
michael@0 107 let testSite1 = getSiteItem(TEST_URI_1.host);
michael@0 108 ok(testSite1.collapsed, "test site 1 is collapsed after early filtering");
michael@0 109 let testSite2 = getSiteItem(TEST_URI_2.host);
michael@0 110 ok(!testSite2.collapsed, "test site 2 is not collapsed after early filtering");
michael@0 111 let testSite3 = getSiteItem(TEST_URI_3.host);
michael@0 112 ok(testSite3.collapsed, "test site 3 is collapsed after early filtering");
michael@0 113
michael@0 114 runNextTest();
michael@0 115 }
michael@0 116 },
michael@0 117 {
michael@0 118 desc: "test removing from sites-list before it is fully constructed.",
michael@0 119 preInit: function() {
michael@0 120 ForgetAboutSite.removeDataFromDomain(TEST_URI_2.host);
michael@0 121 },
michael@0 122 run: function() {
michael@0 123 let testSite1 = getSiteItem(TEST_URI_1.host);
michael@0 124 ok(!testSite2, "test site 1 was not removed from sites list");
michael@0 125 let testSite2 = getSiteItem(TEST_URI_2.host);
michael@0 126 ok(!testSite2, "test site 2 was pre-removed from sites list");
michael@0 127 let testSite3 = getSiteItem(TEST_URI_3.host);
michael@0 128 ok(!testSite2, "test site 3 was not removed from sites list");
michael@0 129
michael@0 130 runNextTest();
michael@0 131 }
michael@0 132 }
michael@0 133 ];
michael@0 134
michael@0 135 function getSiteItem(aHost) {
michael@0 136 return gBrowser.contentDocument.
michael@0 137 querySelector(".site[value='" + aHost + "']");
michael@0 138 }
michael@0 139
michael@0 140 // copied from toolkit/components/places/tests/head_common.js
michael@0 141 function waitForClearHistory(aCallback) {
michael@0 142 let observer = {
michael@0 143 observe: function(aSubject, aTopic, aData) {
michael@0 144 Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
michael@0 145 aCallback();
michael@0 146 }
michael@0 147 };
michael@0 148 Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
michael@0 149 PlacesUtils.bhistory.removeAllPages();
michael@0 150 }

mercurial