forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1329032 - Test privileged about page to use SystemPrincipal as Tr…
…iggeringPrincipal when loading about page in child. r=gijs
- Loading branch information
Christoph Kerschbaumer
committed
Jan 17, 2017
1 parent
05287d4
commit 8c97c0c
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
browser/base/content/test/general/browser_e10s_about_page_triggeringprincipal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use strict"; | ||
Cu.import("resource://gre/modules/Services.jsm"); | ||
|
||
registerCleanupFunction(function() { | ||
Services.ppmm.broadcastAsyncMessage("AboutPrincipalTest:Unregister"); | ||
yield BrowserTestUtils.waitForMessage(Services.ppmm, "AboutPrincipalTest:Unregistered"); | ||
|
||
Services.ppmm.removeDelayedProcessScript( | ||
"chrome://mochitests/content/browser/browser/base/content/test/general/file_register_about_page.js" | ||
); | ||
}); | ||
|
||
add_task(function* test_principal() { | ||
Services.ppmm.loadProcessScript( | ||
"chrome://mochitests/content/browser/browser/base/content/test/general/file_register_about_page.js", | ||
true | ||
); | ||
|
||
yield BrowserTestUtils.withNewTab("about:test-about-principal-parent", function*(browser) { | ||
let loadPromise = BrowserTestUtils.browserLoaded(browser, false, "about:test-about-principal-child"); | ||
let myLink = browser.contentDocument.getElementById("aboutchildprincipal"); | ||
myLink.click(); | ||
yield loadPromise; | ||
|
||
yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function*() { | ||
let channel = content.document.docShell.currentDocumentChannel; | ||
is(channel.originalURI.asciiSpec, | ||
"about:test-about-principal-child", | ||
"sanity check - make sure we test the principal for the correct URI"); | ||
|
||
let triggeringPrincipal = channel.loadInfo.triggeringPrincipal; | ||
ok(Services.scriptSecurityManager.isSystemPrincipal(triggeringPrincipal), | ||
"loading about: from privileged page must have a triggering of System"); | ||
|
||
let contentPolicyType = channel.loadInfo.externalContentPolicyType; | ||
is(contentPolicyType, Ci.nsIContentPolicy.TYPE_DOCUMENT, | ||
"sanity check - loading a top level document"); | ||
|
||
let loadingPrincipal = channel.loadInfo.loadingPrincipal; | ||
is(loadingPrincipal, null, | ||
"sanity check - load of TYPE_DOCUMENT must have a null loadingPrincipal"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test for Bug 1329032</title> | ||
</head> | ||
<body> | ||
Just an about page that only loads in the child! | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test for Bug 1329032</title> | ||
</head> | ||
<body> | ||
<a href="about:test-about-principal-child" id="aboutchildprincipal">about:test-about-principal-child</a> | ||
</body> | ||
</html> |
81 changes: 81 additions & 0 deletions
81
browser/base/content/test/general/file_register_about_page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { interfaces: Ci, results: Cr, manager: Cm, utils: Cu } = Components; | ||
Cu.import("resource://gre/modules/Services.jsm"); | ||
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | ||
|
||
function AboutPage(chromeURL, aboutHost, classID, description, uriFlags) { | ||
this.chromeURL = chromeURL; | ||
this.aboutHost = aboutHost; | ||
this.classID = Components.ID(classID); | ||
this.description = description; | ||
this.uriFlags = uriFlags; | ||
} | ||
|
||
AboutPage.prototype = { | ||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), | ||
getURIFlags(aURI) { // eslint-disable-line no-unused-vars | ||
return this.uriFlags; | ||
}, | ||
|
||
newChannel(aURI, aLoadInfo) { | ||
let newURI = Services.io.newURI(this.chromeURL); | ||
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI, | ||
aLoadInfo); | ||
channel.originalURI = aURI; | ||
|
||
if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) { | ||
channel.owner = null; | ||
} | ||
return channel; | ||
}, | ||
|
||
createInstance(outer, iid) { | ||
if (outer !== null) { | ||
throw Cr.NS_ERROR_NO_AGGREGATION; | ||
} | ||
return this.QueryInterface(iid); | ||
}, | ||
|
||
register() { | ||
Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory( | ||
this.classID, this.description, | ||
"@mozilla.org/network/protocol/about;1?what=" + this.aboutHost, this); | ||
}, | ||
|
||
unregister() { | ||
Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory( | ||
this.classID, this); | ||
} | ||
}; | ||
|
||
/* exported AboutPrincipalTest */ | ||
var AboutPrincipalTest = {}; | ||
|
||
XPCOMUtils.defineLazyGetter(AboutPrincipalTest, "aboutChild", () => | ||
new AboutPage("chrome://mochitests/content/browser/browser/base/content/test/general/file_about_child.html", | ||
"test-about-principal-child", | ||
"{df6cbd19-c95b-4011-874b-315347c0832c}", | ||
"About Principal Child Test", | ||
Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD | | ||
Ci.nsIAboutModule.ALLOW_SCRIPT) | ||
|
||
); | ||
|
||
XPCOMUtils.defineLazyGetter(AboutPrincipalTest, "aboutParent", () => | ||
new AboutPage("chrome://mochitests/content/browser/browser/base/content/test/general/file_about_parent.html", | ||
"test-about-principal-parent", | ||
"{15e1a03d-9f94-4352-bfb8-94216140d3ab}", | ||
"About Principal Parent Test", | ||
Ci.nsIAboutModule.ALLOW_SCRIPT) | ||
); | ||
|
||
AboutPrincipalTest.aboutParent.register(); | ||
AboutPrincipalTest.aboutChild.register(); | ||
|
||
function onUnregisterMessage() { | ||
removeMessageListener("AboutPrincipalTest:Unregister", onUnregisterMessage); | ||
AboutPrincipalTest.aboutParent.unregister(); | ||
AboutPrincipalTest.aboutChild.unregister(); | ||
sendAsyncMessage("AboutPrincipalTest:Unregistered"); | ||
} | ||
|
||
addMessageListener("AboutPrincipalTest:Unregister", onUnregisterMessage); |