4 https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
8 <title>Test for Bug
1036214</title>
9 <script type=
"application/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <script type=
"application/javascript">
13 /** Test for subsumes-checking |any| and |object| for js-implemented WebIDL. **/
14 SimpleTest.waitForExplicitFinish();
17 xoObjects.push(window[
0]);
18 xoObjects.push(window[
0].location);
19 xoObjects.push(SpecialPowers.unwrap(SpecialPowers.wrap(window[
0]).document));
20 xoObjects.push(SpecialPowers);
21 xoObjects.push(SpecialPowers.wrap);
22 SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go);
25 function checkThrows(f, msg) {
28 ok(false,
"Should have thrown: " + msg);
30 ok(true,
"Threw correctly: " + msg);
31 ok(/denied|insecure/.test(e),
"Threw security exception: " + e);
38 // Test the basics of the test interface.
42 var obj = { b:
22, c:
"str" };
43 var obj2 = { foo:
"baz" };
44 var myDict = { anyMember:
42, objectMember: { answer:
42 }, objectOrStringMember: { answer:
"anobject" },
45 anySequenceMember: [{},
1,
"thirdinsequence"],
46 innerDictionary: { innerObject: { answer:
"rabbithole" } } };
47 var t = new TestInterfaceJS(any, obj, myDict);
48 is(Object.getPrototypeOf(t), TestInterfaceJS.prototype,
"Prototype setup works correctly");
49 is(t.anyArg, any,
"anyArg is correct");
50 is(t.objectArg, obj,
"objectArg is correct");
51 is(t.dictionaryArg.anyMember,
42,
"dictionaryArg looks correct");
52 is(t.dictionaryArg.objectMember.answer,
42,
"dictionaryArg looks correct");
54 is(t.anyAttr,
2,
"ping-pong any attribute works");
56 is(t.objAttr, obj2,
"ping-pong object attribute works");
57 t.dictionaryAttr = myDict;
58 is(t.dictionaryAttr.anyMember,
42,
"ping-pong dictionary attribute works");
59 is(t.dictionaryAttr.objectMember.answer,
42,
"ping-pong dictionary attribute works");
61 is(any, t.pingPongAny(any),
"ping-pong works with any");
62 is(obj, t.pingPongObject(obj),
"ping-pong works with obj");
63 is(obj, t.pingPongObjectOrString(obj),
"ping-pong works with obj or string");
64 is(
"foo", t.pingPongObjectOrString(
"foo"),
"ping-pong works with obj or string");
65 is(t.pingPongDictionary(myDict).anyMember,
42,
"ping pong works with dict");
66 is(t.pingPongDictionary(myDict).objectMember.answer,
42,
"ping pong works with dict");
67 is(t.pingPongDictionary(myDict).objectOrStringMember.answer,
"anobject",
"ping pong works with dict");
68 is(t.pingPongDictionary(myDict).anySequenceMember[
2],
"thirdinsequence",
"ping pong works with dict");
69 is(t.pingPongDictionary(myDict).innerDictionary.innerObject.answer,
"rabbithole",
"ping pong works with layered dicts");
70 is(t.pingPongDictionaryOrLong({anyMember:
42}),
42,
"ping pong (dict or long) works with dict");
71 is(t.pingPongDictionaryOrLong(
42),
42,
"ping pong (dict or long) works with long");
72 ok(/canary/.test(t.pingPongMap({ someVal:
42, someOtherVal:
"canary" })),
"ping pong works with mozmap");
73 is(t.objectSequenceLength([{}, {}, {}]),
3,
"ping pong works with object sequence");
74 is(t.anySequenceLength([
42, 'string', {}, undefined]),
4,
"ping pong works with any sequence");
77 // Test that we throw in the cross-origin cases.
80 xoObjects.forEach(function(xoObj) {
81 var blank = new TestInterfaceJS();
82 checkThrows(() =
> new TestInterfaceJS(xoObj, undefined),
"any param for constructor");
83 checkThrows(() =
> new TestInterfaceJS(undefined, xoObj),
"obj param for constructor");
84 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { anyMember: xoObj }),
"any dict param for constructor");
85 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { objectMember: xoObj }),
"object dict param for constructor");
86 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { objectOrStringMember: xoObj }),
"union dict param for constructor");
87 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { anySequenceMember: [
0, xoObj, 'hi' ] }),
"sequence dict param for constructor");
88 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { innerDictionary: { innerObject: xoObj } }),
"inner dict param for constructor");
89 checkThrows(() =
> t.anyAttr = xoObj,
"anyAttr");
90 checkThrows(() =
> t.objectAttr = xoObj,
"objAttr");
91 checkThrows(() =
> t.dictionaryAttr = { anyMember: xoObj },
"dictionaryAttr any");
92 checkThrows(() =
> t.dictionaryAttr = { objectMember: xoObj },
"dictionaryAttr object");
93 checkThrows(() =
> t.pingPongAny(xoObj),
"pingpong any");
94 checkThrows(() =
> t.pingPongObject(xoObj),
"pingpong obj");
95 checkThrows(() =
> t.pingPongObjectOrString(xoObj),
"pingpong union");
96 checkThrows(() =
> t.pingPongDictionary({ anyMember: xoObj }),
"dictionary pingpong any");
97 checkThrows(() =
> t.pingPongDictionary({ objectMember: xoObj }),
"dictionary pingpong object");
98 checkThrows(() =
> t.pingPongDictionary({ anyMember: xoObj, objectMember: xoObj }),
"dictionary pingpong both");
99 checkThrows(() =
> t.pingPongDictionary({ objectOrStringMember: xoObj }),
"dictionary pingpong objectorstring");
100 checkThrows(() =
> t.pingPongDictionaryOrLong({ objectMember: xoObj }),
"unionable dictionary");
101 checkThrows(() =
> t.pingPongDictionaryOrLong({ anyMember: xoObj }),
"unionable dictionary");
102 checkThrows(() =
> t.pingPongMap({ someMember:
42, someOtherMember: {}, crossOriginMember: xoObj }),
"mozmap");
103 checkThrows(() =
> t.objectSequenceLength([{}, {}, xoObj, {}]),
"object sequence");
104 checkThrows(() =
> t.anySequenceLength([
42, 'someString', xoObj, {}]),
"any sequence");
114 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=1036214">Mozilla Bug
1036214</a>
116 <div id=
"content" style=
"display: none">
121 <iframe id=
"ifr" onload=
"setup();" src=
"http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>