Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1345573 - Part 2: Remove old tests for permissions syncing, and a…
Browse files Browse the repository at this point in the history
…dd test for new logic, r=baku

MozReview-Commit-ID: A2vYqdCpeu6
  • Loading branch information
mystor committed Mar 21, 2017
1 parent 5eef733 commit f54c6f5
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 125 deletions.
2 changes: 2 additions & 0 deletions extensions/cookie/test/browser.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[DEFAULT]

[browser_test_favicon.js]
[browser_permmgr_sync.js]
skip-if = !e10s # This tests e10s specific behavior
149 changes: 149 additions & 0 deletions extensions/cookie/test/browser_permmgr_sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
function addPerm(aURI, aName) {
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;
}

add_task(function* () {
// Make sure that we get a new process for the tab which we create. This is
// important, becuase we wanto to assert information about the initial state
// of the local permissions cache.
//
// We use the same approach here as was used in the e10s-multi localStorage
// tests (dom/tests/browser/browser_localStorage_e10s.js (bug )). This ensures
// that our tab has its own process.
//
// Bug 1345990 tracks implementing a better tool for ensuring this.
let keepAliveCount = 0;
try {
keepAliveCount = SpecialPowers.getIntPref("dom.ipc.keepProcessesAlive.web");
} catch (ex) {
// Then zero is correct.
}
let safeProcessCount = keepAliveCount + 2;
info("dom.ipc.keepProcessesAlive.web is " + keepAliveCount + ", boosting " +
"process count temporarily to " + safeProcessCount);
yield SpecialPowers.pushPrefEnv({
set: [
["dom.ipc.processCount", safeProcessCount],
["dom.ipc.processCount.web", safeProcessCount]
]
});

addPerm("http://example.com", "perm1");
addPerm("http://foo.bar.example.com", "perm2");
addPerm("about:home", "perm3");
addPerm("https://example.com", "perm4");

yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (aBrowser) {
yield ContentTask.spawn(aBrowser, null, 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);
is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
"perm2"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("about:home"),
"perm3"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
"perm4"),
Services.perms.UNKNOWN_ACTION);

// Perform a load of example.com
yield 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);
is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
"perm2"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("about:home"),
"perm3"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
"perm4"),
Services.perms.UNKNOWN_ACTION);
});

addPerm("http://example.com", "newperm1");
addPerm("http://foo.bar.example.com", "newperm2");
addPerm("about:home", "newperm3");
addPerm("https://example.com", "newperm4");

yield ContentTask.spawn(aBrowser, null, 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);
is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
"newperm1"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
"perm2"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
"newperm2"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("about:home"),
"perm3"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("about:home"),
"newperm3"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
"perm4"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
"newperm4"),
Services.perms.UNKNOWN_ACTION);

// Loading a subdomain now, on https
yield 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);
is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
"newperm1"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
"perm2"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
"newperm2"),
Services.perms.UNKNOWN_ACTION);
is(Services.perms.testPermission(Services.io.newURI("about:home"),
"perm3"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("about:home"),
"newperm3"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
"perm4"),
Services.perms.ALLOW_ACTION);
is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
"newperm4"),
Services.perms.ALLOW_ACTION);
});
});
});
1 change: 0 additions & 1 deletion extensions/cookie/test/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

XPCSHELL_TESTS_MANIFESTS += [
'unit/xpcshell.ini',
'unit_ipc/xpcshell.ini',
]

MOCHITEST_MANIFESTS += ['mochitest.ini']
Expand Down
59 changes: 0 additions & 59 deletions extensions/cookie/test/unit_ipc/test_child.js

This file was deleted.

59 changes: 0 additions & 59 deletions extensions/cookie/test/unit_ipc/test_parent.js

This file was deleted.

6 changes: 0 additions & 6 deletions extensions/cookie/test/unit_ipc/xpcshell.ini

This file was deleted.

0 comments on commit f54c6f5

Please sign in to comment.