Index: LayoutTests/fast/html/eventhandler-attribute-non-callable.html |
diff --git a/LayoutTests/fast/html/eventhandler-attribute-non-callable.html b/LayoutTests/fast/html/eventhandler-attribute-non-callable.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d09bedcfa974ac8ab639d81f06276ee4469fc714 |
--- /dev/null |
+++ b/LayoutTests/fast/html/eventhandler-attribute-non-callable.html |
@@ -0,0 +1,44 @@ |
+<html> |
+<head> |
+<link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#eventhandler"> |
+<script src="../js/resources/js-test-pre.js"></script> |
+<body> |
haraken
2013/08/08 13:57:35
Super Nit: </head> is missing.
do-not-use
2013/08/08 14:05:48
Done.
|
+<div id="div"></div> |
+<script> |
+description("This test checks that EventHandler attributes only accept JS functions as input."); |
+ |
+var div = document.getElementById("div"); |
+var wasCallbackCalled = false; |
+ |
+function callback() { |
+ wasCallbackCalled = true; |
+} |
+ |
+function dispatchKeyEvent() |
+{ |
+ var event = document.createEvent("KeyboardEvent"); |
+ event.initKeyboardEvent("keydown", true, true, null, "Enter", ""); |
+ div.dispatchEvent(event); |
+} |
+ |
+// Input is a JS function, this should work. |
+shouldBeNull('div.onkeydown'); |
+shouldNotThrow('div.onkeydown = callback'); |
+shouldBe('div.onkeydown', 'callback'); |
+dispatchKeyEvent(); |
+shouldBeTrue('wasCallbackCalled'); |
+ |
+// Non callable input should be treated as null. |
+var o = {}; |
+o.__defineGetter__("handleEvent", callback); |
haraken
2013/08/08 13:55:47
We want to use Object.defineProperty()
do-not-use
2013/08/08 14:05:48
Done.
|
+shouldNotBe('div.onkeydown', 'null'); |
+shouldNotThrow('div.onkeydown = o'); |
+shouldBeNull('div.onkeydown'); |
+wasCallbackCalled = false; |
+dispatchKeyEvent(); |
+shouldBeFalse('wasCallbackCalled'); |
+ |
haraken
2013/08/08 13:55:47
We might want to add a test case for 'div.onkeydow
do-not-use
2013/08/08 14:05:48
Done.
|
+</script> |
+<script src="../js/resources/js-test-post.js"></script> |
+</body> |
+</html> |