Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: LayoutTests/fast/html/eventhandler-attribute-non-callable.html

Issue 22687002: Treat non-callable input as null for EventHandler attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take Kentaro's feedback into consideration Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7753760848f0e97e0fa157b7fc34689c089c1aec
--- /dev/null
+++ b/LayoutTests/fast/html/eventhandler-attribute-non-callable.html
@@ -0,0 +1,50 @@
+<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>
+</head>
+<body>
+<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;
arv (Not doing code reviews) 2013/08/08 14:41:28 A general tip for cases like this is to use a coun
+
+function callback() {
+ wasCallbackCalled = true;
+}
+
+function dispatchKeyEvent()
+{
+ var event = document.createEvent("KeyboardEvent");
arv (Not doing code reviews) 2013/08/08 14:41:28 I always prefer new FooEvent since the initFooEven
+ 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 = {};
+Object.defineProperty(o, 'handleEvent', callback);
arv (Not doing code reviews) 2013/08/08 14:41:28 This is incorrect usage of the defineProperty API.
+shouldNotBe('div.onkeydown', 'null');
+shouldNotThrow('div.onkeydown = o');
+shouldBeNull('div.onkeydown');
+wasCallbackCalled = false;
+dispatchKeyEvent();
+shouldBeFalse('wasCallbackCalled');
+
+// Test null assignment.
+shouldNotThrow('div.onkeydown = callback');
+shouldBe('div.onkeydown', 'callback');
+shouldNotThrow('div.onkeydown = null');
+shouldBeNull('div.onkeydown');
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698