4 https://bugzilla.mozilla.org/show_bug.cgi?id=1036214
8 <title>Test for Bug
1036214</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <script type=
"application/javascript">
12 /* global TestInterfaceJS */
14 /** Test for subsumes-checking |any| and |object| for js-implemented WebIDL. **/
15 SimpleTest.waitForExplicitFinish();
18 // window[
0] is same-process and cross-origin, even with Fission enabled.
19 xoObjects.push(window[
0]);
20 xoObjects.push(window[
0].location);
21 xoObjects.push(SpecialPowers.unwrap(SpecialPowers.wrap(window[
0]).document));
22 xoObjects.push(SpecialPowers.unwrap(SpecialPowers));
23 xoObjects.push(SpecialPowers.unwrap(SpecialPowers.wrap));
24 SpecialPowers.pushPrefEnv({set: [[
"dom.expose_test_interfaces", true]]}, go);
28 if (SpecialPowers.useRemoteSubframes) {
29 // window[
1] is cross-origin and out of process, with Fission enabled.
30 xoObjects.push(window[
1]);
31 xoObjects.push(window[
1].location);
35 function checkThrows(f, msg) {
38 ok(false,
"Should have thrown: " + msg);
40 ok(true,
"Threw correctly: " + msg);
41 ok(/denied|insecure/.test(e),
"Threw security exception: " + e);
47 // Test the basics of the test interface.
51 var obj = { b:
22, c:
"str" };
52 var obj2 = { foo:
"baz" };
53 var myDict = { anyMember:
42, objectMember: { answer:
42 }, objectOrStringMember: { answer:
"anobject" },
54 anySequenceMember: [{},
1,
"thirdinsequence"],
55 objectRecordMember: { key: { answer:
"fortytwo" } },
56 innerDictionary: { innerObject: { answer:
"rabbithole" } } };
57 var t = new TestInterfaceJS(any, obj, myDict);
58 is(Object.getPrototypeOf(t), TestInterfaceJS.prototype,
"Prototype setup works correctly");
59 is(t.anyArg, any,
"anyArg is correct");
60 is(t.objectArg, obj,
"objectArg is correct");
61 is(t.getDictionaryArg().anyMember,
42,
"dictionaryArg looks correct");
62 is(t.getDictionaryArg().objectMember.answer,
42,
"dictionaryArg looks correct");
63 is(t.getDictionaryArg().objectRecordMember.key.answer,
"fortytwo",
"dictionaryArg looks correct");
64 is(t.getDictionaryArg().objectRecordMember.key.answer,
"fortytwo",
"dictionaryArg looks correct");
66 is(t.anyAttr,
2,
"ping-pong any attribute works");
68 is(t.objAttr, obj2,
"ping-pong object attribute works");
69 t.setDictionaryAttr(myDict);
70 is(t.getDictionaryAttr().anyMember,
42,
"ping-pong dictionary works");
71 is(t.getDictionaryAttr().objectMember.answer,
42,
"ping-pong dictionary works");
72 is(t.getDictionaryAttr().objectRecordMember.key.answer,
"fortytwo",
"ping-pong dictionary works");
73 is(t.getDictionaryAttr().objectRecordMember.key.answer,
"fortytwo",
"ping-pong dictionary works");
75 is(any, t.pingPongAny(any),
"ping-pong works with any");
76 is(obj, t.pingPongObject(obj),
"ping-pong works with obj");
77 is(obj, t.pingPongObjectOrString(obj),
"ping-pong works with obj or string");
78 is(
"foo", t.pingPongObjectOrString(
"foo"),
"ping-pong works with obj or string");
79 is(t.pingPongDictionary(myDict).anyMember,
42,
"ping pong works with dict");
80 is(t.pingPongDictionary(myDict).objectMember.answer,
42,
"ping pong works with dict");
81 is(t.pingPongDictionary(myDict).objectOrStringMember.answer,
"anobject",
"ping pong works with dict");
82 is(t.pingPongDictionary(myDict).anySequenceMember[
2],
"thirdinsequence",
"ping pong works with dict");
83 is(t.pingPongDictionary(myDict).objectRecordMember.key.answer,
"fortytwo",
"ping pong works with dict");
84 is(t.pingPongDictionary(myDict).objectRecordMember.key.answer,
"fortytwo",
"ping pong works with dict");
85 is(t.pingPongDictionary(myDict).innerDictionary.innerObject.answer,
"rabbithole",
"ping pong works with layered dicts");
86 is(t.pingPongDictionaryOrLong({anyMember:
42}),
42,
"ping pong (dict or long) works with dict");
87 is(t.pingPongDictionaryOrLong(
42),
42,
"ping pong (dict or long) works with long");
88 ok(/canary/.test(t.pingPongRecord({ someVal:
42, someOtherVal:
"canary" })),
"ping pong works with record");
89 is(t.objectSequenceLength([{}, {}, {}]),
3,
"ping pong works with object sequence");
90 is(t.anySequenceLength([
42,
"string", {}, undefined]),
4,
"ping pong works with any sequence");
93 // Test that we throw in the cross-origin cases.
96 xoObjects.forEach(function(xoObj) {
97 new TestInterfaceJS();
98 checkThrows(() =
> new TestInterfaceJS(xoObj, undefined),
"any param for constructor");
99 checkThrows(() =
> new TestInterfaceJS(undefined, xoObj),
"obj param for constructor");
100 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { anyMember: xoObj }),
"any dict param for constructor");
101 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { objectMember: xoObj }),
"object dict param for constructor");
102 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { objectOrStringMember: xoObj }),
"union dict param for constructor");
103 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { anySequenceMember: [
0, xoObj,
"hi" ] }),
"sequence dict param for constructor");
104 checkThrows(() =
> new TestInterfaceJS(undefined, undefined, { innerDictionary: { innerObject: xoObj } }),
"inner dict param for constructor");
105 checkThrows(() =
> t.anyAttr = xoObj,
"anyAttr");
106 checkThrows(() =
> t.objectAttr = xoObj,
"objAttr");
107 checkThrows(() =
> t.setDictionaryAttr({ anyMember: xoObj }),
"dictionaryAttr any");
108 checkThrows(() =
> t.setDictionaryAttr({ objectMember: xoObj }),
"dictionaryAttr object");
109 checkThrows(() =
> t.pingPongAny(xoObj),
"pingpong any");
110 checkThrows(() =
> t.pingPongObject(xoObj),
"pingpong obj");
111 checkThrows(() =
> t.pingPongObjectOrString(xoObj),
"pingpong union");
112 checkThrows(() =
> t.pingPongDictionary({ anyMember: xoObj }),
"dictionary pingpong any");
113 checkThrows(() =
> t.pingPongDictionary({ objectMember: xoObj }),
"dictionary pingpong object");
114 checkThrows(() =
> t.pingPongDictionary({ anyMember: xoObj, objectMember: xoObj }),
"dictionary pingpong both");
115 checkThrows(() =
> t.pingPongDictionary({ objectOrStringMember: xoObj }),
"dictionary pingpong objectorstring");
116 checkThrows(() =
> t.pingPongDictionary({ objectRecordMember: { key: xoObj } }),
"dictionary pingpong record of object");
117 checkThrows(() =
> t.pingPongDictionaryOrLong({ objectMember: xoObj }),
"unionable dictionary");
118 checkThrows(() =
> t.pingPongDictionaryOrLong({ anyMember: xoObj }),
"unionable dictionary");
119 checkThrows(() =
> t.pingPongRecord({ someMember:
42, someOtherMember: {}, crossOriginMember: xoObj }),
"record");
120 checkThrows(() =
> t.objectSequenceLength([{}, {}, xoObj, {}]),
"object sequence");
121 checkThrows(() =
> t.anySequenceLength([
42,
"someString", xoObj, {}]),
"any sequence");
131 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=1036214">Mozilla Bug
1036214</a>
133 <div id=
"content" style=
"display: none">
138 <iframe id=
"ifr" onload=
"setup();" src=
"http://test1.mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>
139 <iframe id=
"ifr2" onload=
"setup2();" src=
"http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>