Auto merge of #15359 - freeatnet:15332-macroed-event-handlers-check-for-window, r=KiChjang

Event handlers forwarded to a window check for window presence

<!-- Please describe your changes on the following line: -->
This change adds a check for the presence of a window in event handlers of `body` and `frameset` that are forwarded to the window.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15332

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

I'm new to both Servo and Rust — so any suggestions for improvement are very welcome.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15359)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-03 13:10:50 -08:00 committed by GitHub
commit 8926db302a
6 changed files with 119 additions and 13 deletions

View file

@ -45890,6 +45890,12 @@
"path": "html/semantics/embedded-content/the-img-element/not-rendered-dimension-getter.html",
"url": "/html/semantics/embedded-content/the-img-element/not-rendered-dimension-getter.html"
}
],
"html/webappapis/scripting/events/body-exposed-window-event-handlers.html": [
{
"path": "html/webappapis/scripting/events/body-exposed-window-event-handlers.html",
"url": "/html/webappapis/scripting/events/body-exposed-window-event-handlers.html"
}
]
}
},

View file

@ -0,0 +1,49 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<body></body>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var elements = ['body', 'frameset'];
var handlers = [
'load', 'resize', 'blur', 'focus', 'scroll',
'afterprint', 'beforeprint', 'beforeunload', 'hashchange',
'languagechange', 'message', 'offline', 'online', 'pagehide',
'pageshow', 'popstate', 'rejectionhandled', 'storage',
'unhandledrejection', 'unload'];
elements.forEach(function (elementName) {
handlers.forEach(function (eventName) {
var handlerName = "on" + eventName;
test(function() {
var windowHandler = function () { return "Handler attached to the window"; };
window[handlerName] = windowHandler;
var d = (new DOMParser).parseFromString('', 'text/html');
var b = d.createElement(elementName);
assert_equals(b[handlerName], null);
window[handlerName] = null;
}, "Return null when getting the " + eventName + " event handler of a windowless " + elementName);
test(function() {
var windowHandler = function () { return "Handler attached to the window"; };
window[handlerName] = windowHandler;
var d = (new DOMParser).parseFromString('', 'text/html');
var b = d.createElement(elementName);
b[handlerName] = function() { return "Handler attached to windowless element"; };
assert_equals(window[handlerName], windowHandler);
assert_equals(b[handlerName], null);
// Clean up window event handler
window[handlerName] = null;
}, "Ignore setting of " + eventName + " window event handlers on windowless " + elementName);
});
});
</script>