mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
Bug 968335 - Tests. r=bz
This commit is contained in:
parent
c8ca39b87d
commit
4de0b7d455
@ -11,7 +11,7 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var gGlobal = this;
|
||||
function checkGlobal(obj) {
|
||||
if (typeof obj == 'object' && Cu.getGlobalForObject(obj) != gGlobal) {
|
||||
if (Object(obj) === obj && Cu.getGlobalForObject(obj) != gGlobal) {
|
||||
// This message may not make it to the caller in a useful form, so dump
|
||||
// as well.
|
||||
var msg = "TestInterfaceJS received an object from a different scope!";
|
||||
@ -44,6 +44,8 @@ TestInterfaceJS.prototype = {
|
||||
set objectAttr(val) { checkGlobal(val); this._objectAttr = val; },
|
||||
pingPongAny: function(any) { checkGlobal(any); return any; },
|
||||
pingPongObject: function(obj) { checkGlobal(obj); return obj; },
|
||||
|
||||
getCallerPrincipal: function() { return Cu.getWebIDLCallerPrincipal().origin; }
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceJS])
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
[JSImplementation="@mozilla.org/dom/test-interface-js;1",
|
||||
Pref="dom.expose_test_interfaces",
|
||||
Constructor(any anyArg, object objectArg)]
|
||||
Constructor(optional any anyArg, optional object objectArg)]
|
||||
interface TestInterfaceJS {
|
||||
readonly attribute any anyArg;
|
||||
readonly attribute object objectArg;
|
||||
@ -14,4 +14,7 @@ interface TestInterfaceJS {
|
||||
attribute object objectAttr;
|
||||
any pingPongAny(any arg);
|
||||
object pingPongObject(any obj);
|
||||
|
||||
// For testing bug 968335.
|
||||
DOMString getCallerPrincipal();
|
||||
};
|
||||
|
@ -89,5 +89,8 @@ support-files =
|
||||
[test_bug965082.html]
|
||||
[test_crosscompartment_weakmap.html]
|
||||
[test_frameWrapping.html]
|
||||
# The JS test component we use below is only available in debug builds.
|
||||
[test_getWebIDLCaller.html]
|
||||
skip-if = debug == false
|
||||
[test_nac.xhtml]
|
||||
[test_sameOriginPolicy.html]
|
||||
|
49
js/xpconnect/tests/mochitest/test_getWebIDLCaller.html
Normal file
49
js/xpconnect/tests/mochitest/test_getWebIDLCaller.html
Normal file
@ -0,0 +1,49 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=968335
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 968335</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Cu.getCallerPrincipal (within JS-implemented WebIDL). **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go);
|
||||
|
||||
|
||||
function go() {
|
||||
var t = new TestInterfaceJS();
|
||||
is(t.getCallerPrincipal(), location.origin,
|
||||
"Cu.getCallerPrincipal works right within JS-implemented WebIDL");
|
||||
|
||||
try {
|
||||
SpecialPowers.Cu.getWebIDLCallerPrincipal();
|
||||
ok(false, "Should have thrown");
|
||||
} catch (e) {
|
||||
ok(/NOT_AVAILABLE/.test(SpecialPowers.wrap(e)),
|
||||
"API should throw when invoked outside of JS-implemented WebIDL");
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=968335">Mozilla Bug 968335</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user