dom/events/test/test_bug659350.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial