diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /image/test/browser/browser_docshell_type_editor.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'image/test/browser/browser_docshell_type_editor.js')
-rw-r--r-- | image/test/browser/browser_docshell_type_editor.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/image/test/browser/browser_docshell_type_editor.js b/image/test/browser/browser_docshell_type_editor.js new file mode 100644 index 000000000..8ac98924f --- /dev/null +++ b/image/test/browser/browser_docshell_type_editor.js @@ -0,0 +1,92 @@ + +"use strict"; + +const Ci = Components.interfaces; +const SIMPLE_HTML = "data:text/html,<html><head></head><body></body></html>"; + +// The following URI is *not* accessible to content, hence loading that URI +// from an unprivileged site should be blocked. If docshell is of appType +// APP_TYPE_EDITOR however the load should be allowed. +// >> chrome://devtools/content/framework/dev-edition-promo/dev-edition-logo.png + +add_task(function* () { + info("docshell of appType APP_TYPE_EDITOR can access privileged images."); + + yield BrowserTestUtils.withNewTab({ + gBrowser, + url: SIMPLE_HTML + }, function* (browser) { + yield ContentTask.spawn(browser, null, function* () { + let rootDocShell = docShell.QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell); + let defaultAppType = rootDocShell.appType; + + rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_EDITOR; + + is(rootDocShell.appType, Ci.nsIDocShell.APP_TYPE_EDITOR, + "sanity check: appType after update should be type editor"); + + return new Promise(resolve => { + let doc = content.document; + let image = doc.createElement("img"); + image.onload = function() { + ok(true, "APP_TYPE_EDITOR is allowed to load privileged image"); + // restore appType of rootDocShell before moving on to the next test + rootDocShell.appType = defaultAppType; + resolve(); + } + image.onerror = function() { + ok(false, "APP_TYPE_EDITOR is allowed to load privileged image"); + // restore appType of rootDocShell before moving on to the next test + rootDocShell.appType = defaultAppType; + resolve(); + } + doc.body.appendChild(image); + image.src = "chrome://devtools/content/framework/dev-edition-promo/dev-edition-logo.png"; + }); + }); + }); +}); + +add_task(function* () { + info("docshell of appType APP_TYPE_UNKNOWN can *not* access privileged images."); + + yield BrowserTestUtils.withNewTab({ + gBrowser, + url: SIMPLE_HTML + }, function* (browser) { + yield ContentTask.spawn(browser, null, function* () { + let rootDocShell = docShell.QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell); + let defaultAppType = rootDocShell.appType; + + rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_UNKNOWN; + + is(rootDocShell.appType, Ci.nsIDocShell.APP_TYPE_UNKNOWN, + "sanity check: appType of docshell should be unknown"); + + return new Promise(resolve => { + let doc = content.document; + let image = doc.createElement("img"); + image.onload = function() { + ok(false, "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image"); + // restore appType of rootDocShell before moving on to the next test + rootDocShell.appType = defaultAppType; + resolve(); + } + image.onerror = function() { + ok(true, "APP_TYPE_UNKNOWN is *not* allowed to acces privileged image"); + // restore appType of rootDocShell before moving on to the next test + rootDocShell.appType = defaultAppType; + resolve(); + } + doc.body.appendChild(image); + image.src = "chrome://devtools/content/framework/dev-edition-promo/dev-edition-logo.png"; + }); + }); + }); +}); |