Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=659350
5 -->
6 <head>
7 <title>Test for Bug 659350</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=659350">Mozilla Bug 659350</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
16 </div>
17 <pre id="test">
18 <script type="application/javascript">
20 /** Test for Bug 659350 **/
21 function testIn(eventName, obj, objName, expected) {
22 is(eventName in obj, expected, "'" + eventName + "' shuld be in " + objName);
23 }
25 var div = document.createElement("div");
27 // Forwarded events
28 testIn("onscroll", window, "window", true);
29 testIn("onscroll", document.body, "body", true);
30 testIn("onscroll", div, "div", true);
31 // Window events
32 testIn("onpopstate", window, "window", true);
33 testIn("onpopstate", document.body, "body", true);
34 testIn("onpopstate", div, "div", false);
35 // Non-idl events
36 testIn("onopen", window, "window", false);
37 testIn("onopen", document.body, "body", false);
38 testIn("onopen", div, "div", false);
40 function f() {}
41 function g() {}
43 // Basic sanity of interaction between the IDL and content attributes
44 div.onload = f;
45 is(div.onload, f, "Should have 'f' as div's onload");
46 div.setAttribute("onload", "");
47 isnot(div.onload, f, "Should not longer have 'f' as div's onload");
48 is(div.onload.toString(), "function onload(event) {\n\n}",
49 "Should have wrapped empty string in a function");
50 div.setAttribute("onload", "foopy();");
51 is(div.onload.toString(), "function onload(event) {\nfoopy();\n}",
52 "Should have wrapped call in a function");
53 div.removeAttribute("onload");
54 is(div.onload, null, "Should have null onload now");
56 // Test forwarding to window for both events that are window-specific and that
57 // exist on all elements
58 function testPropagationToWindow(eventName) {
59 is(window["on"+eventName], null, "Shouldn't have " + eventName + " stuff yet");
60 document.body["on"+eventName] = f;
61 is(window["on"+eventName], f,
62 "Setting on"+eventName+" on body should propagate to window");
63 document.createElement("body")["on"+eventName] = g;
64 is(window["on"+eventName], g,
65 "Setting on"+eventName+" on body not in document should propagate to window");
66 document.createElement("frameset")["on"+eventName] = f;
67 is(window["on"+eventName], f,
68 "Setting on"+eventName+" on frameset not in document should propagate to window");
70 document.body.setAttribute("on"+eventName, eventName);
71 is(window["on"+eventName].toString(),
72 "function on"+eventName+"(event) {\n"+eventName+"\n}",
73 "Setting on"+eventName+"attribute on body should propagate to window");
74 document.createElement("body").setAttribute("on"+eventName, eventName+"2");
75 is(window["on"+eventName].toString(),
76 "function on"+eventName+"(event) {\n"+eventName+"2\n}",
77 "Setting on"+eventName+"attribute on body outside the document should propagate to window");
78 }
80 testPropagationToWindow("popstate");
81 testPropagationToWindow("scroll");
83 // Test |this| and scoping
84 var called;
85 div.onscroll = function(event) {
86 is(this, div, "This should be div when invoking event listener");
87 is(event, ev, "Event argument should be the event that was dispatched");
88 called = true;
89 }
90 var ev = document.createEvent("Events");
91 ev.initEvent("scroll", true, true);
92 called = false;
93 div.dispatchEvent(ev);
94 is(called, true, "Event listener set via on* property not called");
96 div.foopy = "Found me";
97 document.foopy = "Didn't find me";
98 document.foopy2 = "Found me";
99 div.setAttribute("onscroll",
100 "is(this, div, 'This should be div when invoking via attribute');\
101 is(foopy, 'Found me', 'div should be on the scope chain when invoking handler compiled from content attribute');\
102 is(foopy2, 'Found me', 'document should be on the scope chain when invking handler compiled from content attribute');\
103 is(event, ev, 'Event argument should be the event that was dispatched');\
104 called = true;");
105 called = false;
106 div.dispatchEvent(ev);
107 is(called, true, "Event listener set via on* attribute not called");
108 </script>
109 </pre>
110 </body>
111 </html>