dom/events/test/test_bug659350.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug659350.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=659350
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 659350</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=659350">Mozilla Bug 659350</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 659350 **/
    1.24 +function testIn(eventName, obj, objName, expected) {
    1.25 +  is(eventName in obj, expected, "'" + eventName + "' shuld be in " + objName);
    1.26 +}
    1.27 +
    1.28 +var div = document.createElement("div");
    1.29 +
    1.30 +// Forwarded events
    1.31 +testIn("onscroll", window, "window", true);
    1.32 +testIn("onscroll", document.body, "body", true);
    1.33 +testIn("onscroll", div, "div", true);
    1.34 +// Window events
    1.35 +testIn("onpopstate", window, "window", true);
    1.36 +testIn("onpopstate", document.body, "body", true);
    1.37 +testIn("onpopstate", div, "div", false);
    1.38 +// Non-idl events
    1.39 +testIn("onopen", window, "window", false);
    1.40 +testIn("onopen", document.body, "body", false);
    1.41 +testIn("onopen", div, "div", false);
    1.42 +
    1.43 +function f() {}
    1.44 +function g() {}
    1.45 +
    1.46 +// Basic sanity of interaction between the IDL and content attributes
    1.47 +div.onload = f;
    1.48 +is(div.onload, f, "Should have 'f' as div's onload");
    1.49 +div.setAttribute("onload", "");
    1.50 +isnot(div.onload, f, "Should not longer have 'f' as div's onload");
    1.51 +is(div.onload.toString(), "function onload(event) {\n\n}",
    1.52 +   "Should have wrapped empty string in a function");
    1.53 +div.setAttribute("onload", "foopy();");
    1.54 +is(div.onload.toString(), "function onload(event) {\nfoopy();\n}",
    1.55 +   "Should have wrapped call in a function");
    1.56 +div.removeAttribute("onload");
    1.57 +is(div.onload, null, "Should have null onload now");
    1.58 +
    1.59 +// Test forwarding to window for both events that are window-specific and that
    1.60 +// exist on all elements
    1.61 +function testPropagationToWindow(eventName) {
    1.62 +  is(window["on"+eventName], null, "Shouldn't have " + eventName + " stuff yet");
    1.63 +  document.body["on"+eventName] = f;
    1.64 +  is(window["on"+eventName], f,
    1.65 +     "Setting on"+eventName+" on body should propagate to window");
    1.66 +  document.createElement("body")["on"+eventName] = g;
    1.67 +  is(window["on"+eventName], g,
    1.68 +     "Setting on"+eventName+" on body not in document should propagate to window");
    1.69 +  document.createElement("frameset")["on"+eventName] = f;
    1.70 +  is(window["on"+eventName], f,
    1.71 +     "Setting on"+eventName+" on frameset not in document should propagate to window");
    1.72 +
    1.73 +  document.body.setAttribute("on"+eventName, eventName);
    1.74 +  is(window["on"+eventName].toString(),
    1.75 +            "function on"+eventName+"(event) {\n"+eventName+"\n}",
    1.76 +            "Setting on"+eventName+"attribute on body should propagate to window");
    1.77 +  document.createElement("body").setAttribute("on"+eventName, eventName+"2");
    1.78 +  is(window["on"+eventName].toString(),
    1.79 +            "function on"+eventName+"(event) {\n"+eventName+"2\n}",
    1.80 +            "Setting on"+eventName+"attribute on body outside the document should propagate to window");
    1.81 +}
    1.82 +
    1.83 +testPropagationToWindow("popstate");
    1.84 +testPropagationToWindow("scroll");
    1.85 +
    1.86 +// Test |this| and scoping
    1.87 +var called;
    1.88 +div.onscroll = function(event) {
    1.89 +  is(this, div, "This should be div when invoking event listener");
    1.90 +  is(event, ev, "Event argument should be the event that was dispatched");
    1.91 +  called = true;
    1.92 +}
    1.93 +var ev = document.createEvent("Events");
    1.94 +ev.initEvent("scroll", true, true);
    1.95 +called = false;
    1.96 +div.dispatchEvent(ev);
    1.97 +is(called, true, "Event listener set via on* property not called");
    1.98 +
    1.99 +div.foopy = "Found me";
   1.100 +document.foopy = "Didn't find me";
   1.101 +document.foopy2 = "Found me";
   1.102 +div.setAttribute("onscroll",
   1.103 +                 "is(this, div, 'This should be div when invoking via attribute');\
   1.104 +                  is(foopy, 'Found me', 'div should be on the scope chain when invoking handler compiled from content attribute');\
   1.105 +                  is(foopy2, 'Found me', 'document should be on the scope chain when invking handler compiled from content attribute');\
   1.106 +                  is(event, ev, 'Event argument should be the event that was dispatched');\
   1.107 +                  called = true;");
   1.108 +called = false;
   1.109 +div.dispatchEvent(ev);
   1.110 +is(called, true, "Event listener set via on* attribute not called");
   1.111 +</script>
   1.112 +</pre>
   1.113 +</body>
   1.114 +</html>

mercurial