diff --git a/.eslintrc.js b/.eslintrc.js index 556f107cbfba..c6ef2e059fcd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -45,7 +45,6 @@ module.exports = { "overrides": [{ "files": [ "devtools/**", - "extensions/**", "gfx/**", "gradle/**", "hal/**", diff --git a/.prettierignore b/.prettierignore index aedb3ba8f38b..3c2badcae60a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js toolkit/components/telemetry/healthreport-prefs.js # Ignore all top-level directories for now. -extensions/** gfx/** gradle/** hal/** diff --git a/extensions/permissions/test/browser_permmgr_sync.js b/extensions/permissions/test/browser_permmgr_sync.js index 1e3c4936f053..4232d6ff2ab3 100644 --- a/extensions/permissions/test/browser_permmgr_sync.js +++ b/extensions/permissions/test/browser_permmgr_sync.js @@ -1,10 +1,16 @@ function addPerm(aURI, aName) { - Services.perms.add(Services.io.newURI(aURI), aName, Services.perms.ALLOW_ACTION); + Services.perms.add( + Services.io.newURI(aURI), + aName, + Services.perms.ALLOW_ACTION + ); } function hasPerm(aURI, aName) { - return Services.perms.testPermission(Services.io.newURI(aURI), aName) - == Services.perms.ALLOW_ACTION; + return ( + Services.perms.testPermission(Services.io.newURI(aURI), aName) == + Services.perms.ALLOW_ACTION + ); } add_task(async function() { @@ -24,13 +30,18 @@ add_task(async function() { // Then zero is correct. } let safeProcessCount = keepAliveCount + 2; - info("dom.ipc.keepProcessesAlive.web is " + keepAliveCount + ", boosting " + - "process count temporarily to " + safeProcessCount); + info( + "dom.ipc.keepProcessesAlive.web is " + + keepAliveCount + + ", boosting " + + "process count temporarily to " + + safeProcessCount + ); await SpecialPowers.pushPrefEnv({ set: [ ["dom.ipc.processCount", safeProcessCount], - ["dom.ipc.processCount.web", safeProcessCount] - ] + ["dom.ipc.processCount.web", safeProcessCount], + ], }); addPerm("http://example.com", "perm1"); @@ -40,131 +51,284 @@ add_task(async function() { // NOTE: This permission is a preload permission, so it should be avaliable in the content process from startup. addPerm("https://somerandomwebsite.com", "document"); - await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, async function(aBrowser) { - await ContentTask.spawn(aBrowser, null, async function() { - // Before the load http URIs shouldn't have been sent down yet - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "perm1"), - Services.perms.UNKNOWN_ACTION, "perm1-1"); - is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"), - "perm2"), - Services.perms.UNKNOWN_ACTION, "perm2-1"); - is(Services.perms.testPermission(Services.io.newURI("about:home"), - "perm3"), - Services.perms.ALLOW_ACTION, "perm3-1"); - is(Services.perms.testPermission(Services.io.newURI("https://example.com"), - "perm4"), - Services.perms.UNKNOWN_ACTION, "perm4-1"); - is(Services.perms.testPermission(Services.io.newURI("https://somerandomwebsite.com"), - "document"), - Services.perms.ALLOW_ACTION, "document-1"); + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:blank" }, + async function(aBrowser) { + await ContentTask.spawn(aBrowser, null, async function() { + // Before the load http URIs shouldn't have been sent down yet + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "perm1" + ), + Services.perms.UNKNOWN_ACTION, + "perm1-1" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://foo.bar.example.com"), + "perm2" + ), + Services.perms.UNKNOWN_ACTION, + "perm2-1" + ); + is( + Services.perms.testPermission( + Services.io.newURI("about:home"), + "perm3" + ), + Services.perms.ALLOW_ACTION, + "perm3-1" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://example.com"), + "perm4" + ), + Services.perms.UNKNOWN_ACTION, + "perm4-1" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://somerandomwebsite.com"), + "document" + ), + Services.perms.ALLOW_ACTION, + "document-1" + ); - // Perform a load of example.com - await new Promise(resolve => { - let iframe = content.document.createElement('iframe'); - iframe.setAttribute('src', 'http://example.com'); - iframe.onload = resolve; - content.document.body.appendChild(iframe); + // Perform a load of example.com + await new Promise(resolve => { + let iframe = content.document.createElement("iframe"); + iframe.setAttribute("src", "http://example.com"); + iframe.onload = resolve; + content.document.body.appendChild(iframe); + }); + + // After the load finishes, we should know about example.com, but not foo.bar.example.com + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "perm1" + ), + Services.perms.ALLOW_ACTION, + "perm1-2" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://foo.bar.example.com"), + "perm2" + ), + Services.perms.UNKNOWN_ACTION, + "perm2-2" + ); + is( + Services.perms.testPermission( + Services.io.newURI("about:home"), + "perm3" + ), + Services.perms.ALLOW_ACTION, + "perm3-2" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://example.com"), + "perm4" + ), + Services.perms.UNKNOWN_ACTION, + "perm4-2" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://somerandomwebsite.com"), + "document" + ), + Services.perms.ALLOW_ACTION, + "document-2" + ); }); - // After the load finishes, we should know about example.com, but not foo.bar.example.com - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "perm1"), - Services.perms.ALLOW_ACTION, "perm1-2"); - is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"), - "perm2"), - Services.perms.UNKNOWN_ACTION, "perm2-2"); - is(Services.perms.testPermission(Services.io.newURI("about:home"), - "perm3"), - Services.perms.ALLOW_ACTION, "perm3-2"); - is(Services.perms.testPermission(Services.io.newURI("https://example.com"), - "perm4"), - Services.perms.UNKNOWN_ACTION, "perm4-2"); - is(Services.perms.testPermission(Services.io.newURI("https://somerandomwebsite.com"), - "document"), - Services.perms.ALLOW_ACTION, "document-2"); - }); + addPerm("http://example.com", "newperm1"); + addPerm("http://foo.bar.example.com", "newperm2"); + addPerm("about:home", "newperm3"); + addPerm("https://example.com", "newperm4"); + addPerm("https://someotherrandomwebsite.com", "document"); - addPerm("http://example.com", "newperm1"); - addPerm("http://foo.bar.example.com", "newperm2"); - addPerm("about:home", "newperm3"); - addPerm("https://example.com", "newperm4"); - addPerm("https://someotherrandomwebsite.com", "document"); + await ContentTask.spawn(aBrowser, null, async function() { + // The new permissions should be avaliable, but only for + // http://example.com, and about:home + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "perm1" + ), + Services.perms.ALLOW_ACTION, + "perm1-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "newperm1" + ), + Services.perms.ALLOW_ACTION, + "newperm1-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://foo.bar.example.com"), + "perm2" + ), + Services.perms.UNKNOWN_ACTION, + "perm2-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://foo.bar.example.com"), + "newperm2" + ), + Services.perms.UNKNOWN_ACTION, + "newperm2-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("about:home"), + "perm3" + ), + Services.perms.ALLOW_ACTION, + "perm3-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("about:home"), + "newperm3" + ), + Services.perms.ALLOW_ACTION, + "newperm3-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://example.com"), + "perm4" + ), + Services.perms.UNKNOWN_ACTION, + "perm4-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://example.com"), + "newperm4" + ), + Services.perms.UNKNOWN_ACTION, + "newperm4-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://somerandomwebsite.com"), + "document" + ), + Services.perms.ALLOW_ACTION, + "document-3" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://someotherrandomwebsite.com"), + "document" + ), + Services.perms.ALLOW_ACTION, + "otherdocument-3" + ); - await ContentTask.spawn(aBrowser, null, async function() { - // The new permissions should be avaliable, but only for - // http://example.com, and about:home - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "perm1"), - Services.perms.ALLOW_ACTION, "perm1-3"); - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "newperm1"), - Services.perms.ALLOW_ACTION, "newperm1-3"); - is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"), - "perm2"), - Services.perms.UNKNOWN_ACTION, "perm2-3"); - is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"), - "newperm2"), - Services.perms.UNKNOWN_ACTION, "newperm2-3"); - is(Services.perms.testPermission(Services.io.newURI("about:home"), - "perm3"), - Services.perms.ALLOW_ACTION, "perm3-3"); - is(Services.perms.testPermission(Services.io.newURI("about:home"), - "newperm3"), - Services.perms.ALLOW_ACTION, "newperm3-3"); - is(Services.perms.testPermission(Services.io.newURI("https://example.com"), - "perm4"), - Services.perms.UNKNOWN_ACTION, "perm4-3"); - is(Services.perms.testPermission(Services.io.newURI("https://example.com"), - "newperm4"), - Services.perms.UNKNOWN_ACTION, "newperm4-3"); - is(Services.perms.testPermission(Services.io.newURI("https://somerandomwebsite.com"), - "document"), - Services.perms.ALLOW_ACTION, "document-3"); - is(Services.perms.testPermission(Services.io.newURI("https://someotherrandomwebsite.com"), - "document"), - Services.perms.ALLOW_ACTION, "otherdocument-3"); + // Loading a subdomain now, on https + await new Promise(resolve => { + let iframe = content.document.createElement("iframe"); + iframe.setAttribute("src", "https://sub1.test1.example.com"); + iframe.onload = resolve; + content.document.body.appendChild(iframe); + }); - // Loading a subdomain now, on https - await new Promise(resolve => { - let iframe = content.document.createElement('iframe'); - iframe.setAttribute('src', 'https://sub1.test1.example.com'); - iframe.onload = resolve; - content.document.body.appendChild(iframe); + // Now that the https subdomain has loaded, we want to make sure that the + // permissions are also avaliable for its parent domain, https://example.com! + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "perm1" + ), + Services.perms.ALLOW_ACTION, + "perm1-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "newperm1" + ), + Services.perms.ALLOW_ACTION, + "newperm1-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://foo.bar.example.com"), + "perm2" + ), + Services.perms.UNKNOWN_ACTION, + "perm2-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("http://foo.bar.example.com"), + "newperm2" + ), + Services.perms.UNKNOWN_ACTION, + "newperm2-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("about:home"), + "perm3" + ), + Services.perms.ALLOW_ACTION, + "perm3-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("about:home"), + "newperm3" + ), + Services.perms.ALLOW_ACTION, + "newperm3-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://example.com"), + "perm4" + ), + Services.perms.ALLOW_ACTION, + "perm4-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://example.com"), + "newperm4" + ), + Services.perms.ALLOW_ACTION, + "newperm4-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://somerandomwebsite.com"), + "document" + ), + Services.perms.ALLOW_ACTION, + "document-4" + ); + is( + Services.perms.testPermission( + Services.io.newURI("https://someotherrandomwebsite.com"), + "document" + ), + Services.perms.ALLOW_ACTION, + "otherdocument-4" + ); }); - - // Now that the https subdomain has loaded, we want to make sure that the - // permissions are also avaliable for its parent domain, https://example.com! - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "perm1"), - Services.perms.ALLOW_ACTION, "perm1-4"); - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "newperm1"), - Services.perms.ALLOW_ACTION, "newperm1-4"); - is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"), - "perm2"), - Services.perms.UNKNOWN_ACTION, "perm2-4"); - is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"), - "newperm2"), - Services.perms.UNKNOWN_ACTION, "newperm2-4"); - is(Services.perms.testPermission(Services.io.newURI("about:home"), - "perm3"), - Services.perms.ALLOW_ACTION, "perm3-4"); - is(Services.perms.testPermission(Services.io.newURI("about:home"), - "newperm3"), - Services.perms.ALLOW_ACTION, "newperm3-4"); - is(Services.perms.testPermission(Services.io.newURI("https://example.com"), - "perm4"), - Services.perms.ALLOW_ACTION, "perm4-4"); - is(Services.perms.testPermission(Services.io.newURI("https://example.com"), - "newperm4"), - Services.perms.ALLOW_ACTION, "newperm4-4"); - is(Services.perms.testPermission(Services.io.newURI("https://somerandomwebsite.com"), - "document"), - Services.perms.ALLOW_ACTION, "document-4"); - is(Services.perms.testPermission(Services.io.newURI("https://someotherrandomwebsite.com"), - "document"), - Services.perms.ALLOW_ACTION, "otherdocument-4"); - }); - }); + } + ); }); diff --git a/extensions/permissions/test/browser_permmgr_viewsrc.js b/extensions/permissions/test/browser_permmgr_viewsrc.js index 83134b63b221..912ead75e919 100644 --- a/extensions/permissions/test/browser_permmgr_viewsrc.js +++ b/extensions/permissions/test/browser_permmgr_viewsrc.js @@ -1,19 +1,27 @@ add_task(async function() { // Add a permission for example.com, start a new content process, and make // sure that the permission has been sent down. - Services.perms.add(Services.io.newURI("http://example.com"), - "viewsourceTestingPerm", - Services.perms.ALLOW_ACTION); + Services.perms.add( + Services.io.newURI("http://example.com"), + "viewsourceTestingPerm", + Services.perms.ALLOW_ACTION + ); - let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, - "view-source:http://example.com", - /* waitForLoad */ true, - /* waitForStateStop */ false, - /* forceNewProcess */ true); + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "view-source:http://example.com", + /* waitForLoad */ true, + /* waitForStateStop */ false, + /* forceNewProcess */ true + ); await ContentTask.spawn(tab.linkedBrowser, null, async function() { - is(Services.perms.testPermission(Services.io.newURI("http://example.com"), - "viewsourceTestingPerm"), - Services.perms.ALLOW_ACTION); + is( + Services.perms.testPermission( + Services.io.newURI("http://example.com"), + "viewsourceTestingPerm" + ), + Services.perms.ALLOW_ACTION + ); }); BrowserTestUtils.removeTab(tab); }); diff --git a/extensions/permissions/test/unit/head.js b/extensions/permissions/test/unit/head.js index 7f1936324e80..b3b92bd106ea 100644 --- a/extensions/permissions/test/unit/head.js +++ b/extensions/permissions/test/unit/head.js @@ -2,8 +2,8 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); -var {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); // Helper to step a generator function and catch a StopIteration exception. function do_run_generator(generator) { @@ -30,4 +30,3 @@ function do_count_enumerator(enumerator) { } return i; } - diff --git a/extensions/permissions/test/unit/test_permmanager_cleardata.js b/extensions/permissions/test/unit/test_permmanager_cleardata.js index af13917a67c8..0dc002a8b0eb 100644 --- a/extensions/permissions/test/unit/test_permmanager_cleardata.js +++ b/extensions/permissions/test/unit/test_permmanager_cleardata.js @@ -4,22 +4,22 @@ var pm; // Create a principal based on the { origin, originAttributes }. -function createPrincipal(aOrigin, aOriginAttributes) -{ - return Services.scriptSecurityManager.createCodebasePrincipal(NetUtil.newURI(aOrigin), aOriginAttributes); +function createPrincipal(aOrigin, aOriginAttributes) { + return Services.scriptSecurityManager.createCodebasePrincipal( + NetUtil.newURI(aOrigin), + aOriginAttributes + ); } // Return the data required by 'clear-origin-attributes-data' notification. -function getData(aPattern) -{ +function getData(aPattern) { return JSON.stringify(aPattern); } // Use aEntries to create principals, add permissions to them and check that they have them. // Then, it is notifying 'clear-origin-attributes-data' with the given aData and check if the permissions // of principals[i] matches the permission in aResults[i]. -function test(aEntries, aData, aResults) -{ +function test(aEntries, aData, aResults) { let principals = []; for (entry of aEntries) { @@ -27,40 +27,68 @@ function test(aEntries, aData, aResults) } for (principal of principals) { - Assert.equal(pm.testPermissionFromPrincipal(principal, "test/clear-origin"), pm.UNKNOWN_ACTION); - pm.addFromPrincipal(principal, "test/clear-origin", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); - Assert.equal(pm.testPermissionFromPrincipal(principal, "test/clear-origin"), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(principal, "test/clear-origin"), + pm.UNKNOWN_ACTION + ); + pm.addFromPrincipal( + principal, + "test/clear-origin", + pm.ALLOW_ACTION, + pm.EXPIRE_NEVER, + 0 + ); + Assert.equal( + pm.testPermissionFromPrincipal(principal, "test/clear-origin"), + pm.ALLOW_ACTION + ); } - Services.obs.notifyObservers(null, 'clear-origin-attributes-data', aData); + Services.obs.notifyObservers(null, "clear-origin-attributes-data", aData); var length = aEntries.length; - for (let i=0; i { let count = 0; let max = 20; @@ -246,13 +374,17 @@ function checkCapabilityViaDB(expected, origin = TEST_ORIGIN, type = TEST_PERMIS // value isn't correct - see if we've retried enough if (count++ == max) { // the do_check_eq() below will fail - which is what we want. - Assert.equal(got, expected, "The database wasn't updated with the expected value"); + Assert.equal( + got, + expected, + "The database wasn't updated with the expected value" + ); resolve(); return; } // we can retry... do_timeout(100, do_check); - } + }; do_check(); }); } @@ -261,19 +393,24 @@ function checkCapabilityViaDB(expected, origin = TEST_ORIGIN, type = TEST_PERMIS // value (ie, the "capability" in nsIPermission parlance) or null if it can't // be found. function findCapabilityViaDB(origin = TEST_ORIGIN, type = TEST_PERMISSION) { - let principal = Services.scriptSecurityManager.createCodebasePrincipal(origin, {}); + let principal = Services.scriptSecurityManager.createCodebasePrincipal( + origin, + {} + ); let originStr = principal.origin; let file = Services.dirsvc.get("ProfD", Ci.nsIFile); file.append("permissions.sqlite"); - let storage = Cc["@mozilla.org/storage/service;1"] - .getService(Ci.mozIStorageService); + let storage = Cc["@mozilla.org/storage/service;1"].getService( + Ci.mozIStorageService + ); let connection = storage.openDatabase(file); let query = connection.createStatement( - "SELECT permission FROM moz_perms WHERE origin = :origin AND type = :type"); + "SELECT permission FROM moz_perms WHERE origin = :origin AND type = :type" + ); query.bindByName("origin", originStr); query.bindByName("type", type); @@ -284,7 +421,7 @@ function findCapabilityViaDB(origin = TEST_ORIGIN, type = TEST_PERMISSION) { let result = query.getInt32(0); if (query.executeStep()) { // this is bad - we never expect more than 1 row here. - do_throw("More than 1 row found!") + do_throw("More than 1 row found!"); } return result; } diff --git a/extensions/permissions/test/unit/test_permmanager_expiration.js b/extensions/permissions/test/unit/test_permmanager_expiration.js index 8a92fe12d975..d5801f0a959b 100644 --- a/extensions/permissions/test/unit/test_permmanager_expiration.js +++ b/extensions/permissions/test/unit/test_permmanager_expiration.js @@ -10,8 +10,7 @@ function run_test() { test_generator.next(); } -function continue_test() -{ +function continue_test() { do_run_generator(test_generator); } @@ -21,62 +20,181 @@ function* do_run_test() { let pm = Services.perms; let permURI = NetUtil.newURI("http://example.com"); - let principal = Services.scriptSecurityManager.createCodebasePrincipal(permURI, {}); + let principal = Services.scriptSecurityManager.createCodebasePrincipal( + permURI, + {} + ); let now = Number(Date.now()); // add a permission with *now* expiration - pm.addFromPrincipal(principal, "test/expiration-perm-exp", 1, pm.EXPIRE_TIME, now); - pm.addFromPrincipal(principal, "test/expiration-session-exp", 1, pm.EXPIRE_SESSION, now); + pm.addFromPrincipal( + principal, + "test/expiration-perm-exp", + 1, + pm.EXPIRE_TIME, + now + ); + pm.addFromPrincipal( + principal, + "test/expiration-session-exp", + 1, + pm.EXPIRE_SESSION, + now + ); // add a permission with future expiration (100 milliseconds) - pm.addFromPrincipal(principal, "test/expiration-perm-exp2", 1, pm.EXPIRE_TIME, now + 100); - pm.addFromPrincipal(principal, "test/expiration-session-exp2", 1, pm.EXPIRE_SESSION, now + 100); + pm.addFromPrincipal( + principal, + "test/expiration-perm-exp2", + 1, + pm.EXPIRE_TIME, + now + 100 + ); + pm.addFromPrincipal( + principal, + "test/expiration-session-exp2", + 1, + pm.EXPIRE_SESSION, + now + 100 + ); // add a permission with future expiration (1000 seconds) - pm.addFromPrincipal(principal, "test/expiration-perm-exp3", 1, pm.EXPIRE_TIME, now + 1e6); - pm.addFromPrincipal(principal, "test/expiration-session-exp3", 1, pm.EXPIRE_SESSION, now + 1e6); + pm.addFromPrincipal( + principal, + "test/expiration-perm-exp3", + 1, + pm.EXPIRE_TIME, + now + 1e6 + ); + pm.addFromPrincipal( + principal, + "test/expiration-session-exp3", + 1, + pm.EXPIRE_SESSION, + now + 1e6 + ); // add a permission without expiration - pm.addFromPrincipal(principal, "test/expiration-perm-nexp", 1, pm.EXPIRE_NEVER, 0); + pm.addFromPrincipal( + principal, + "test/expiration-perm-nexp", + 1, + pm.EXPIRE_NEVER, + 0 + ); // add a permission for renewal - pm.addFromPrincipal(principal, "test/expiration-perm-renewable", 1, pm.EXPIRE_TIME, now + 100); - pm.addFromPrincipal(principal, "test/expiration-session-renewable", 1, pm.EXPIRE_SESSION, now + 100); + pm.addFromPrincipal( + principal, + "test/expiration-perm-renewable", + 1, + pm.EXPIRE_TIME, + now + 100 + ); + pm.addFromPrincipal( + principal, + "test/expiration-session-renewable", + 1, + pm.EXPIRE_SESSION, + now + 100 + ); // And immediately renew them with longer timeouts - pm.updateExpireTime(principal, "test/expiration-perm-renewable", true, now + 100, now + 1e6); - pm.updateExpireTime(principal, "test/expiration-session-renewable", true, now + 1e6, now + 100); + pm.updateExpireTime( + principal, + "test/expiration-perm-renewable", + true, + now + 100, + now + 1e6 + ); + pm.updateExpireTime( + principal, + "test/expiration-session-renewable", + true, + now + 1e6, + now + 100 + ); // check that the second two haven't expired yet - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-perm-exp3")); - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-session-exp3")); - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-perm-nexp")); - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-perm-renewable")); - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-session-renewable")); + Assert.equal( + 1, + pm.testPermissionFromPrincipal(principal, "test/expiration-perm-exp3") + ); + Assert.equal( + 1, + pm.testPermissionFromPrincipal(principal, "test/expiration-session-exp3") + ); + Assert.equal( + 1, + pm.testPermissionFromPrincipal(principal, "test/expiration-perm-nexp") + ); + Assert.equal( + 1, + pm.testPermissionFromPrincipal(principal, "test/expiration-perm-renewable") + ); + Assert.equal( + 1, + pm.testPermissionFromPrincipal( + principal, + "test/expiration-session-renewable" + ) + ); // ... and the first one has do_timeout(10, continue_test); yield; - Assert.equal(0, pm.testPermissionFromPrincipal(principal, "test/expiration-perm-exp")); - Assert.equal(0, pm.testPermissionFromPrincipal(principal, "test/expiration-session-exp")); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal, "test/expiration-perm-exp") + ); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal, "test/expiration-session-exp") + ); // ... and that the short-term one will do_timeout(200, continue_test); yield; - Assert.equal(0, pm.testPermissionFromPrincipal(principal, "test/expiration-perm-exp2")); - Assert.equal(0, pm.testPermissionFromPrincipal(principal, "test/expiration-session-exp2")); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal, "test/expiration-perm-exp2") + ); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal, "test/expiration-session-exp2") + ); // Check that .getPermission returns a matching result - Assert.equal(null, pm.getPermissionObject(principal, "test/expiration-perm-exp", false)); - Assert.equal(null, pm.getPermissionObject(principal, "test/expiration-session-exp", false)); - Assert.equal(null, pm.getPermissionObject(principal, "test/expiration-perm-exp2", false)); - Assert.equal(null, pm.getPermissionObject(principal, "test/expiration-session-exp2", false)); + Assert.equal( + null, + pm.getPermissionObject(principal, "test/expiration-perm-exp", false) + ); + Assert.equal( + null, + pm.getPermissionObject(principal, "test/expiration-session-exp", false) + ); + Assert.equal( + null, + pm.getPermissionObject(principal, "test/expiration-perm-exp2", false) + ); + Assert.equal( + null, + pm.getPermissionObject(principal, "test/expiration-session-exp2", false) + ); // Check that the renewable permissions actually got renewed - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-perm-renewable")); - Assert.equal(1, pm.testPermissionFromPrincipal(principal, "test/expiration-session-renewable")); + Assert.equal( + 1, + pm.testPermissionFromPrincipal(principal, "test/expiration-perm-renewable") + ); + Assert.equal( + 1, + pm.testPermissionFromPrincipal( + principal, + "test/expiration-session-renewable" + ) + ); do_finish_generator_test(test_generator); } - diff --git a/extensions/permissions/test/unit/test_permmanager_getAllForURI.js b/extensions/permissions/test/unit/test_permmanager_getAllForURI.js index 6cec75a71103..cc02d281387f 100644 --- a/extensions/permissions/test/unit/test_permmanager_getAllForURI.js +++ b/extensions/permissions/test/unit/test_permmanager_getAllForURI.js @@ -2,8 +2,9 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function check_enumerator(uri, permissions) { - let pm = Cc["@mozilla.org/permissionmanager;1"] - .getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); let enumerator = pm.getAllForURI(uri); for ([type, capability] of permissions) { @@ -18,61 +19,55 @@ function check_enumerator(uri, permissions) { } function run_test() { - let pm = Cc["@mozilla.org/permissionmanager;1"] - .getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); let uri = NetUtil.newURI("http://example.com"); let sub = NetUtil.newURI("http://sub.example.com"); - check_enumerator(uri, [ ]); + check_enumerator(uri, []); pm.add(uri, "test/getallforuri", pm.ALLOW_ACTION); - check_enumerator(uri, [ - [ "test/getallforuri", pm.ALLOW_ACTION ] - ]); + check_enumerator(uri, [["test/getallforuri", pm.ALLOW_ACTION]]); // check that uris are matched exactly - check_enumerator(sub, [ ]); + check_enumerator(sub, []); pm.add(sub, "test/getallforuri", pm.PROMPT_ACTION); pm.add(sub, "test/getallforuri2", pm.DENY_ACTION); check_enumerator(sub, [ - [ "test/getallforuri", pm.PROMPT_ACTION ], - [ "test/getallforuri2", pm.DENY_ACTION ] + ["test/getallforuri", pm.PROMPT_ACTION], + ["test/getallforuri2", pm.DENY_ACTION], ]); // check that the original uri list has not changed - check_enumerator(uri, [ - [ "test/getallforuri", pm.ALLOW_ACTION ] - ]); + check_enumerator(uri, [["test/getallforuri", pm.ALLOW_ACTION]]); // check that UNKNOWN_ACTION permissions are ignored pm.add(uri, "test/getallforuri2", pm.UNKNOWN_ACTION); pm.add(uri, "test/getallforuri3", pm.DENY_ACTION); check_enumerator(uri, [ - [ "test/getallforuri", pm.ALLOW_ACTION ], - [ "test/getallforuri3", pm.DENY_ACTION ] + ["test/getallforuri", pm.ALLOW_ACTION], + ["test/getallforuri3", pm.DENY_ACTION], ]); // check that permission updates are reflected pm.add(uri, "test/getallforuri", pm.PROMPT_ACTION); check_enumerator(uri, [ - [ "test/getallforuri", pm.PROMPT_ACTION ], - [ "test/getallforuri3", pm.DENY_ACTION ] + ["test/getallforuri", pm.PROMPT_ACTION], + ["test/getallforuri3", pm.DENY_ACTION], ]); // check that permission removals are reflected pm.remove(uri, "test/getallforuri"); - check_enumerator(uri, [ - [ "test/getallforuri3", pm.DENY_ACTION ] - ]); + check_enumerator(uri, [["test/getallforuri3", pm.DENY_ACTION]]); pm.removeAll(); - check_enumerator(uri, [ ]); - check_enumerator(sub, [ ]); + check_enumerator(uri, []); + check_enumerator(sub, []); } - diff --git a/extensions/permissions/test/unit/test_permmanager_getAllWithTypePrefix.js b/extensions/permissions/test/unit/test_permmanager_getAllWithTypePrefix.js index 62a629c8f0b1..27abb9fc2b1b 100644 --- a/extensions/permissions/test/unit/test_permmanager_getAllWithTypePrefix.js +++ b/extensions/permissions/test/unit/test_permmanager_getAllWithTypePrefix.js @@ -2,8 +2,9 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function check_enumerator(prefix, permissions) { - let pm = Cc["@mozilla.org/permissionmanager;1"] - .getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); let array = pm.getAllWithTypePrefix(prefix); for (let [uri, type, capability] of permissions) { @@ -18,52 +19,52 @@ function check_enumerator(prefix, permissions) { } function run_test() { - let pm = Cc["@mozilla.org/permissionmanager;1"] - .getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); let uri = NetUtil.newURI("http://example.com"); let sub = NetUtil.newURI("http://sub.example.com"); - check_enumerator("test/", [ ]); + check_enumerator("test/", []); pm.add(uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION); pm.add(sub, "other-test/getallwithtypeprefix", pm.PROMPT_ACTION); check_enumerator("test/", [ - [ uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION ], + [uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION], ]); pm.add(sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION); check_enumerator("test/", [ - [ sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION ], - [ uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION ], + [sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION], + [uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION], ]); check_enumerator("test/getallwithtypeprefix", [ - [ sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION ], - [ uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION ], + [sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION], + [uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION], ]); // check that UNKNOWN_ACTION permissions are ignored pm.add(uri, "test/getallwithtypeprefix2", pm.UNKNOWN_ACTION); check_enumerator("test/", [ - [ sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION ], - [ uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION ], + [sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION], + [uri, "test/getallwithtypeprefix", pm.ALLOW_ACTION], ]); // check that permission updates are reflected pm.add(uri, "test/getallwithtypeprefix", pm.PROMPT_ACTION); check_enumerator("test/", [ - [ sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION ], - [ uri, "test/getallwithtypeprefix", pm.PROMPT_ACTION ], + [sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION], + [uri, "test/getallwithtypeprefix", pm.PROMPT_ACTION], ]); // check that permission removals are reflected pm.remove(uri, "test/getallwithtypeprefix"); check_enumerator("test/", [ - [ sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION ], + [sub, "test/getallwithtypeprefix", pm.PROMPT_ACTION], ]); pm.removeAll(); - check_enumerator("test/", [ ]); + check_enumerator("test/", []); } - diff --git a/extensions/permissions/test/unit/test_permmanager_getPermissionObject.js b/extensions/permissions/test/unit/test_permmanager_getPermissionObject.js index b3cf20591aa7..b3ea8cf1bf83 100644 --- a/extensions/permissions/test/unit/test_permmanager_getPermissionObject.js +++ b/extensions/permissions/test/unit/test_permmanager_getPermissionObject.js @@ -2,23 +2,28 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function getPrincipalFromURI(aURI) { - let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); let uri = NetUtil.newURI(aURI); return ssm.createCodebasePrincipal(uri, {}); } function getSystemPrincipal() { return Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager) - .getSystemPrincipal(); + .getService(Ci.nsIScriptSecurityManager) + .getSystemPrincipal(); } function run_test() { - var pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + var pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); - Assert.equal(null, pm.getPermissionObject(getSystemPrincipal(), "test/pobject", false)); + Assert.equal( + null, + pm.getPermissionObject(getSystemPrincipal(), "test/pobject", false) + ); let principal = getPrincipalFromURI("http://example.com"); let subPrincipal = getPrincipalFromURI("http://sub.example.com"); @@ -53,7 +58,12 @@ function run_test() { Assert.ok(subPerm != null); Assert.equal(subPerm.principal.origin, "http://example.com"); - pm.addFromPrincipal(principal, "test/pobject", pm.DENY_ACTION, pm.EXPIRE_SESSION); + pm.addFromPrincipal( + principal, + "test/pobject", + pm.DENY_ACTION, + pm.EXPIRE_SESSION + ); // make sure permission objects are not dynamic Assert.equal(rootPerm.capability, pm.ALLOW_ACTION); diff --git a/extensions/permissions/test/unit/test_permmanager_idn.js b/extensions/permissions/test/unit/test_permmanager_idn.js index b9dc3d6384f3..ae4a7b3411cf 100644 --- a/extensions/permissions/test/unit/test_permmanager_idn.js +++ b/extensions/permissions/test/unit/test_permmanager_idn.js @@ -2,8 +2,9 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function getPrincipalFromDomain(aDomain) { - let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); let uri = NetUtil.newURI("http://" + aDomain); return ssm.createCodebasePrincipal(uri, {}); } @@ -11,7 +12,7 @@ function getPrincipalFromDomain(aDomain) { function run_test() { let profile = do_get_profile(); let pm = Services.perms; - let perm = 'test-idn'; + let perm = "test-idn"; // We create three principal linked to IDN. // One with just a domain, one with a subdomain and one with the TLD @@ -26,24 +27,52 @@ function run_test() { pm.addFromPrincipal(tldPrincipal, perm, pm.ALLOW_ACTION, 0, 0); // They should obviously be there now.. - Assert.equal(pm.testPermissionFromPrincipal(mainDomainPrincipal, perm), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(subDomainPrincipal, perm), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(tldPrincipal, perm), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(mainDomainPrincipal, perm), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(subDomainPrincipal, perm), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(tldPrincipal, perm), + pm.ALLOW_ACTION + ); // We do the same thing with the puny-encoded versions of the IDN. - let punyMainDomainPrincipal = getPrincipalFromDomain('xn--f-xgav.com'); - let punySubDomainPrincipal = getPrincipalFromDomain('xn--f-xgaa.xn--br-jia.com'); - let punyTldPrincipal = getPrincipalFromDomain('xn--f-xgav.xn--br-jia.xn--cm-8ja'); + let punyMainDomainPrincipal = getPrincipalFromDomain("xn--f-xgav.com"); + let punySubDomainPrincipal = getPrincipalFromDomain( + "xn--f-xgaa.xn--br-jia.com" + ); + let punyTldPrincipal = getPrincipalFromDomain( + "xn--f-xgav.xn--br-jia.xn--cm-8ja" + ); // Those principals should have the permission granted too. - Assert.equal(pm.testPermissionFromPrincipal(punyMainDomainPrincipal, perm), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(punySubDomainPrincipal, perm), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(punyTldPrincipal, perm), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(punyMainDomainPrincipal, perm), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(punySubDomainPrincipal, perm), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(punyTldPrincipal, perm), + pm.ALLOW_ACTION + ); // However, those two principals shouldn't be allowed because they are like // the IDN but without the UT8-8 characters. let witnessPrincipal = getPrincipalFromDomain("foo.com"); - Assert.equal(pm.testPermissionFromPrincipal(witnessPrincipal, perm), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(witnessPrincipal, perm), + pm.UNKNOWN_ACTION + ); witnessPrincipal = getPrincipalFromDomain("foo.bar.com"); - Assert.equal(pm.testPermissionFromPrincipal(witnessPrincipal, perm), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(witnessPrincipal, perm), + pm.UNKNOWN_ACTION + ); } diff --git a/extensions/permissions/test/unit/test_permmanager_load_invalid_entries.js b/extensions/permissions/test/unit/test_permmanager_load_invalid_entries.js index afcdaf9a5730..07de107693e1 100644 --- a/extensions/permissions/test/unit/test_permmanager_load_invalid_entries.js +++ b/extensions/permissions/test/unit/test_permmanager_load_invalid_entries.js @@ -10,8 +10,9 @@ function run_test() { var file = dir.clone(); file.append("permissions.sqlite"); - var storage = Cc["@mozilla.org/storage/service;1"] - .getService(Ci.mozIStorageService); + var storage = Cc["@mozilla.org/storage/service;1"].getService( + Ci.mozIStorageService + ); // Create database. var connection = storage.openDatabase(file); @@ -19,8 +20,7 @@ function run_test() { Assert.ok(file.exists()); connection.schemaVersion = 3; - connection.executeSimpleSQL( - "DROP TABLE moz_hosts"); + connection.executeSimpleSQL("DROP TABLE moz_hosts"); connection.executeSimpleSQL( "CREATE TABLE moz_hosts (" + " id INTEGER PRIMARY KEY" + @@ -31,82 +31,192 @@ function run_test() { ",expireTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); // Now we can inject garbadge in the database. var garbadge = [ // Regular entry. - { host: '42', type: '0', permission: 1, expireType: 0, expireTime: 0, - isInBrowserElement: 0 }, + { + host: "42", + type: "0", + permission: 1, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, // Special values in host (some being invalid). - { host: 'scheme:file', type: '1', permission: 0, expireType: 0, - expireTime: 0, isInBrowserElement: 0 }, - { host: '192.168.0.1', type: '2', permission: 0, expireType: 0, - expireTime: 0, isInBrowserElement: 0 }, - { host: '2001:0db8:0000:0000:0000:ff00:0042:8329', type: '3', permission: 0, - expireType: 0, expireTime: 0, isInBrowserElement: 0 }, - { host: '::1', type: '4', permission: 0, expireType: 0, expireTime: 0, - isInBrowserElement: 0 }, + { + host: "scheme:file", + type: "1", + permission: 0, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, + { + host: "192.168.0.1", + type: "2", + permission: 0, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, + { + host: "2001:0db8:0000:0000:0000:ff00:0042:8329", + type: "3", + permission: 0, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, + { + host: "::1", + type: "4", + permission: 0, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, // Permission is UNKNOWN_ACTION. - { host: '42', type: '5', permission: Ci.nsIPermissionManager.UNKNOWN_ACTION, - expireType: 0, expireTime: 0, isInBrowserElement: 0 }, + { + host: "42", + type: "5", + permission: Ci.nsIPermissionManager.UNKNOWN_ACTION, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, // Permission is out of range. - { host: '42', type: '6', permission: 100, expireType: 0, expireTime: 0, - isInBrowserElement: 0 }, - { host: '42', type: '7', permission: -100, expireType: 0, expireTime: 0, - isInBrowserElement: 0 }, + { + host: "42", + type: "6", + permission: 100, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, + { + host: "42", + type: "7", + permission: -100, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, // ExpireType is out of range. - { host: '42', type: '8', permission: 1, expireType: -100, expireTime: 0, - isInBrowserElement: 0 }, - { host: '42', type: '9', permission: 1, expireType: 100, expireTime: 0, - isInBrowserElement: 0 }, + { + host: "42", + type: "8", + permission: 1, + expireType: -100, + expireTime: 0, + isInBrowserElement: 0, + }, + { + host: "42", + type: "9", + permission: 1, + expireType: 100, + expireTime: 0, + isInBrowserElement: 0, + }, // ExpireTime is at 0 with ExpireType = Time. - { host: '42', type: '10', permission: 1, - expireType: Ci.nsIPermissionManager.EXPIRE_TIME, expireTime: 0, - isInBrowserElement: 0 }, + { + host: "42", + type: "10", + permission: 1, + expireType: Ci.nsIPermissionManager.EXPIRE_TIME, + expireTime: 0, + isInBrowserElement: 0, + }, // ExpireTime has a value with ExpireType != Time - { host: '42', type: '11', permission: 1, - expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, expireTime: 1000, - isInBrowserElement: 0 }, - { host: '42', type: '12', permission: 1, - expireType: Ci.nsIPermissionManager.EXPIRE_NEVER, expireTime: 1000, - isInBrowserElement: 0 }, + { + host: "42", + type: "11", + permission: 1, + expireType: Ci.nsIPermissionManager.EXPIRE_SESSION, + expireTime: 1000, + isInBrowserElement: 0, + }, + { + host: "42", + type: "12", + permission: 1, + expireType: Ci.nsIPermissionManager.EXPIRE_NEVER, + expireTime: 1000, + isInBrowserElement: 0, + }, // ExpireTime is negative. - { host: '42', type: '13', permission: 1, - expireType: Ci.nsIPermissionManager.EXPIRE_TIME, expireTime: -1, - isInBrowserElement: 0 }, + { + host: "42", + type: "13", + permission: 1, + expireType: Ci.nsIPermissionManager.EXPIRE_TIME, + expireTime: -1, + isInBrowserElement: 0, + }, // IsInBrowserElement is negative or higher than 1. - { host: '42', type: '15', permission: 1, expireType: 0, expireTime: 0, - isInBrowserElement: -1 }, - { host: '42', type: '16', permission: 1, expireType: 0, expireTime: 0, - isInBrowserElement: 10 }, + { + host: "42", + type: "15", + permission: 1, + expireType: 0, + expireTime: 0, + isInBrowserElement: -1, + }, + { + host: "42", + type: "16", + permission: 1, + expireType: 0, + expireTime: 0, + isInBrowserElement: 10, + }, // This insertion should be the last one. It is used to make sure we always // load it regardless of the previous entries validities. - { host: 'example.org', type: 'test-load-invalid-entries', - permission: Ci.nsIPermissionManager.ALLOW_ACTION, expireType: 0, - expireTime: 0, isInBrowserElement: 0 }, + { + host: "example.org", + type: "test-load-invalid-entries", + permission: Ci.nsIPermissionManager.ALLOW_ACTION, + expireType: 0, + expireTime: 0, + isInBrowserElement: 0, + }, ]; - for (var i=0; i 0, "we found at least 1 record that was migrated"); // This permission should always be there. - let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); let uri = NetUtil.newURI("http://example.org"); let principal = ssm.createCodebasePrincipal(uri, {}); - Assert.equal(pm.testPermissionFromPrincipal(principal, 'test-load-invalid-entries'), Ci.nsIPermissionManager.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(principal, "test-load-invalid-entries"), + Ci.nsIPermissionManager.ALLOW_ACTION + ); } diff --git a/extensions/permissions/test/unit/test_permmanager_local_files.js b/extensions/permissions/test/unit/test_permmanager_local_files.js index feb0c52a9945..58e276b097ba 100644 --- a/extensions/permissions/test/unit/test_permmanager_local_files.js +++ b/extensions/permissions/test/unit/test_permmanager_local_files.js @@ -3,8 +3,7 @@ // Test that permissions work for file:// URIs (aka local files). -function getPrincipalFromURIString(uriStr) -{ +function getPrincipalFromURIString(uriStr) { let uri = NetUtil.newURI(uriStr); return Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); } @@ -15,29 +14,61 @@ function run_test() { // If we add a permission to a file:// URI, the test should return true. let principal = getPrincipalFromURIString("file:///foo/bar"); pm.addFromPrincipal(principal, "test/local-files", pm.ALLOW_ACTION, 0, 0); - Assert.equal(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(principal, "test/local-files"), + pm.ALLOW_ACTION + ); // Another file:// URI should have the same permission. let witnessPrincipal = getPrincipalFromURIString("file:///bar/foo"); - Assert.equal(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), + pm.UNKNOWN_ACTION + ); // Giving "file:///" a permission shouldn't give it to all file:// URIs. let rootPrincipal = getPrincipalFromURIString("file:///"); pm.addFromPrincipal(rootPrincipal, "test/local-files", pm.ALLOW_ACTION, 0, 0); - Assert.equal(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), + pm.UNKNOWN_ACTION + ); // Giving "file://" a permission shouldn't give it to all file:// URIs. let schemeRootPrincipal = getPrincipalFromURIString("file://"); - pm.addFromPrincipal(schemeRootPrincipal, "test/local-files", pm.ALLOW_ACTION, 0, 0); - Assert.equal(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); + pm.addFromPrincipal( + schemeRootPrincipal, + "test/local-files", + pm.ALLOW_ACTION, + 0, + 0 + ); + Assert.equal( + pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), + pm.UNKNOWN_ACTION + ); // Giving 'node' a permission shouldn't give it to its 'children'. - let fileInDirPrincipal = getPrincipalFromURIString("file:///foo/bar/foobar.txt"); - Assert.equal(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); + let fileInDirPrincipal = getPrincipalFromURIString( + "file:///foo/bar/foobar.txt" + ); + Assert.equal( + pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), + pm.UNKNOWN_ACTION + ); // Revert "file:///foo/bar" permission and check that it has been correctly taken into account. pm.removeFromPrincipal(principal, "test/local-files"); - Assert.equal(pm.testPermissionFromPrincipal(principal, "test/local-files"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(principal, "test/local-files"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(witnessPrincipal, "test/local-files"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(fileInDirPrincipal, "test/local-files"), + pm.UNKNOWN_ACTION + ); } diff --git a/extensions/permissions/test/unit/test_permmanager_matches.js b/extensions/permissions/test/unit/test_permmanager_matches.js index 904754491323..32831d98d0d5 100644 --- a/extensions/permissions/test/unit/test_permmanager_matches.js +++ b/extensions/permissions/test/unit/test_permmanager_matches.js @@ -2,33 +2,53 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function matches_always(perm, principals) { - principals.forEach((principal) => { - Assert.ok(perm.matches(principal, true), "perm: " + perm.principal.origin + ", princ: " + principal.origin); - Assert.ok(perm.matches(principal, false), "perm: " + perm.principal.origin + ", princ: " + principal.origin); + principals.forEach(principal => { + Assert.ok( + perm.matches(principal, true), + "perm: " + perm.principal.origin + ", princ: " + principal.origin + ); + Assert.ok( + perm.matches(principal, false), + "perm: " + perm.principal.origin + ", princ: " + principal.origin + ); }); } function matches_weak(perm, principals) { - principals.forEach((principal) => { - Assert.ok(!perm.matches(principal, true), "perm: " + perm.principal.origin + ", princ: " + principal.origin); - Assert.ok(perm.matches(principal, false), "perm: " + perm.principal.origin + ", princ: " + principal.origin); + principals.forEach(principal => { + Assert.ok( + !perm.matches(principal, true), + "perm: " + perm.principal.origin + ", princ: " + principal.origin + ); + Assert.ok( + perm.matches(principal, false), + "perm: " + perm.principal.origin + ", princ: " + principal.origin + ); }); } function matches_never(perm, principals) { - principals.forEach((principal) => { - Assert.ok(!perm.matches(principal, true), "perm: " + perm.principal.origin + ", princ: " + principal.origin); - Assert.ok(!perm.matches(principal, false), "perm: " + perm.principal.origin + ", princ: " + principal.origin); + principals.forEach(principal => { + Assert.ok( + !perm.matches(principal, true), + "perm: " + perm.principal.origin + ", princ: " + principal.origin + ); + Assert.ok( + !perm.matches(principal, false), + "perm: " + perm.principal.origin + ", princ: " + principal.origin + ); }); } function run_test() { // initialize the permission manager service - let pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); - let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); // Add some permissions let uri0 = NetUtil.newURI("http://google.com/search?q=foo#hashtag"); @@ -45,7 +65,7 @@ function run_test() { let uri4_n = secMan.createCodebasePrincipal(uri4, {}); let uri5_n = secMan.createCodebasePrincipal(uri5, {}); - attrs = {inIsolatedMozBrowser: true}; + attrs = { inIsolatedMozBrowser: true }; let uri0_y_ = secMan.createCodebasePrincipal(uri0, attrs); let uri1_y_ = secMan.createCodebasePrincipal(uri1, attrs); let uri2_y_ = secMan.createCodebasePrincipal(uri2, attrs); @@ -53,7 +73,7 @@ function run_test() { let uri4_y_ = secMan.createCodebasePrincipal(uri4, attrs); let uri5_y_ = secMan.createCodebasePrincipal(uri5, attrs); - attrs = {userContextId: 1}; + attrs = { userContextId: 1 }; let uri0_1 = secMan.createCodebasePrincipal(uri0, attrs); let uri1_1 = secMan.createCodebasePrincipal(uri1, attrs); let uri2_1 = secMan.createCodebasePrincipal(uri2, attrs); @@ -61,7 +81,7 @@ function run_test() { let uri4_1 = secMan.createCodebasePrincipal(uri4, attrs); let uri5_1 = secMan.createCodebasePrincipal(uri5, attrs); - attrs = {firstPartyDomain: "cnn.com"}; + attrs = { firstPartyDomain: "cnn.com" }; let uri0_cnn = secMan.createCodebasePrincipal(uri0, attrs); let uri1_cnn = secMan.createCodebasePrincipal(uri1, attrs); let uri2_cnn = secMan.createCodebasePrincipal(uri2, attrs); @@ -80,31 +100,105 @@ function run_test() { matches_always(perm_n, [uri0_n, uri0_1]); matches_weak(perm_n, [uri1_n, uri1_1]); - matches_never(perm_n, [uri2_n, uri3_n, uri4_n, uri5_n, - uri0_y_, uri1_y_, uri2_y_, uri3_y_, uri4_y_, uri5_y_, - uri2_1, uri3_1, uri4_1, uri5_1, - uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]); + matches_never(perm_n, [ + uri2_n, + uri3_n, + uri4_n, + uri5_n, + uri0_y_, + uri1_y_, + uri2_y_, + uri3_y_, + uri4_y_, + uri5_y_, + uri2_1, + uri3_1, + uri4_1, + uri5_1, + uri0_cnn, + uri1_cnn, + uri2_cnn, + uri3_cnn, + uri4_cnn, + uri5_cnn, + ]); matches_always(perm_y_, [uri0_y_]); matches_weak(perm_y_, [uri1_y_]); - matches_never(perm_y_, [uri2_y_, uri3_y_, uri4_y_, uri5_y_, - uri0_n, uri1_n, uri2_n, uri3_n, uri4_n, uri5_n, - uri0_1, uri1_1, uri2_1, uri3_1, uri4_1, uri5_1, - uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]); + matches_never(perm_y_, [ + uri2_y_, + uri3_y_, + uri4_y_, + uri5_y_, + uri0_n, + uri1_n, + uri2_n, + uri3_n, + uri4_n, + uri5_n, + uri0_1, + uri1_1, + uri2_1, + uri3_1, + uri4_1, + uri5_1, + uri0_cnn, + uri1_cnn, + uri2_cnn, + uri3_cnn, + uri4_cnn, + uri5_cnn, + ]); matches_always(perm_1, [uri0_n, uri0_1]); matches_weak(perm_1, [uri1_n, uri1_1]); - matches_never(perm_1, [uri2_n, uri3_n, uri4_n, uri5_n, - uri0_y_, uri1_y_, uri2_y_, uri3_y_, uri4_y_, uri5_y_, - uri2_1, uri3_1, uri4_1, uri5_1, - uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]); + matches_never(perm_1, [ + uri2_n, + uri3_n, + uri4_n, + uri5_n, + uri0_y_, + uri1_y_, + uri2_y_, + uri3_y_, + uri4_y_, + uri5_y_, + uri2_1, + uri3_1, + uri4_1, + uri5_1, + uri0_cnn, + uri1_cnn, + uri2_cnn, + uri3_cnn, + uri4_cnn, + uri5_cnn, + ]); matches_always(perm_cnn, [uri0_n, uri0_1]); matches_weak(perm_cnn, [uri1_n, uri1_1]); - matches_never(perm_cnn, [uri2_n, uri3_n, uri4_n, uri5_n, - uri0_y_, uri1_y_, uri2_y_, uri3_y_, uri4_y_, uri5_y_, - uri2_1, uri3_1, uri4_1, uri5_1, - uri0_cnn, uri1_cnn, uri2_cnn, uri3_cnn, uri4_cnn, uri5_cnn]); + matches_never(perm_cnn, [ + uri2_n, + uri3_n, + uri4_n, + uri5_n, + uri0_y_, + uri1_y_, + uri2_y_, + uri3_y_, + uri4_y_, + uri5_y_, + uri2_1, + uri3_1, + uri4_1, + uri5_1, + uri0_cnn, + uri1_cnn, + uri2_cnn, + uri3_cnn, + uri4_cnn, + uri5_cnn, + ]); // Clean up! pm.removeAll(); diff --git a/extensions/permissions/test/unit/test_permmanager_matchesuri.js b/extensions/permissions/test/unit/test_permmanager_matchesuri.js index be60510a59d1..335c50b2c9db 100644 --- a/extensions/permissions/test/unit/test_permmanager_matchesuri.js +++ b/extensions/permissions/test/unit/test_permmanager_matchesuri.js @@ -2,32 +2,52 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function matches_always(perm, uris) { - uris.forEach((uri) => { - Assert.ok(perm.matchesURI(uri, true), "perm: " + perm.principal.origin + ", URI: " + uri.spec); - Assert.ok(perm.matchesURI(uri, false), "perm: " + perm.principal.origin + ", URI: " + uri.spec); + uris.forEach(uri => { + Assert.ok( + perm.matchesURI(uri, true), + "perm: " + perm.principal.origin + ", URI: " + uri.spec + ); + Assert.ok( + perm.matchesURI(uri, false), + "perm: " + perm.principal.origin + ", URI: " + uri.spec + ); }); } function matches_weak(perm, uris) { - uris.forEach((uri) => { - Assert.ok(!perm.matchesURI(uri, true), "perm: " + perm.principal.origin + ", URI: " + uri.spec); - Assert.ok(perm.matchesURI(uri, false), "perm: " + perm.principal.origin + ", URI: " + uri.spec); + uris.forEach(uri => { + Assert.ok( + !perm.matchesURI(uri, true), + "perm: " + perm.principal.origin + ", URI: " + uri.spec + ); + Assert.ok( + perm.matchesURI(uri, false), + "perm: " + perm.principal.origin + ", URI: " + uri.spec + ); }); } function matches_never(perm, uris) { - uris.forEach((uri) => { - Assert.ok(!perm.matchesURI(uri, true), "perm: " + perm.principal.origin + ", URI: " + uri.spec); - Assert.ok(!perm.matchesURI(uri, false), "perm: " + perm.principal.origin + ", URI: " + uri.spec); + uris.forEach(uri => { + Assert.ok( + !perm.matchesURI(uri, true), + "perm: " + perm.principal.origin + ", URI: " + uri.spec + ); + Assert.ok( + !perm.matchesURI(uri, false), + "perm: " + perm.principal.origin + ", URI: " + uri.spec + ); }); } function mk_permission(uri) { - let pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); - let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); // Get the permission from the principal! let principal = secMan.createCodebasePrincipal(uri, {}); @@ -40,11 +60,13 @@ function mk_permission(uri) { function run_test() { // initialize the permission manager service - let pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); - let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); let fileprefix = "file:///"; if (Services.appinfo.OS == "WINNT") { @@ -77,7 +99,17 @@ function run_test() { let perm = mk_permission(uri1); matches_always(perm, [uri1]); matches_weak(perm, [uri4]); - matches_never(perm, [uri0, uri2, uri3, uri5, uri6, uri7, fileuri1, fileuri2, fileuri3]); + matches_never(perm, [ + uri0, + uri2, + uri3, + uri5, + uri6, + uri7, + fileuri1, + fileuri2, + fileuri3, + ]); } { @@ -91,56 +123,138 @@ function run_test() { let perm = mk_permission(uri3); matches_always(perm, [uri3]); matches_weak(perm, []); - matches_never(perm, [uri1, uri2, uri4, uri5, uri6, uri7, fileuri1, fileuri2, fileuri3]); + matches_never(perm, [ + uri1, + uri2, + uri4, + uri5, + uri6, + uri7, + fileuri1, + fileuri2, + fileuri3, + ]); } { let perm = mk_permission(uri4); matches_always(perm, [uri4]); matches_weak(perm, []); - matches_never(perm, [uri1, uri2, uri3, uri5, uri6, uri7, fileuri1, fileuri2, fileuri3]); + matches_never(perm, [ + uri1, + uri2, + uri3, + uri5, + uri6, + uri7, + fileuri1, + fileuri2, + fileuri3, + ]); } { let perm = mk_permission(uri5); matches_always(perm, [uri5, uri7]); matches_weak(perm, [uri6]); - matches_never(perm, [uri0, uri1, uri2, uri3, uri4, fileuri1, fileuri2, fileuri3]); + matches_never(perm, [ + uri0, + uri1, + uri2, + uri3, + uri4, + fileuri1, + fileuri2, + fileuri3, + ]); } { let perm = mk_permission(uri6); matches_always(perm, [uri6]); matches_weak(perm, []); - matches_never(perm, [uri0, uri1, uri2, uri3, uri4, uri5, uri7, fileuri1, fileuri2, fileuri3]); + matches_never(perm, [ + uri0, + uri1, + uri2, + uri3, + uri4, + uri5, + uri7, + fileuri1, + fileuri2, + fileuri3, + ]); } { let perm = mk_permission(uri7); matches_always(perm, [uri5, uri7]); matches_weak(perm, [uri6]); - matches_never(perm, [uri0, uri1, uri2, uri3, uri4, fileuri1, fileuri2, fileuri3]); + matches_never(perm, [ + uri0, + uri1, + uri2, + uri3, + uri4, + fileuri1, + fileuri2, + fileuri3, + ]); } { let perm = mk_permission(fileuri1); matches_always(perm, [fileuri1]); matches_weak(perm, []); - matches_never(perm, [uri0, uri1, uri2, uri3, uri4, uri5, uri6, uri7, fileuri2, fileuri3]); + matches_never(perm, [ + uri0, + uri1, + uri2, + uri3, + uri4, + uri5, + uri6, + uri7, + fileuri2, + fileuri3, + ]); } { let perm = mk_permission(fileuri2); matches_always(perm, [fileuri2]); matches_weak(perm, []); - matches_never(perm, [uri0, uri1, uri2, uri3, uri4, uri5, uri6, uri7, fileuri1, fileuri3]); + matches_never(perm, [ + uri0, + uri1, + uri2, + uri3, + uri4, + uri5, + uri6, + uri7, + fileuri1, + fileuri3, + ]); } { let perm = mk_permission(fileuri3); matches_always(perm, [fileuri3]); matches_weak(perm, []); - matches_never(perm, [uri0, uri1, uri2, uri3, uri4, uri5, uri6, uri7, fileuri1, fileuri2]); + matches_never(perm, [ + uri0, + uri1, + uri2, + uri3, + uri4, + uri5, + uri6, + uri7, + fileuri1, + fileuri2, + ]); } // Clean up! diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_4-7.js b/extensions/permissions/test/unit/test_permmanager_migrate_4-7.js index 542d12de9c86..324387483cce 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_4-7.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_4-7.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -34,18 +36,29 @@ add_task(async function test() { ",modificationTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); let stmtInsert = db.createStatement( "INSERT INTO moz_hosts (" + "id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" + - ") VALUES (" + + ") VALUES (" + ":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" + - ")"); + ")" + ); let id = 0; - function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) { + function insertHost( + host, + type, + permission, + expireType, + expireTime, + modificationTime, + appId, + isInBrowserElement + ) { let thisId = id++; stmtInsert.bindByName("id", thisId); @@ -73,7 +86,7 @@ add_task(async function test() { expireTime, modificationTime, appId, - isInBrowserElement + isInBrowserElement, }; } @@ -93,8 +106,26 @@ add_task(async function test() { insertHost("192.0.2.235", "A", 1, 0, 0, 0, 0, false), insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false), insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false), + insertHost( + "moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", + "A", + 1, + 0, + 0, + 0, + 0, + false + ), + insertHost( + "moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", + "B", + 1, + 0, + 0, + 0, + 0, + false + ), insertHost("", "A", 1, 0, 0, 0, 0, false), insertHost("", "B", 1, 0, 0, 0, 0, false), ]; @@ -150,11 +181,15 @@ add_task(async function test() { ["https://192.0.2.235", "A", 1, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // Add some places to the places database - await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory")); - await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory")); + await PlacesTestUtils.addVisits( + Services.io.newURI("https://foo.com/some/other/subdirectory") + ); + await PlacesTestUtils.addVisits( + Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory") + ); // This will force the permission-manager to reload the data. Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); @@ -164,28 +199,43 @@ add_task(async function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_4-7_no_history.js b/extensions/permissions/test/unit/test_permmanager_migrate_4-7_no_history.js index 043a8a66f042..38e721d4602f 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_4-7_no_history.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_4-7_no_history.js @@ -15,14 +15,19 @@ var factory = { lockFactory() { throw Cr.NS_ERROR_NOT_IMPLEMENTED; }, - QueryInterface: ChromeUtils.generateQI([Ci.nsIFactory]) + QueryInterface: ChromeUtils.generateQI([Ci.nsIFactory]), }; -var newClassID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID(); +var newClassID = Cc["@mozilla.org/uuid-generator;1"] + .getService(Ci.nsIUUIDGenerator) + .generateUUID(); var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); var oldClassID = registrar.contractIDToCID(CONTRACT_ID); -var oldFactory = Components.manager.getClassObject(Cc[CONTRACT_ID], Ci.nsIFactory); +var oldFactory = Components.manager.getClassObject( + Cc[CONTRACT_ID], + Ci.nsIFactory +); registrar.registerFactory(newClassID, "", CONTRACT_ID, factory); function cleanupFactory() { @@ -30,8 +35,7 @@ function cleanupFactory() { registrar.registerFactory(oldClassID, "", CONTRACT_ID, null); } -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -48,7 +52,9 @@ add_task(function test() { // Make sure that we can't resolve the nsINavHistoryService try { - Cc['@mozilla.org/browser/nav-history-service;1'].getService(Ci.nsINavHistoryService); + Cc["@mozilla.org/browser/nav-history-service;1"].getService( + Ci.nsINavHistoryService + ); Assert.ok(false, "There shouldn't have been a nsINavHistoryService"); } catch (e) { Assert.ok(true, "There wasn't a nsINavHistoryService"); @@ -70,18 +76,29 @@ add_task(function test() { ",modificationTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); let stmtInsert = db.createStatement( "INSERT INTO moz_hosts (" + "id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" + - ") VALUES (" + + ") VALUES (" + ":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" + - ")"); + ")" + ); let id = 0; - function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) { + function insertHost( + host, + type, + permission, + expireType, + expireTime, + modificationTime, + appId, + isInBrowserElement + ) { let thisId = id++; stmtInsert.bindByName("id", thisId); @@ -109,7 +126,7 @@ add_task(function test() { expireTime, modificationTime, appId, - isInBrowserElement + isInBrowserElement, }; } @@ -129,8 +146,26 @@ add_task(function test() { insertHost("263.123.555.676", "A", 1, 0, 0, 0, 0, false), insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false), insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false), + insertHost( + "moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", + "A", + 1, + 0, + 0, + 0, + 0, + false + ), + insertHost( + "moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", + "B", + 1, + 0, + 0, + 0, + 0, + false + ), insertHost("", "A", 1, 0, 0, 0, 0, false), insertHost("", "B", 1, 0, 0, 0, 0, false), ]; @@ -171,7 +206,7 @@ add_task(function test() { ["https://263.123.555.676", "A", 1, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // This will force the permission-manager to reload the data. Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); @@ -181,28 +216,43 @@ add_task(function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_5-7a.js b/extensions/permissions/test/unit/test_permmanager_migrate_5-7a.js index 271df58fae7f..fdcf739e575f 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_5-7a.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_5-7a.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -35,14 +37,16 @@ add_task(async function test() { ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + - ")"); + ")" + ); let stmt5Insert = db.createStatement( "INSERT INTO moz_hosts (" + "id, origin, type, permission, expireType, expireTime, modificationTime" + - ") VALUES (" + + ") VALUES (" + ":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" + - ")"); + ")" + ); /* * V4 table @@ -58,18 +62,27 @@ add_task(async function test() { ",modificationTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); let stmtInsert = db.createStatement( "INSERT INTO moz_hosts_v4 (" + "id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" + - ") VALUES (" + + ") VALUES (" + ":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" + - ")"); + ")" + ); let id = 0; - function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) { + function insertOrigin( + origin, + type, + permission, + expireType, + expireTime, + modificationTime + ) { let thisId = id++; stmt5Insert.bindByName("id", thisId); @@ -93,11 +106,20 @@ add_task(async function test() { permission, expireType, expireTime, - modificationTime + modificationTime, }; } - function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) { + function insertHost( + host, + type, + permission, + expireType, + expireTime, + modificationTime, + appId, + isInBrowserElement + ) { let thisId = id++; stmtInsert.bindByName("id", thisId); @@ -125,7 +147,7 @@ add_task(async function test() { expireTime, modificationTime, appId, - isInBrowserElement + isInBrowserElement, }; } @@ -151,8 +173,26 @@ add_task(async function test() { insertHost("192.0.2.235", "A", 1, 0, 0, 0, 0, false), insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false), insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false), + insertHost( + "moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", + "A", + 1, + 0, + 0, + 0, + 0, + false + ), + insertHost( + "moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", + "B", + 1, + 0, + 0, + 0, + 0, + false + ), insertHost("", "A", 1, 0, 0, 0, 0, false), insertHost("", "B", 1, 0, 0, 0, 0, false), ]; @@ -209,11 +249,15 @@ add_task(async function test() { ["https://192.0.2.235", "A", 1, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // Add some places to the places database - await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory")); - await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory")); + await PlacesTestUtils.addVisits( + Services.io.newURI("https://foo.com/some/other/subdirectory") + ); + await PlacesTestUtils.addVisits( + Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory") + ); // This will force the permission-manager to reload the data. Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); @@ -223,28 +267,43 @@ add_task(async function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present @@ -265,12 +324,14 @@ add_task(async function test() { } // Check that the moz_perms_v6 table contains the backup of the entry we created - let mozPermsV6Stmt = db.createStatement("SELECT " + - "origin, type, permission, expireType, expireTime, modificationTime " + - "FROM moz_perms_v6 WHERE id = :id"); + let mozPermsV6Stmt = db.createStatement( + "SELECT " + + "origin, type, permission, expireType, expireTime, modificationTime " + + "FROM moz_perms_v6 WHERE id = :id" + ); try { // Check that the moz_hosts table still contains the correct values. - created5.forEach((it) => { + created5.forEach(it => { mozPermsV6Stmt.reset(); mozPermsV6Stmt.bindByName("id", it.id); mozPermsV6Stmt.executeStep(); @@ -286,7 +347,9 @@ add_task(async function test() { } // Check that there are the right number of values - let mozPermsV6Count = db.createStatement("SELECT count(*) FROM moz_perms_v6"); + let mozPermsV6Count = db.createStatement( + "SELECT count(*) FROM moz_perms_v6" + ); try { mozPermsV6Count.executeStep(); Assert.equal(mozPermsV6Count.getInt64(0), created5.length); diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_5-7b.js b/extensions/permissions/test/unit/test_permmanager_migrate_5-7b.js index c1438d84014d..c34a4112616c 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_5-7b.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_5-7b.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -35,18 +37,27 @@ add_task(function test() { ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + - ")"); + ")" + ); let stmt5Insert = db.createStatement( "INSERT INTO moz_hosts (" + "id, origin, type, permission, expireType, expireTime, modificationTime" + - ") VALUES (" + + ") VALUES (" + ":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" + - ")"); + ")" + ); let id = 0; - function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) { + function insertOrigin( + origin, + type, + permission, + expireType, + expireTime, + modificationTime + ) { let thisId = id++; stmt5Insert.bindByName("id", thisId); @@ -70,7 +81,7 @@ add_task(function test() { permission, expireType, expireTime, - modificationTime + modificationTime, }; } @@ -100,7 +111,7 @@ add_task(function test() { ["http://localhost", "B", 2, 0, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // This will force the permission-manager to reload the data. Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); @@ -110,28 +121,43 @@ add_task(function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present @@ -142,13 +168,15 @@ add_task(function test() { Assert.ok(!db.tableExists("moz_hosts_is_backup")); Assert.ok(!db.tableExists("moz_perms_v6")); - let mozHostsStmt = db.createStatement("SELECT " + - "host, type, permission, expireType, expireTime, " + - "modificationTime, isInBrowserElement " + - "FROM moz_hosts WHERE id = :id"); + let mozHostsStmt = db.createStatement( + "SELECT " + + "host, type, permission, expireType, expireTime, " + + "modificationTime, isInBrowserElement " + + "FROM moz_hosts WHERE id = :id" + ); try { // Check that the moz_hosts table still contains the correct values. - created4.forEach((it) => { + created4.forEach(it => { mozHostsStmt.reset(); mozHostsStmt.bindByName("id", it.id); mozHostsStmt.executeStep(); diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_6-7a.js b/extensions/permissions/test/unit/test_permmanager_migrate_6-7a.js index 5c1f79eb937b..86341de487e6 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_6-7a.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_6-7a.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -35,14 +37,16 @@ add_task(async function test() { ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + - ")"); + ")" + ); let stmt6Insert = db.createStatement( "INSERT INTO moz_perms (" + "id, origin, type, permission, expireType, expireTime, modificationTime" + - ") VALUES (" + + ") VALUES (" + ":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" + - ")"); + ")" + ); /* * V4 table @@ -58,18 +62,27 @@ add_task(async function test() { ",modificationTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); let stmtInsert = db.createStatement( "INSERT INTO moz_hosts (" + "id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" + - ") VALUES (" + + ") VALUES (" + ":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" + - ")"); + ")" + ); let id = 0; - function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) { + function insertOrigin( + origin, + type, + permission, + expireType, + expireTime, + modificationTime + ) { let thisId = id++; stmt6Insert.bindByName("id", thisId); @@ -93,11 +106,20 @@ add_task(async function test() { permission, expireType, expireTime, - modificationTime + modificationTime, }; } - function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) { + function insertHost( + host, + type, + permission, + expireType, + expireTime, + modificationTime, + appId, + isInBrowserElement + ) { let thisId = id++; stmtInsert.bindByName("id", thisId); @@ -125,7 +147,7 @@ add_task(async function test() { expireTime, modificationTime, appId, - isInBrowserElement + isInBrowserElement, }; } @@ -151,8 +173,26 @@ add_task(async function test() { insertHost("192.0.2.235", "A", 1, 0, 0, 0, 0, false), insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false), insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false), + insertHost( + "moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", + "A", + 1, + 0, + 0, + 0, + 0, + false + ), + insertHost( + "moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", + "B", + 1, + 0, + 0, + 0, + 0, + false + ), insertHost("", "A", 1, 0, 0, 0, 0, false), insertHost("", "B", 1, 0, 0, 0, 0, false), ]; @@ -209,11 +249,15 @@ add_task(async function test() { ["https://192.0.2.235", "A", 1, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // Add some places to the places database - await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory")); - await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory")); + await PlacesTestUtils.addVisits( + Services.io.newURI("https://foo.com/some/other/subdirectory") + ); + await PlacesTestUtils.addVisits( + Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory") + ); // This will force the permission-manager to reload the data. Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); @@ -223,28 +267,43 @@ add_task(async function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present @@ -265,12 +324,14 @@ add_task(async function test() { } // Check that the moz_perms_v6 table contains the backup of the entry we created - let mozPermsV6Stmt = db.createStatement("SELECT " + - "origin, type, permission, expireType, expireTime, modificationTime " + - "FROM moz_perms_v6 WHERE id = :id"); + let mozPermsV6Stmt = db.createStatement( + "SELECT " + + "origin, type, permission, expireType, expireTime, modificationTime " + + "FROM moz_perms_v6 WHERE id = :id" + ); try { // Check that the moz_hosts table still contains the correct values. - created6.forEach((it) => { + created6.forEach(it => { mozPermsV6Stmt.reset(); mozPermsV6Stmt.bindByName("id", it.id); mozPermsV6Stmt.executeStep(); @@ -286,7 +347,9 @@ add_task(async function test() { } // Check that there are the right number of values - let mozPermsV6Count = db.createStatement("SELECT count(*) FROM moz_perms_v6"); + let mozPermsV6Count = db.createStatement( + "SELECT count(*) FROM moz_perms_v6" + ); try { mozPermsV6Count.executeStep(); Assert.equal(mozPermsV6Count.getInt64(0), created6.length); diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_6-7b.js b/extensions/permissions/test/unit/test_permmanager_migrate_6-7b.js index 4b7d034cc416..31b77d43dc7f 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_6-7b.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_6-7b.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -35,18 +37,27 @@ add_task(function test() { ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + - ")"); + ")" + ); let stmt6Insert = db.createStatement( "INSERT INTO moz_perms (" + "id, origin, type, permission, expireType, expireTime, modificationTime" + - ") VALUES (" + + ") VALUES (" + ":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" + - ")"); + ")" + ); let id = 0; - function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) { + function insertOrigin( + origin, + type, + permission, + expireType, + expireTime, + modificationTime + ) { let thisId = id++; stmt6Insert.bindByName("id", thisId); @@ -70,7 +81,7 @@ add_task(function test() { permission, expireType, expireTime, - modificationTime + modificationTime, }; } @@ -91,10 +102,10 @@ add_task(function test() { let expected = [ ["https://foo.com", "A", 2, 0, 0, 0], ["http://foo.com", "A", 2, 0, 0, 0], - ["http://foo.com^inBrowser=1", "A", 2, 0, 0, 0] + ["http://foo.com^inBrowser=1", "A", 2, 0, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // This will force the permission-manager to reload the data. Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk"); @@ -104,28 +115,43 @@ add_task(function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present @@ -136,13 +162,15 @@ add_task(function test() { Assert.ok(!db.tableExists("moz_hosts_is_backup")); Assert.ok(!db.tableExists("moz_perms_v6")); - let mozHostsStmt = db.createStatement("SELECT " + - "host, type, permission, expireType, expireTime, " + - "modificationTime, isInBrowserElement " + - "FROM moz_hosts WHERE id = :id"); + let mozHostsStmt = db.createStatement( + "SELECT " + + "host, type, permission, expireType, expireTime, " + + "modificationTime, isInBrowserElement " + + "FROM moz_hosts WHERE id = :id" + ); try { // Check that the moz_hosts table still contains the correct values. - created4.forEach((it) => { + created4.forEach(it => { mozHostsStmt.reset(); mozHostsStmt.bindByName("id", it.id); mozHostsStmt.executeStep(); diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_7-8.js b/extensions/permissions/test/unit/test_permmanager_migrate_7-8.js index 014a4b61067e..962e8de251f6 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_7-8.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_7-8.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -35,14 +37,16 @@ add_task(async function test() { ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + - ")"); + ")" + ); let stmt6Insert = db.createStatement( "INSERT INTO moz_perms (" + "id, origin, type, permission, expireType, expireTime, modificationTime" + - ") VALUES (" + + ") VALUES (" + ":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" + - ")"); + ")" + ); /* * V4 table @@ -58,23 +62,34 @@ add_task(async function test() { ",modificationTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); let stmtInsert = db.createStatement( "INSERT INTO moz_hosts (" + "id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" + - ") VALUES (" + + ") VALUES (" + ":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" + - ")"); + ")" + ); /* * The v4 table is a backup */ - db.executeSimpleSQL("CREATE TABLE moz_hosts_is_backup (dummy INTEGER PRIMARY KEY)"); + db.executeSimpleSQL( + "CREATE TABLE moz_hosts_is_backup (dummy INTEGER PRIMARY KEY)" + ); let id = 0; - function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) { + function insertOrigin( + origin, + type, + permission, + expireType, + expireTime, + modificationTime + ) { let thisId = id++; stmt6Insert.bindByName("id", thisId); @@ -98,11 +113,20 @@ add_task(async function test() { permission, expireType, expireTime, - modificationTime + modificationTime, }; } - function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) { + function insertHost( + host, + type, + permission, + expireType, + expireTime, + modificationTime, + appId, + isInBrowserElement + ) { let thisId = id++; stmtInsert.bindByName("id", thisId); @@ -130,7 +154,7 @@ add_task(async function test() { expireTime, modificationTime, appId, - isInBrowserElement + isInBrowserElement, }; } @@ -161,8 +185,26 @@ add_task(async function test() { insertHost("2001:db8::ff00:42:8329", "C", 1, 0, 0, 0, 0, false), insertHost("file:///some/path/to/file.html", "A", 1, 0, 0, 0, 0, false), insertHost("file:///another/file.html", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", "A", 1, 0, 0, 0, 0, false), - insertHost("moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", "B", 1, 0, 0, 0, 0, false), + insertHost( + "moz-nullprincipal:{8695105a-adbe-4e4e-8083-851faa5ca2d7}", + "A", + 1, + 0, + 0, + 0, + 0, + false + ), + insertHost( + "moz-nullprincipal:{12ahjksd-akjs-asd3-8393-asdu2189asdu}", + "B", + 1, + 0, + 0, + 0, + 0, + false + ), insertHost("", "A", 1, 0, 0, 0, 0, false), insertHost("", "B", 1, 0, 0, 0, 0, false), ]; @@ -192,11 +234,15 @@ add_task(async function test() { ["https://192.0.2.235", "A", 2, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // Add some places to the places database - await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory")); - await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory")); + await PlacesTestUtils.addVisits( + Services.io.newURI("https://foo.com/some/other/subdirectory") + ); + await PlacesTestUtils.addVisits( + Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory") + ); await PlacesTestUtils.addVisits(Services.io.newURI("ftp://127.0.0.1:8080")); await PlacesTestUtils.addVisits(Services.io.newURI("https://localhost:8080")); @@ -208,28 +254,43 @@ add_task(async function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present diff --git a/extensions/permissions/test/unit/test_permmanager_migrate_9-10.js b/extensions/permissions/test/unit/test_permmanager_migrate_9-10.js index 969a7bb8d0c6..fcd3382dc5b2 100644 --- a/extensions/permissions/test/unit/test_permmanager_migrate_9-10.js +++ b/extensions/permissions/test/unit/test_permmanager_migrate_9-10.js @@ -1,13 +1,15 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ -ChromeUtils.defineModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); +ChromeUtils.defineModuleGetter( + this, + "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm" +); var PERMISSIONS_FILE_NAME = "permissions.sqlite"; -function GetPermissionsFile(profile) -{ +function GetPermissionsFile(profile) { let file = profile.clone(); file.append(PERMISSIONS_FILE_NAME); return file; @@ -32,14 +34,16 @@ add_task(async function test() { ",expireType INTEGER" + ",expireTime INTEGER" + ",modificationTime INTEGER" + - ")"); + ")" + ); let stmt6Insert = db.createStatement( "INSERT INTO moz_perms (" + "id, origin, type, permission, expireType, expireTime, modificationTime" + - ") VALUES (" + + ") VALUES (" + ":id, :origin, :type, :permission, :expireType, :expireTime, :modificationTime" + - ")"); + ")" + ); db.executeSimpleSQL( "CREATE TABLE moz_hosts (" + @@ -52,18 +56,27 @@ add_task(async function test() { ",modificationTime INTEGER" + ",appId INTEGER" + ",isInBrowserElement INTEGER" + - ")"); + ")" + ); let stmtInsert = db.createStatement( "INSERT INTO moz_hosts (" + "id, host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement" + - ") VALUES (" + + ") VALUES (" + ":id, :host, :type, :permission, :expireType, :expireTime, :modificationTime, :appId, :isInBrowserElement" + - ")"); + ")" + ); let id = 0; - function insertOrigin(origin, type, permission, expireType, expireTime, modificationTime) { + function insertOrigin( + origin, + type, + permission, + expireType, + expireTime, + modificationTime + ) { let thisId = id++; stmt6Insert.bindByName("id", thisId); @@ -87,11 +100,20 @@ add_task(async function test() { permission, expireType, expireTime, - modificationTime + modificationTime, }; } - function insertHost(host, type, permission, expireType, expireTime, modificationTime, appId, isInBrowserElement) { + function insertHost( + host, + type, + permission, + expireType, + expireTime, + modificationTime, + appId, + isInBrowserElement + ) { let thisId = id++; stmtInsert.bindByName("id", thisId); @@ -119,7 +141,7 @@ add_task(async function test() { expireTime, modificationTime, appId, - isInBrowserElement + isInBrowserElement, }; } @@ -149,11 +171,15 @@ add_task(async function test() { ["http://foo.com^inBrowser=1", "A", 2, 0, 0, 0], ]; - let found = expected.map((it) => 0); + let found = expected.map(it => 0); // Add some places to the places database - await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory")); - await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory")); + await PlacesTestUtils.addVisits( + Services.io.newURI("https://foo.com/some/other/subdirectory") + ); + await PlacesTestUtils.addVisits( + Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory") + ); await PlacesTestUtils.addVisits(Services.io.newURI("ftp://127.0.0.1:8080")); await PlacesTestUtils.addVisits(Services.io.newURI("https://localhost:8080")); @@ -165,28 +191,43 @@ add_task(async function test() { let isExpected = false; expected.forEach((it, i) => { - if (permission.principal.origin == it[0] && - permission.type == it[1] && - permission.capability == it[2] && - permission.expireType == it[3] && - permission.expireTime == it[4]) { + if ( + permission.principal.origin == it[0] && + permission.type == it[1] && + permission.capability == it[2] && + permission.expireType == it[3] && + permission.expireTime == it[4] + ) { isExpected = true; found[i]++; } }); - Assert.ok(isExpected, - "Permission " + (isExpected ? "should" : "shouldn't") + - " be in permission database: " + - permission.principal.origin + ", " + - permission.type + ", " + - permission.capability + ", " + - permission.expireType + ", " + - permission.expireTime); + Assert.ok( + isExpected, + "Permission " + + (isExpected ? "should" : "shouldn't") + + " be in permission database: " + + permission.principal.origin + + ", " + + permission.type + + ", " + + permission.capability + + ", " + + permission.expireType + + ", " + + permission.expireTime + ); } found.forEach((count, i) => { - Assert.ok(count == 1, "Expected count = 1, got count = " + count + " for permission " + expected[i]); + Assert.ok( + count == 1, + "Expected count = 1, got count = " + + count + + " for permission " + + expected[i] + ); }); // Check to make sure that all of the tables which we care about are present diff --git a/extensions/permissions/test/unit/test_permmanager_notifications.js b/extensions/permissions/test/unit/test_permmanager_notifications.js index a4c94d3bb844..801a7e2aca00 100644 --- a/extensions/permissions/test/unit/test_permmanager_notifications.js +++ b/extensions/permissions/test/unit/test_permmanager_notifications.js @@ -12,8 +12,7 @@ function run_test() { test_generator.next(); } -function continue_test() -{ +function continue_test() { do_run_generator(test_generator); } @@ -24,8 +23,9 @@ function* do_run_test() { let pm = Services.perms; let now = Number(Date.now()); let permType = "test/expiration-perm"; - let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); let uri = NetUtil.newURI("http://example.com"); let principal = ssm.createCodebasePrincipal(uri, {}); @@ -36,13 +36,25 @@ function* do_run_test() { // do_execute_soon() so that we can use our generator to continue the test // where we left off. executeSoon(function() { - pm.addFromPrincipal(principal, permType, pm.ALLOW_ACTION, pm.EXPIRE_TIME, now + 100000); + pm.addFromPrincipal( + principal, + permType, + pm.ALLOW_ACTION, + pm.EXPIRE_TIME, + now + 100000 + ); }); yield; // Alter a permission, to test the 'changed' notification. executeSoon(function() { - pm.addFromPrincipal(principal, permType, pm.ALLOW_ACTION, pm.EXPIRE_TIME, now + 200000); + pm.addFromPrincipal( + principal, + permType, + pm.ALLOW_ACTION, + pm.EXPIRE_TIME, + now + 200000 + ); }); yield; @@ -99,7 +111,6 @@ permission_observer.prototype = { default: do_throw("too many add notifications posted."); } - } else if (data == "changed") { let perm = subject.QueryInterface(Ci.nsIPermission); this.changes++; @@ -112,7 +123,6 @@ permission_observer.prototype = { default: do_throw("too many change notifications posted."); } - } else if (data == "deleted") { let perm = subject.QueryInterface(Ci.nsIPermission); this.deletes++; @@ -123,13 +133,11 @@ permission_observer.prototype = { default: do_throw("too many delete notifications posted."); } - } else if (data == "cleared") { // only clear once: at the end Assert.ok(!this.cleared); Assert.equal(do_count_enumerator(Services.perms.enumerator), 0); this.cleared = true; - } else { do_throw("unexpected data '" + data + "'!"); } diff --git a/extensions/permissions/test/unit/test_permmanager_removeall.js b/extensions/permissions/test/unit/test_permmanager_removeall.js index 77de65b63f5f..607e811b91e8 100644 --- a/extensions/permissions/test/unit/test_permmanager_removeall.js +++ b/extensions/permissions/test/unit/test_permmanager_removeall.js @@ -6,8 +6,9 @@ function run_test() { var dir = do_get_profile(); // initialize the permission manager service - var pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + var pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); // get the db file var file = dir.clone(); @@ -15,14 +16,17 @@ function run_test() { Assert.ok(file.exists()); // corrupt the file - var ostream = Cc["@mozilla.org/network/file-output-stream;1"]. - createInstance(Ci.nsIFileOutputStream); + var ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( + Ci.nsIFileOutputStream + ); ostream.init(file, 0x02, 0o666, 0); - var conv = Cc["@mozilla.org/intl/converter-output-stream;1"]. - createInstance(Ci.nsIConverterOutputStream); + var conv = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance( + Ci.nsIConverterOutputStream + ); conv.init(ostream, "UTF-8"); - for (var i = 0; i < file.fileSize; ++i) + for (var i = 0; i < file.fileSize; ++i) { conv.writeString("a"); + } conv.close(); // prepare an empty hostperm.1 file so that it can be used for importing diff --git a/extensions/permissions/test/unit/test_permmanager_removebytype.js b/extensions/permissions/test/unit/test_permmanager_removebytype.js index b6f7d12d6ccf..118c69edd155 100644 --- a/extensions/permissions/test/unit/test_permmanager_removebytype.js +++ b/extensions/permissions/test/unit/test_permmanager_removebytype.js @@ -5,8 +5,9 @@ function run_test() { Services.prefs.setCharPref("permissions.manager.defaultsUrl", ""); // initialize the permission manager service - let pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); Assert.equal(perm_count(), 0); diff --git a/extensions/permissions/test/unit/test_permmanager_removebytypesince.js b/extensions/permissions/test/unit/test_permmanager_removebytypesince.js index cd2a837058dc..126e53901719 100644 --- a/extensions/permissions/test/unit/test_permmanager_removebytypesince.js +++ b/extensions/permissions/test/unit/test_permmanager_removebytypesince.js @@ -5,7 +5,9 @@ add_task(async function test() { Services.prefs.setCharPref("permissions.manager.defaultsUrl", ""); // initialize the permission manager service - let pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); Assert.equal(perm_count(), 0); @@ -48,7 +50,7 @@ add_task(async function test() { Assert.equal(pm.testPermission(uri, "apple"), 3); Assert.equal(pm.testPermission(uri2, "apple"), 0); Assert.equal(pm.testPermission(uri3, "apple"), 0); - + Assert.equal(pm.testPermission(uri, "cucumber"), 1); Assert.equal(pm.testPermission(uri3, "cucumber"), 3); @@ -57,24 +59,24 @@ add_task(async function test() { Assert.equal(pm.testPermission(uri, "pear"), 1); Assert.equal(pm.testPermission(uri2, "pear"), 2); - + Assert.equal(pm.testPermission(uri, "apple"), 3); Assert.equal(pm.testPermission(uri2, "apple"), 0); Assert.equal(pm.testPermission(uri3, "apple"), 0); - + Assert.equal(pm.testPermission(uri, "cucumber"), 1); Assert.equal(pm.testPermission(uri3, "cucumber"), 0); - + pm.removeByTypeSince("pear", since); Assert.equal(perm_count(), 3); - + Assert.equal(pm.testPermission(uri, "pear"), 1); Assert.equal(pm.testPermission(uri2, "pear"), 0); - + Assert.equal(pm.testPermission(uri, "apple"), 3); Assert.equal(pm.testPermission(uri2, "apple"), 0); Assert.equal(pm.testPermission(uri3, "apple"), 0); - + Assert.equal(pm.testPermission(uri, "cucumber"), 1); Assert.equal(pm.testPermission(uri3, "cucumber"), 0); diff --git a/extensions/permissions/test/unit/test_permmanager_removepermission.js b/extensions/permissions/test/unit/test_permmanager_removepermission.js index f3766bb576d3..a0c8193db482 100644 --- a/extensions/permissions/test/unit/test_permmanager_removepermission.js +++ b/extensions/permissions/test/unit/test_permmanager_removepermission.js @@ -3,8 +3,9 @@ function run_test() { // initialize the permission manager service - let pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + let pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); Assert.equal(perm_count(), 0); @@ -42,7 +43,6 @@ function run_test() { remove_one_by_type("pear"); Assert.equal(perm_count(), 0); - function perm_count() { let enumerator = pm.enumerator; let count = 0; diff --git a/extensions/permissions/test/unit/test_permmanager_removesince.js b/extensions/permissions/test/unit/test_permmanager_removesince.js index 00111625e80a..331bda8f7afd 100644 --- a/extensions/permissions/test/unit/test_permmanager_removesince.js +++ b/extensions/permissions/test/unit/test_permmanager_removesince.js @@ -10,8 +10,7 @@ function run_test() { test_generator.next(); } -function continue_test() -{ +function continue_test() { do_run_generator(test_generator); } @@ -24,10 +23,16 @@ function* do_run_test() { // to help with testing edge-cases, we will arrange for .removeAllSince to // remove *all* permissions from one principal and one permission from another. let permURI1 = NetUtil.newURI("http://example.com"); - let principal1 = Services.scriptSecurityManager.createCodebasePrincipal(permURI1, {}); + let principal1 = Services.scriptSecurityManager.createCodebasePrincipal( + permURI1, + {} + ); let permURI2 = NetUtil.newURI("http://example.org"); - let principal2 = Services.scriptSecurityManager.createCodebasePrincipal(permURI2, {}); + let principal2 = Services.scriptSecurityManager.createCodebasePrincipal( + permURI2, + {} + ); // add a permission now - this isn't going to be removed. pm.addFromPrincipal(principal1, "test/remove-since", 1); @@ -57,13 +62,25 @@ function* do_run_test() { pm.removeAllSince(since); // principal1 - the first one should remain. - Assert.equal(1, pm.testPermissionFromPrincipal(principal1, "test/remove-since")); + Assert.equal( + 1, + pm.testPermissionFromPrincipal(principal1, "test/remove-since") + ); // but the second should have been removed. - Assert.equal(0, pm.testPermissionFromPrincipal(principal1, "test/remove-since-2")); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal1, "test/remove-since-2") + ); // principal2 - both should have been removed. - Assert.equal(0, pm.testPermissionFromPrincipal(principal2, "test/remove-since")); - Assert.equal(0, pm.testPermissionFromPrincipal(principal2, "test/remove-since-2")); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal2, "test/remove-since") + ); + Assert.equal( + 0, + pm.testPermissionFromPrincipal(principal2, "test/remove-since-2") + ); do_finish_generator_test(test_generator); } diff --git a/extensions/permissions/test/unit/test_permmanager_subdomains.js b/extensions/permissions/test/unit/test_permmanager_subdomains.js index f7ea104691a3..e896adfe8ec7 100644 --- a/extensions/permissions/test/unit/test_permmanager_subdomains.js +++ b/extensions/permissions/test/unit/test_permmanager_subdomains.js @@ -2,73 +2,228 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ function getPrincipalFromURI(aURI) { - let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"] - .getService(Ci.nsIScriptSecurityManager); + let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( + Ci.nsIScriptSecurityManager + ); let uri = NetUtil.newURI(aURI); return ssm.createCodebasePrincipal(uri, {}); } function run_test() { - var pm = Cc["@mozilla.org/permissionmanager;1"]. - getService(Ci.nsIPermissionManager); + var pm = Cc["@mozilla.org/permissionmanager;1"].getService( + Ci.nsIPermissionManager + ); // Adds a permission to a sub-domain. Checks if it is working. let sub1Principal = getPrincipalFromURI("http://sub1.example.com"); pm.addFromPrincipal(sub1Principal, "test/subdomains", pm.ALLOW_ACTION, 0, 0); - Assert.equal(pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub1Principal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub1Principal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); // A sub-sub-domain should get the permission. let subsubPrincipal = getPrincipalFromURI("http://sub.sub1.example.com"); - Assert.equal(pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(subsubPrincipal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + subsubPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); // Another sub-domain shouldn't get the permission. let sub2Principal = getPrincipalFromURI("http://sub2.example.com"); - Assert.equal(pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub2Principal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub2Principal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); // Remove current permissions. pm.removeFromPrincipal(sub1Principal, "test/subdomains"); - Assert.equal(pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub1Principal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub1Principal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); // Adding the permission to the main domain. Checks if it is working. let mainPrincipal = getPrincipalFromURI("http://example.com"); pm.addFromPrincipal(mainPrincipal, "test/subdomains", pm.ALLOW_ACTION, 0, 0); - Assert.equal(pm.testPermissionFromPrincipal(mainPrincipal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(mainPrincipal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(mainPrincipal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + mainPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); // All sub-domains should have the permission now. - Assert.equal(pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub1Principal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub2Principal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(subsubPrincipal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub1Principal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub2Principal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + subsubPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); // Remove current permissions. pm.removeFromPrincipal(mainPrincipal, "test/subdomains"); - Assert.equal(pm.testPermissionFromPrincipal(mainPrincipal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(mainPrincipal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub1Principal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub2Principal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(subsubPrincipal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(mainPrincipal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + mainPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub1Principal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub2Principal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + subsubPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); // A sanity check that the previous implementation wasn't passing... let crazyPrincipal = getPrincipalFromURI("http://com"); pm.addFromPrincipal(crazyPrincipal, "test/subdomains", pm.ALLOW_ACTION, 0, 0); - Assert.equal(pm.testPermissionFromPrincipal(crazyPrincipal, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(crazyPrincipal.originNoSuffix, "test/subdomains"), pm.ALLOW_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(mainPrincipal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(mainPrincipal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub1Principal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(sub2Principal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), pm.UNKNOWN_ACTION); - Assert.equal(pm.testPermissionOriginNoSuffix(subsubPrincipal.originNoSuffix, "test/subdomains"), pm.UNKNOWN_ACTION); + Assert.equal( + pm.testPermissionFromPrincipal(crazyPrincipal, "test/subdomains"), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + crazyPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.ALLOW_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(mainPrincipal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + mainPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(sub1Principal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub1Principal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(sub2Principal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + sub2Principal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionFromPrincipal(subsubPrincipal, "test/subdomains"), + pm.UNKNOWN_ACTION + ); + Assert.equal( + pm.testPermissionOriginNoSuffix( + subsubPrincipal.originNoSuffix, + "test/subdomains" + ), + pm.UNKNOWN_ACTION + ); } diff --git a/extensions/pref/autoconfig/src/prefcalls.js b/extensions/pref/autoconfig/src/prefcalls.js index 35226386575a..479e298c2d0a 100644 --- a/extensions/pref/autoconfig/src/prefcalls.js +++ b/extensions/pref/autoconfig/src/prefcalls.js @@ -20,201 +20,215 @@ var gVersion; var gIsUTF8; function getPrefBranch() { - var prefService = Cc[PrefServiceContractID] - .getService(nsIPrefService); - return prefService.getBranch(null); + var prefService = Cc[PrefServiceContractID].getService(nsIPrefService); + return prefService.getBranch(null); } function pref(prefName, value) { - try { - var prefBranch = getPrefBranch(); + try { + var prefBranch = getPrefBranch(); - if (typeof value == "string") { - if (gIsUTF8) { - prefBranch.setStringPref(prefName, value); - return; - } - prefBranch.setCharPref(prefName, value); - } else if (typeof value == "number") { - prefBranch.setIntPref(prefName, value); - } else if (typeof value == "boolean") { - prefBranch.setBoolPref(prefName, value); - } - } catch (e) { - displayError("pref", e); + if (typeof value == "string") { + if (gIsUTF8) { + prefBranch.setStringPref(prefName, value); + return; + } + prefBranch.setCharPref(prefName, value); + } else if (typeof value == "number") { + prefBranch.setIntPref(prefName, value); + } else if (typeof value == "boolean") { + prefBranch.setBoolPref(prefName, value); } + } catch (e) { + displayError("pref", e); + } } function defaultPref(prefName, value) { - try { - var prefService = Cc[PrefServiceContractID] - .getService(nsIPrefService); - var prefBranch = prefService.getDefaultBranch(null); - if (typeof value == "string") { - if (gIsUTF8) { - prefBranch.setStringPref(prefName, value); - return; - } - prefBranch.setCharPref(prefName, value); - } else if (typeof value == "number") { - prefBranch.setIntPref(prefName, value); - } else if (typeof value == "boolean") { - prefBranch.setBoolPref(prefName, value); - } - } catch (e) { - displayError("defaultPref", e); + try { + var prefService = Cc[PrefServiceContractID].getService(nsIPrefService); + var prefBranch = prefService.getDefaultBranch(null); + if (typeof value == "string") { + if (gIsUTF8) { + prefBranch.setStringPref(prefName, value); + return; + } + prefBranch.setCharPref(prefName, value); + } else if (typeof value == "number") { + prefBranch.setIntPref(prefName, value); + } else if (typeof value == "boolean") { + prefBranch.setBoolPref(prefName, value); } + } catch (e) { + displayError("defaultPref", e); + } } function lockPref(prefName, value) { - try { - var prefBranch = getPrefBranch(); + try { + var prefBranch = getPrefBranch(); - if (prefBranch.prefIsLocked(prefName)) - prefBranch.unlockPref(prefName); - - defaultPref(prefName, value); - - prefBranch.lockPref(prefName); - } catch (e) { - displayError("lockPref", e); + if (prefBranch.prefIsLocked(prefName)) { + prefBranch.unlockPref(prefName); } + + defaultPref(prefName, value); + + prefBranch.lockPref(prefName); + } catch (e) { + displayError("lockPref", e); + } } function unlockPref(prefName) { - try { - var prefBranch = getPrefBranch(); - prefBranch.unlockPref(prefName); - } catch (e) { - displayError("unlockPref", e); - } + try { + var prefBranch = getPrefBranch(); + prefBranch.unlockPref(prefName); + } catch (e) { + displayError("unlockPref", e); + } } function getPref(prefName) { - try { - var prefBranch = getPrefBranch(); + try { + var prefBranch = getPrefBranch(); - switch (prefBranch.getPrefType(prefName)) { - case prefBranch.PREF_STRING: - if (gIsUTF8) { - return prefBranch.getStringPref(prefName); - } - return prefBranch.getCharPref(prefName); - - case prefBranch.PREF_INT: - return prefBranch.getIntPref(prefName); - - case prefBranch.PREF_BOOL: - return prefBranch.getBoolPref(prefName); - default: - return null; + switch (prefBranch.getPrefType(prefName)) { + case prefBranch.PREF_STRING: + if (gIsUTF8) { + return prefBranch.getStringPref(prefName); } - } catch (e) { - displayError("getPref", e); + return prefBranch.getCharPref(prefName); + + case prefBranch.PREF_INT: + return prefBranch.getIntPref(prefName); + + case prefBranch.PREF_BOOL: + return prefBranch.getBoolPref(prefName); + default: + return null; } - return undefined; + } catch (e) { + displayError("getPref", e); + } + return undefined; } function clearPref(prefName) { - try { - var prefBranch = getPrefBranch(); - prefBranch.clearUserPref(prefName); - } catch (e) { - } + try { + var prefBranch = getPrefBranch(); + prefBranch.clearUserPref(prefName); + } catch (e) {} } function setLDAPVersion(version) { - gVersion = version; + gVersion = version; } - function getLDAPAttributes(host, base, filter, attribs, isSecure) { - try { - var urlSpec = "ldap" + (isSecure ? "s" : "") + "://" + host + (isSecure ? ":636" : "") + "/" + base + "?" + attribs + "?sub?" + - filter; + try { + var urlSpec = + "ldap" + + (isSecure ? "s" : "") + + "://" + + host + + (isSecure ? ":636" : "") + + "/" + + base + + "?" + + attribs + + "?sub?" + + filter; - var url = Cc["@mozilla.org/network/io-service;1"] - .getService(Ci.nsIIOService) - .newURI(urlSpec) - .QueryInterface(Ci.nsILDAPURL); + var url = Cc["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService) + .newURI(urlSpec) + .QueryInterface(Ci.nsILDAPURL); - var ldapquery = Cc[LDAPSyncQueryContractID] - .createInstance(nsILDAPSyncQuery); - // default to LDAP v3 - if (!gVersion) - gVersion = Ci.nsILDAPConnection.VERSION3; - // user supplied method - processLDAPValues(ldapquery.getQueryResults(url, gVersion)); - } catch (e) { - displayError("getLDAPAttibutes", e); + var ldapquery = Cc[LDAPSyncQueryContractID].createInstance( + nsILDAPSyncQuery + ); + // default to LDAP v3 + if (!gVersion) { + gVersion = Ci.nsILDAPConnection.VERSION3; } + // user supplied method + processLDAPValues(ldapquery.getQueryResults(url, gVersion)); + } catch (e) { + displayError("getLDAPAttibutes", e); + } } function getLDAPValue(str, key) { - try { - if (str == null || key == null) - return null; - - var search_key = "\n" + key + "="; - - var start_pos = str.indexOf(search_key); - if (start_pos == -1) - return null; - - start_pos += search_key.length; - - var end_pos = str.indexOf("\n", start_pos); - if (end_pos == -1) - end_pos = str.length; - - return str.substring(start_pos, end_pos); - } catch (e) { - displayError("getLDAPValue", e); + try { + if (str == null || key == null) { + return null; } - return undefined; + + var search_key = "\n" + key + "="; + + var start_pos = str.indexOf(search_key); + if (start_pos == -1) { + return null; + } + + start_pos += search_key.length; + + var end_pos = str.indexOf("\n", start_pos); + if (end_pos == -1) { + end_pos = str.length; + } + + return str.substring(start_pos, end_pos); + } catch (e) { + displayError("getLDAPValue", e); + } + return undefined; } function displayError(funcname, message) { - try { - var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Ci.nsIPromptService); - var bundle = Cc["@mozilla.org/intl/stringbundle;1"] - .getService(Ci.nsIStringBundleService) - .createBundle("chrome://autoconfig/locale/autoconfig.properties"); + try { + var promptService = Cc[ + "@mozilla.org/embedcomp/prompt-service;1" + ].getService(Ci.nsIPromptService); + var bundle = Cc["@mozilla.org/intl/stringbundle;1"] + .getService(Ci.nsIStringBundleService) + .createBundle("chrome://autoconfig/locale/autoconfig.properties"); - var title = bundle.GetStringFromName("autoConfigTitle"); - var msg = bundle.formatStringFromName("autoConfigMsg", [funcname]); - promptService.alert(null, title, msg + " " + message); - } catch (e) { } + var title = bundle.GetStringFromName("autoConfigTitle"); + var msg = bundle.formatStringFromName("autoConfigMsg", [funcname]); + promptService.alert(null, title, msg + " " + message); + } catch (e) {} } function getenv(name) { - try { - var environment = Cc["@mozilla.org/process/environment;1"]. - getService(Ci.nsIEnvironment); - return environment.get(name); - } catch (e) { - displayError("getEnvironment", e); - } - return undefined; + try { + var environment = Cc["@mozilla.org/process/environment;1"].getService( + Ci.nsIEnvironment + ); + return environment.get(name); + } catch (e) { + displayError("getEnvironment", e); + } + return undefined; } var APIs = { - pref, - defaultPref, - lockPref, - unlockPref, - getPref, - clearPref, - setLDAPVersion, - getLDAPAttributes, - getLDAPValue, - displayError, - getenv, + pref, + defaultPref, + lockPref, + unlockPref, + getPref, + clearPref, + setLDAPVersion, + getLDAPAttributes, + getLDAPValue, + displayError, + getenv, }; for (let [defineAs, func] of Object.entries(APIs)) { - Cu.exportFunction(func, gSandbox, {defineAs}); + Cu.exportFunction(func, gSandbox, { defineAs }); } Object.defineProperty(Cu.waiveXrays(gSandbox), "gIsUTF8", { diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig.js b/extensions/pref/autoconfig/test/unit/test_autoconfig.js index 2f8c5bcba303..2951cadbd1ca 100644 --- a/extensions/pref/autoconfig/test/unit/test_autoconfig.js +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig.js @@ -5,11 +5,12 @@ /* Turning off this rule to allow control flow operations in finally block * http://eslint.org/docs/rules/no-unsafe-finally */ -const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); function run_test() { - let env = Cc["@mozilla.org/process/environment;1"] - .getService(Ci.nsIEnvironment); + let env = Cc["@mozilla.org/process/environment;1"].getService( + Ci.nsIEnvironment + ); let prefs = Services.prefs.getBranch(null); let defPrefs = Services.prefs.getDefaultBranch(null); @@ -32,12 +33,18 @@ function run_test() { env.set("AUTOCONFIG_TEST_GETENV", "getenv"); - Services.obs.notifyObservers(Services.prefs, "prefservice:before-read-userprefs"); + Services.obs.notifyObservers( + Services.prefs, + "prefservice:before-read-userprefs" + ); ok(prefs.prefHasUserValue("_autoconfig_.test.userpref")); equal("userpref", prefs.getStringPref("_autoconfig_.test.userpref")); - equal("defaultpref", defPrefs.getStringPref("_autoconfig_.test.defaultpref")); + equal( + "defaultpref", + defPrefs.getStringPref("_autoconfig_.test.defaultpref") + ); equal("defaultpref", prefs.getStringPref("_autoconfig_.test.defaultpref")); ok(prefs.prefIsLocked("_autoconfig_.test.lockpref")); diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js index bd52864770c3..cda3d6188f9a 100644 --- a/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js @@ -5,7 +5,7 @@ /* Turning off this rule to allow control flow operations in finally block * http://eslint.org/docs/rules/no-unsafe-finally */ -const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); function run_test() { let greD = Services.dirsvc.get("GreD", Ci.nsIFile); @@ -21,50 +21,65 @@ function run_test() { Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports); Services.prefs.resetPrefs(); - var tests = [{ - filename: "autoconfig-utf8.cfg", - prefs: { - "_test.string.ASCII": "UTF-8", - "_test.string.non-ASCII": "日本語", - "_test.string.getPref": "日本語", - "_test.string.gIsUTF8": "true", + var tests = [ + { + filename: "autoconfig-utf8.cfg", + prefs: { + "_test.string.ASCII": "UTF-8", + "_test.string.non-ASCII": "日本語", + "_test.string.getPref": "日本語", + "_test.string.gIsUTF8": "true", + }, }, - }, { - filename: "autoconfig-latin1.cfg", - prefs: { - "_test.string.ASCII": "ASCII", - "_test.string.non-ASCII": "日本語", - "_test.string.getPref": "日本語", - "_test.string.gIsUTF8": "false", + { + filename: "autoconfig-latin1.cfg", + prefs: { + "_test.string.ASCII": "ASCII", + "_test.string.non-ASCII": "日本語", + "_test.string.getPref": "日本語", + "_test.string.gIsUTF8": "false", + }, }, - }, { - filename: "autoconfig-chromecheck.cfg", - prefs: { - "_test.string.typeofComponents": "undefined", + { + filename: "autoconfig-chromecheck.cfg", + prefs: { + "_test.string.typeofComponents": "undefined", + }, }, - }]; + ]; function testAutoConfig(test) { // Make sure pref values are unset. for (let prefName in test.prefs) { - Assert.equal(Ci.nsIPrefBranch.PREF_INVALID, Services.prefs.getPrefType(prefName)); + Assert.equal( + Ci.nsIPrefBranch.PREF_INVALID, + Services.prefs.getPrefType(prefName) + ); } let autoConfigCfg = testDir.clone(); autoConfigCfg.append(test.filename); autoConfigCfg.copyTo(greD, "autoconfig.cfg"); - Services.obs.notifyObservers(Services.prefs, "prefservice:before-read-userprefs"); + Services.obs.notifyObservers( + Services.prefs, + "prefservice:before-read-userprefs" + ); for (let prefName in test.prefs) { - Assert.equal(test.prefs[prefName], - Services.prefs.getStringPref(prefName)); + Assert.equal( + test.prefs[prefName], + Services.prefs.getStringPref(prefName) + ); } Services.prefs.resetPrefs(); // Make sure pref values are reset. for (let prefName in test.prefs) { - Assert.equal(Ci.nsIPrefBranch.PREF_INVALID, Services.prefs.getPrefType(prefName)); + Assert.equal( + Ci.nsIPrefBranch.PREF_INVALID, + Services.prefs.getPrefType(prefName) + ); } } diff --git a/extensions/spellcheck/hunspell/tests/unit/test_hunspell.js b/extensions/spellcheck/hunspell/tests/unit/test_hunspell.js index 31bb32e5aed7..3a93ed4fa0ec 100644 --- a/extensions/spellcheck/hunspell/tests/unit/test_hunspell.js +++ b/extensions/spellcheck/hunspell/tests/unit/test_hunspell.js @@ -3,134 +3,165 @@ */ const tests = [ - ["affixes", "iso-8859-1"], - ["condition", "iso-8859-1"], - ["condition-utf", "UTF-8"], - ["base", "iso-8859-1"], - ["base-utf", "UTF-8"], - ["allcaps", "iso-8859-1"], - ["allcaps-utf", "UTF-8"], - ["allcaps2", "iso-8859-1"], - ["allcaps3", "iso-8859-1"], - ["keepcase", "iso-8859-1"], - ["i58202", "iso-8859-1"], - ["map", "iso-8859-1"], - ["rep", "iso-8859-1"], - ["sug", "iso-8859-1"], - ["sugutf", "UTF-8"], - ["phone", "iso-8859-1"], - ["flag", "iso-8859-1"], - ["flaglong", "iso-8859-1"], - ["flagnum", "iso-8859-1"], - ["flagutf8", "UTF-8"], - ["slash", "iso-8859-1"], - ["forbiddenword", "iso-8859-1"], - ["nosuggest", "iso-8859-1"], - ["alias", "iso-8859-1"], - ["alias2", "iso-8859-1"], - ["alias3", "iso-8859-1"], - ["breakdefault", "iso-8859-1"], - ["break", "UTF-8"], - ["needaffix", "iso-8859-1"], - ["needaffix2", "iso-8859-1"], - ["needaffix3", "iso-8859-1"], - ["needaffix4", "iso-8859-1"], - ["needaffix5", "iso-8859-1"], - ["circumfix", "iso-8859-1"], - ["fogemorpheme", "iso-8859-1"], - ["onlyincompound", "iso-8859-1"], - ["complexprefixes", "iso-8859-1"], - ["complexprefixes2", "iso-8859-1"], - ["complexprefixesutf", "UTF-8"], - ["conditionalprefix", "iso-8859-1"], - ["zeroaffix", "iso-8859-1"], - ["utf8", "UTF-8"], - ["utf8-bom", "UTF-8", {1: "todo"}], - ["utf8-bom2", "UTF-8", {1: "todo"}], - ["utf8-nonbmp", "UTF-8", {1: "todo", 2: "todo", 3: "todo", 4: "todo"}], - ["compoundflag", "iso-8859-1"], - ["compoundrule", "iso-8859-1"], - ["compoundrule2", "iso-8859-1"], - ["compoundrule3", "iso-8859-1"], - ["compoundrule4", "iso-8859-1"], - ["compoundrule5", "UTF-8"], - ["compoundrule6", "iso-8859-1"], - ["compoundrule7", "iso-8859-1"], - ["compoundrule8", "iso-8859-1"], - ["compoundaffix", "iso-8859-1"], - ["compoundaffix2", "iso-8859-1"], - ["compoundaffix3", "iso-8859-1"], - ["checkcompounddup", "iso-8859-1"], - ["checkcompoundtriple", "iso-8859-1"], - ["simplifiedtriple", "iso-8859-1"], - ["checkcompoundrep", "iso-8859-1"], - ["checkcompoundcase2", "iso-8859-1"], - ["checkcompoundcaseutf", "UTF-8"], - ["checkcompoundpattern", "iso-8859-1"], - ["checkcompoundpattern2", "iso-8859-1"], - ["checkcompoundpattern3", "iso-8859-1"], - ["checkcompoundpattern4", "iso-8859-1"], - ["utfcompound", "UTF-8"], - ["checksharps", "iso-8859-1"], - ["checksharpsutf", "UTF-8"], - ["germancompounding", "iso-8859-1"], - ["germancompoundingold", "iso-8859-1"], - ["i35725", "iso-8859-1"], - ["i53643", "iso-8859-1"], - ["i54633", "iso-8859-1"], - ["i54980", "iso-8859-1", {1: "todo", 3: "todo"}], - ["maputf", "UTF-8"], - ["reputf", "UTF-8"], - ["ignore", "iso-8859-1"], - ["ignoreutf", "UTF-8", - {1: "todo", 2: "todo", 3: "todo", 4: "todo", 5: "todo", 6: "todo", - 7: "todo", 8: "todo"}], - ["1592880", "iso-8859-1"], - ["1695964", "iso-8859-1"], - ["1463589", "iso-8859-1"], - ["1463589-utf", "UTF-8"], - ["IJ", "iso-8859-1"], - ["i68568", "iso-8859-1"], - ["i68568utf", "UTF-8"], - ["1706659", "iso-8859-1"], - ["digits-in-words", "iso-8859-1"], -// ["colons-in-words", "iso-8859-1"], Suggestion test only - ["ngram-utf-fix", "UTF-8"], - ["morph", "us-ascii", - {11: "todo", 12: "todo", 13: "todo", 14: "todo", 15: "todo", 16: "todo", - 17: "todo", 18: "todo", 19: "todo", 20: "todo", 21: "todo", 22: "todo", - 23: "todo", 24: "todo", 25: "todo", 26: "todo", 27: "todo"}], - ["1975530", "UTF-8"], - ["fullstrip", "iso-8859-1"], - ["iconv", "UTF-8"], - ["oconv", "UTF-8"], - ["encoding", "iso-8859-1", {1: "todo", 3: "todo"}], - ["korean", "UTF-8"], - ["opentaal-forbiddenword1", "UTF-8"], - ["opentaal-forbiddenword2", "UTF-8"], - ["opentaal-keepcase", "UTF-8"], - ["arabic", "UTF-8"], - ["2970240", "iso-8859-1"], - ["2970242", "iso-8859-1"], - ["breakoff", "iso-8859-1"], - ["opentaal-cpdpat", "iso-8859-1"], - ["opentaal-cpdpat2", "iso-8859-1"], - ["2999225", "iso-8859-1"], - ["onlyincompound2", "iso-8859-1"], - ["forceucase", "iso-8859-1"], - ["warn", "iso-8859-1"] + ["affixes", "iso-8859-1"], + ["condition", "iso-8859-1"], + ["condition-utf", "UTF-8"], + ["base", "iso-8859-1"], + ["base-utf", "UTF-8"], + ["allcaps", "iso-8859-1"], + ["allcaps-utf", "UTF-8"], + ["allcaps2", "iso-8859-1"], + ["allcaps3", "iso-8859-1"], + ["keepcase", "iso-8859-1"], + ["i58202", "iso-8859-1"], + ["map", "iso-8859-1"], + ["rep", "iso-8859-1"], + ["sug", "iso-8859-1"], + ["sugutf", "UTF-8"], + ["phone", "iso-8859-1"], + ["flag", "iso-8859-1"], + ["flaglong", "iso-8859-1"], + ["flagnum", "iso-8859-1"], + ["flagutf8", "UTF-8"], + ["slash", "iso-8859-1"], + ["forbiddenword", "iso-8859-1"], + ["nosuggest", "iso-8859-1"], + ["alias", "iso-8859-1"], + ["alias2", "iso-8859-1"], + ["alias3", "iso-8859-1"], + ["breakdefault", "iso-8859-1"], + ["break", "UTF-8"], + ["needaffix", "iso-8859-1"], + ["needaffix2", "iso-8859-1"], + ["needaffix3", "iso-8859-1"], + ["needaffix4", "iso-8859-1"], + ["needaffix5", "iso-8859-1"], + ["circumfix", "iso-8859-1"], + ["fogemorpheme", "iso-8859-1"], + ["onlyincompound", "iso-8859-1"], + ["complexprefixes", "iso-8859-1"], + ["complexprefixes2", "iso-8859-1"], + ["complexprefixesutf", "UTF-8"], + ["conditionalprefix", "iso-8859-1"], + ["zeroaffix", "iso-8859-1"], + ["utf8", "UTF-8"], + ["utf8-bom", "UTF-8", { 1: "todo" }], + ["utf8-bom2", "UTF-8", { 1: "todo" }], + ["utf8-nonbmp", "UTF-8", { 1: "todo", 2: "todo", 3: "todo", 4: "todo" }], + ["compoundflag", "iso-8859-1"], + ["compoundrule", "iso-8859-1"], + ["compoundrule2", "iso-8859-1"], + ["compoundrule3", "iso-8859-1"], + ["compoundrule4", "iso-8859-1"], + ["compoundrule5", "UTF-8"], + ["compoundrule6", "iso-8859-1"], + ["compoundrule7", "iso-8859-1"], + ["compoundrule8", "iso-8859-1"], + ["compoundaffix", "iso-8859-1"], + ["compoundaffix2", "iso-8859-1"], + ["compoundaffix3", "iso-8859-1"], + ["checkcompounddup", "iso-8859-1"], + ["checkcompoundtriple", "iso-8859-1"], + ["simplifiedtriple", "iso-8859-1"], + ["checkcompoundrep", "iso-8859-1"], + ["checkcompoundcase2", "iso-8859-1"], + ["checkcompoundcaseutf", "UTF-8"], + ["checkcompoundpattern", "iso-8859-1"], + ["checkcompoundpattern2", "iso-8859-1"], + ["checkcompoundpattern3", "iso-8859-1"], + ["checkcompoundpattern4", "iso-8859-1"], + ["utfcompound", "UTF-8"], + ["checksharps", "iso-8859-1"], + ["checksharpsutf", "UTF-8"], + ["germancompounding", "iso-8859-1"], + ["germancompoundingold", "iso-8859-1"], + ["i35725", "iso-8859-1"], + ["i53643", "iso-8859-1"], + ["i54633", "iso-8859-1"], + ["i54980", "iso-8859-1", { 1: "todo", 3: "todo" }], + ["maputf", "UTF-8"], + ["reputf", "UTF-8"], + ["ignore", "iso-8859-1"], + [ + "ignoreutf", + "UTF-8", + { + 1: "todo", + 2: "todo", + 3: "todo", + 4: "todo", + 5: "todo", + 6: "todo", + 7: "todo", + 8: "todo", + }, + ], + ["1592880", "iso-8859-1"], + ["1695964", "iso-8859-1"], + ["1463589", "iso-8859-1"], + ["1463589-utf", "UTF-8"], + ["IJ", "iso-8859-1"], + ["i68568", "iso-8859-1"], + ["i68568utf", "UTF-8"], + ["1706659", "iso-8859-1"], + ["digits-in-words", "iso-8859-1"], + // ["colons-in-words", "iso-8859-1"], Suggestion test only + ["ngram-utf-fix", "UTF-8"], + [ + "morph", + "us-ascii", + { + 11: "todo", + 12: "todo", + 13: "todo", + 14: "todo", + 15: "todo", + 16: "todo", + 17: "todo", + 18: "todo", + 19: "todo", + 20: "todo", + 21: "todo", + 22: "todo", + 23: "todo", + 24: "todo", + 25: "todo", + 26: "todo", + 27: "todo", + }, + ], + ["1975530", "UTF-8"], + ["fullstrip", "iso-8859-1"], + ["iconv", "UTF-8"], + ["oconv", "UTF-8"], + ["encoding", "iso-8859-1", { 1: "todo", 3: "todo" }], + ["korean", "UTF-8"], + ["opentaal-forbiddenword1", "UTF-8"], + ["opentaal-forbiddenword2", "UTF-8"], + ["opentaal-keepcase", "UTF-8"], + ["arabic", "UTF-8"], + ["2970240", "iso-8859-1"], + ["2970242", "iso-8859-1"], + ["breakoff", "iso-8859-1"], + ["opentaal-cpdpat", "iso-8859-1"], + ["opentaal-cpdpat2", "iso-8859-1"], + ["2999225", "iso-8859-1"], + ["onlyincompound2", "iso-8859-1"], + ["forceucase", "iso-8859-1"], + ["warn", "iso-8859-1"], ]; function* do_get_file_by_line(file, charset) { dump("getting file by line for file " + file.path + "\n"); - dump("using charset " + charset +"\n"); - let fis = Cc["@mozilla.org/network/file-input-stream;1"]. - createInstance(Ci.nsIFileInputStream); - fis.init(file, 0x1 /* READONLY */, - 0o444, Ci.nsIFileInputStream.CLOSE_ON_EOF); + dump("using charset " + charset + "\n"); + let fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance( + Ci.nsIFileInputStream + ); + fis.init(file, 0x1 /* READONLY */, 0o444, Ci.nsIFileInputStream.CLOSE_ON_EOF); - let lis = Cc["@mozilla.org/intl/converter-input-stream;1"]. - createInstance(Ci.nsIConverterInputStream); + let lis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance( + Ci.nsIConverterInputStream + ); lis.init(fis, charset, 1024, 0); lis.QueryInterface(Ci.nsIUnicharLineInputStream); @@ -152,7 +183,7 @@ function do_run_test(checker, name, charset, todo_good, todo_bad) { let bad = do_get_file("data/" + name + ".wrong", true); let sug = do_get_file("data/" + name + ".sug", true); - dump("Need some expected output\n") + dump("Need some expected output\n"); Assert.ok(good.exists() || bad.exists() || sug.exists()); dump("Setting dictionary to " + name + "\n"); @@ -196,12 +227,13 @@ function do_run_test(checker, name, charset, todo_good, todo_bad) { } } - // XXXkhuey test suggestions + // XXXkhuey test suggestions } function run_test() { - let spellChecker = Cc["@mozilla.org/spellchecker/engine;1"]. - getService(Ci.mozISpellCheckingEngine); + let spellChecker = Cc["@mozilla.org/spellchecker/engine;1"].getService( + Ci.mozISpellCheckingEngine + ); Assert.ok(!!spellChecker, "Should have a spell checker"); spellChecker.QueryInterface(Ci.mozISpellCheckingEngine); diff --git a/extensions/spellcheck/hunspell/tests/unit/test_hunspell_unicode_paths.js b/extensions/spellcheck/hunspell/tests/unit/test_hunspell_unicode_paths.js index 7ac7557f8f63..6c9719d4ee72 100644 --- a/extensions/spellcheck/hunspell/tests/unit/test_hunspell_unicode_paths.js +++ b/extensions/spellcheck/hunspell/tests/unit/test_hunspell_unicode_paths.js @@ -1,22 +1,31 @@ "use strict"; -const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); +const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm"); Cu.importGlobalProperties(["TextEncoder"]); -XPCOMUtils.defineLazyServiceGetter(this, "spellCheck", - "@mozilla.org/spellchecker/engine;1", "mozISpellCheckingEngine"); +XPCOMUtils.defineLazyServiceGetter( + this, + "spellCheck", + "@mozilla.org/spellchecker/engine;1", + "mozISpellCheckingEngine" +); -const nsFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile", - "initWithPath"); +const nsFile = Components.Constructor( + "@mozilla.org/file/local;1", + "nsIFile", + "initWithPath" +); add_task(async function() { let prof = do_get_profile(); let basePath = OS.Path.join(prof.path, "\u263a", "dictionaries"); let baseDir = nsFile(basePath); - await OS.File.makeDir(basePath, {from: prof.path}); + await OS.File.makeDir(basePath, { from: prof.path }); let dicPath = OS.Path.join(basePath, "dict.dic"); let affPath = OS.Path.join(basePath, "dict.aff"); @@ -29,6 +38,8 @@ add_task(async function() { spellCheck.loadDictionariesFromDir(baseDir); spellCheck.dictionary = "dict"; - ok(spellCheck.check(WORD), "Dictionary should have been loaded from a unicode path"); + ok( + spellCheck.check(WORD), + "Dictionary should have been loaded from a unicode path" + ); }); - diff --git a/extensions/spellcheck/tests/mochitest/helper_bug1170484.js b/extensions/spellcheck/tests/mochitest/helper_bug1170484.js index 1cf419962e4e..53bb34d46527 100644 --- a/extensions/spellcheck/tests/mochitest/helper_bug1170484.js +++ b/extensions/spellcheck/tests/mochitest/helper_bug1170484.js @@ -1,4 +1,4 @@ -const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); // Chrome scripts are run with synchronous messages, so make sure we're completely // decoupled from the content process before doing this work. diff --git a/extensions/universalchardet/tests/CharsetDetectionTests.js b/extensions/universalchardet/tests/CharsetDetectionTests.js index 194370f6a6e5..fee17aeeb73e 100644 --- a/extensions/universalchardet/tests/CharsetDetectionTests.js +++ b/extensions/universalchardet/tests/CharsetDetectionTests.js @@ -6,90 +6,95 @@ var gDetectorList; var gTestIndex; var gLocalDir; -function CharsetDetectionTests(aTestFile, aExpectedCharset, aDetectorList) -{ - gExpectedCharset = aExpectedCharset; - gDetectorList = aDetectorList; +function CharsetDetectionTests(aTestFile, aExpectedCharset, aDetectorList) { + gExpectedCharset = aExpectedCharset; + gDetectorList = aDetectorList; - InitDetectorTests(); + InitDetectorTests(); - var fileURI = gLocalDir + aTestFile; - $("testframe").src = fileURI; + var fileURI = gLocalDir + aTestFile; + $("testframe").src = fileURI; - SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForExplicitFinish(); } -function InitDetectorTests() -{ - var prefService = Cc["@mozilla.org/preferences-service;1"] - .getService(Ci.nsIPrefBranch); - var str = Cc["@mozilla.org/supports-string;1"] - .createInstance(Ci.nsISupportsString); - var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Ci.mozIJSSubScriptLoader); - var ioService = Cc['@mozilla.org/network/io-service;1'] - .getService(Ci.nsIIOService); - loader.loadSubScript("chrome://mochikit/content/chrome-harness.js"); +function InitDetectorTests() { + var prefService = Cc["@mozilla.org/preferences-service;1"].getService( + Ci.nsIPrefBranch + ); + var str = Cc["@mozilla.org/supports-string;1"].createInstance( + Ci.nsISupportsString + ); + var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService( + Ci.mozIJSSubScriptLoader + ); + var ioService = Cc["@mozilla.org/network/io-service;1"].getService( + Ci.nsIIOService + ); + loader.loadSubScript("chrome://mochikit/content/chrome-harness.js"); - try { - gOldPref = prefService - .getComplexValue("intl.charset.detector", - Ci.nsIPrefLocalizedString).data; - } catch (e) { - gOldPref = ""; - } - SetDetectorPref(gDetectorList[0]); - gTestIndex = 0; - $("testframe").onload = DoDetectionTest; + try { + gOldPref = prefService.getComplexValue( + "intl.charset.detector", + Ci.nsIPrefLocalizedString + ).data; + } catch (e) { + gOldPref = ""; + } + SetDetectorPref(gDetectorList[0]); + gTestIndex = 0; + $("testframe").onload = DoDetectionTest; - if (gExpectedCharset == "default") { - // No point trying to be generic here, because we have plenty of other - // unit tests that fail if run using a non-windows-1252 locale. - gExpectedCharset = "windows-1252"; - } + if (gExpectedCharset == "default") { + // No point trying to be generic here, because we have plenty of other + // unit tests that fail if run using a non-windows-1252 locale. + gExpectedCharset = "windows-1252"; + } - // Get the local directory. This needs to be a file: URI because chrome: - // URIs are always UTF-8 (bug 617339) and we are testing decoding from other - // charsets. - var jar = getJar(getRootDirectory(window.location.href)); - var dir = jar ? - extractJarToTmp(jar) : - getChromeDir(getResolvedURI(window.location.href)); - gLocalDir = ioService.newFileURI(dir).spec; + // Get the local directory. This needs to be a file: URI because chrome: + // URIs are always UTF-8 (bug 617339) and we are testing decoding from other + // charsets. + var jar = getJar(getRootDirectory(window.location.href)); + var dir = jar + ? extractJarToTmp(jar) + : getChromeDir(getResolvedURI(window.location.href)); + gLocalDir = ioService.newFileURI(dir).spec; } -function SetDetectorPref(aPrefValue) -{ - var fallback = ""; - if (aPrefValue == "ja_parallel_state_machine") { - fallback = "Shift_JIS"; - } else if (aPrefValue == "ruprob" || aPrefValue == "ukprob") { - fallback = "windows-1251"; - } - var prefService = Cc["@mozilla.org/preferences-service;1"] - .getService(Ci.nsIPrefBranch); - prefService.setStringPref("intl.charset.detector", aPrefValue); - prefService.setStringPref("intl.charset.fallback.override", fallback); - gCurrentDetector = aPrefValue; +function SetDetectorPref(aPrefValue) { + var fallback = ""; + if (aPrefValue == "ja_parallel_state_machine") { + fallback = "Shift_JIS"; + } else if (aPrefValue == "ruprob" || aPrefValue == "ukprob") { + fallback = "windows-1251"; + } + var prefService = Cc["@mozilla.org/preferences-service;1"].getService( + Ci.nsIPrefBranch + ); + prefService.setStringPref("intl.charset.detector", aPrefValue); + prefService.setStringPref("intl.charset.fallback.override", fallback); + gCurrentDetector = aPrefValue; } function DoDetectionTest() { - var iframeDoc = $("testframe").contentDocument; - var charset = iframeDoc.characterSet; + var iframeDoc = $("testframe").contentDocument; + var charset = iframeDoc.characterSet; - is(charset, gExpectedCharset, - "decoded as " + gExpectedCharset + " by " + gDetectorList[gTestIndex]); + is( + charset, + gExpectedCharset, + "decoded as " + gExpectedCharset + " by " + gDetectorList[gTestIndex] + ); - if (++gTestIndex < gDetectorList.length) { - SetDetectorPref(gDetectorList[gTestIndex]); - iframeDoc.location.reload(); - } else { - CleanUpDetectionTests(); - } + if (++gTestIndex < gDetectorList.length) { + SetDetectorPref(gDetectorList[gTestIndex]); + iframeDoc.location.reload(); + } else { + CleanUpDetectionTests(); + } } function CleanUpDetectionTests() { - SetDetectorPref(gOldPref); - SimpleTest.finish(); + SetDetectorPref(gOldPref); + SimpleTest.finish(); } -