Add a test for accesskey in regard to iframes.
authorhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Sep 2011 03:57:39 +0000 (03:57 +0000)
committerhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Sep 2011 03:57:39 +0000 (03:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67642

Reviewed by Hajime Morita.

To catch any improvement of accesskey behavior in regard to
iframes, it'd be nice to add a test to verify the current behavior.

* fast/dom/access-key-iframe-expected.txt: Added.
* fast/dom/access-key-iframe.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96292 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/access-key-iframe-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/access-key-iframe.html [new file with mode: 0644]

index 952a6c8..cabdf04 100644 (file)
@@ -1,3 +1,16 @@
+2011-09-28  Hayato Ito  <hayato@chromium.org>
+
+        Add a test for accesskey in regard to iframes.
+        https://bugs.webkit.org/show_bug.cgi?id=67642
+
+        Reviewed by Hajime Morita.
+
+        To catch any improvement of accesskey behavior in regard to
+        iframes, it'd be nice to add a test to verify the current behavior.
+
+        * fast/dom/access-key-iframe-expected.txt: Added.
+        * fast/dom/access-key-iframe.html: Added.
+
 2011-09-28  Kent Tamura  <tkent@chromium.org>
 
         REGRESSION(r93858): Can't type anything into input elements when maxlength is greater than 2^31
diff --git a/LayoutTests/fast/dom/access-key-iframe-expected.txt b/LayoutTests/fast/dom/access-key-iframe-expected.txt
new file mode 100644 (file)
index 0000000..a8bfb71
--- /dev/null
@@ -0,0 +1,22 @@
+Tests to ensure that accesskey works in iframes and other iframes don't effect current accesskey maps.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Accesskeys should work in an iframe. "iframe1" has both "inputG" and "inputH" (accesskey="c") elements.
+PASS iframe1.contentDocument.getElementById("inputG").focus(); pressAccessKey("c"); targetsOfFocusEvents is ["inputG", "inputH"]
+
+"inputC" element has an accessKey of "a" and other iframes also have elements with accesskey of "a". An acccesskey should not be overridden by other iframes, so "inputC" should be selected.
+PASS document.getElementById("inputB").focus(); pressAccessKey("a"); targetsOfFocusEvents; is ["inputB", "inputC"]
+
+A child iframe, iframe1, has an element with accesskey of "d", which should be ignored.
+PASS document.getElementById("inputB").focus(); pressAccessKey("d"); targetsOfFocusEvents is ["inputB"]
+
+An accesskey defined in an ancestor iframe should be ignored. "inputD" has accesskey of "b", which should not be selected from descendant iframes, iframe1 and iframe2.
+PASS iframe1.contentDocument.getElementById("inputG").focus(); pressAccessKey("b"); targetsOfFocusEvents is ["inputG"]
+PASS iframe2.contentDocument.getElementById("inputK").focus(); pressAccessKey("b"); targetsOfFocusEvents is ["inputK"]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/access-key-iframe.html b/LayoutTests/fast/dom/access-key-iframe.html
new file mode 100644 (file)
index 0000000..4baa233
--- /dev/null
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../js/resources/js-test-pre.js"></script>
+<p id="description"></p>
+<div id="sandbox"></div>
+<pre id="console"></pre>
+<script>
+description("Tests to ensure that accesskey works in iframes and other iframes don't effect current accesskey maps.");
+
+function pressAccessKey(key)
+{
+    if (navigator.userAgent.search(/\bMac OS X\b/) != -1)
+        modifiers = ["ctrlKey", "altKey"];
+    else
+        modifiers = ["altKey"];
+    eventSender.keyDown(key, modifiers);
+}
+
+var targetsOfFocusEvents = [];
+
+function clearEventRecords()
+{
+    targetsOfFocusEvents = [];
+}
+
+function recordFocusEvent(event)
+{
+    if (event.type == 'focus')
+        targetsOfFocusEvents.push(event.target.id);
+}
+
+function createDomInDocument(doc, tagName, attributes)
+{
+    var element = doc.createElement(tagName);
+    for (var name in attributes)
+        element.setAttribute(name, attributes[name]);
+
+    if (attributes['id'])
+        element.addEventListener('focus', recordFocusEvent, false);
+    return element;
+}
+
+function test()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var sandbox = document.getElementById('sandbox');
+    sandbox.appendChild(createDomInDocument(document, 'input', {'id': 'inputB'}));
+    sandbox.appendChild(createDomInDocument(document, 'input', {'id': 'inputC', 'accesskey': 'a'}));
+    sandbox.appendChild(createDomInDocument(document, 'input', {'id': 'inputD', 'accesskey': 'b'}));
+    sandbox.appendChild(createDomInDocument(document, 'input', {'id': 'inputE', 'accesskey': 'c'}));
+
+    window.iframe1 = document.createElement('iframe');
+    sandbox.appendChild(iframe1);
+    iframe1.contentDocument.body.appendChild(createDomInDocument(iframe1.contentDocument, 'input', {'id': 'inputG', 'accesskey': 'a'}));
+    iframe1.contentDocument.body.appendChild(createDomInDocument(iframe1.contentDocument, 'input', {'id': 'inputH', 'accesskey': 'c'}));
+    iframe1.contentDocument.body.appendChild(createDomInDocument(iframe1.contentDocument, 'input', {'id': 'inputI', 'accesskey': 'd'}));
+
+    window.iframe2 = iframe1.contentDocument.createElement('iframe');
+    iframe1.contentDocument.body.appendChild(iframe2);
+    iframe2.contentDocument.body.appendChild(createDomInDocument(iframe2.contentDocument, 'input', {'id': 'inputK'}));
+    iframe2.contentDocument.body.appendChild(createDomInDocument(iframe2.contentDocument, 'input', {'id': 'inputL', 'accesskey': 'a'}));
+
+    debug('Accesskeys should work in an iframe. "iframe1" has both "inputG" and "inputH" (accesskey="c") elements.');
+    clearEventRecords();
+    shouldBe('iframe1.contentDocument.getElementById("inputG").focus(); pressAccessKey("c"); targetsOfFocusEvents', '["inputG", "inputH"]');
+
+    debug('\n"inputC" element has an accessKey of "a" and other iframes also have elements with accesskey of "a". An acccesskey should not be overridden by other iframes, so "inputC" should be selected.');
+    clearEventRecords();
+    shouldBe('document.getElementById("inputB").focus(); pressAccessKey("a"); targetsOfFocusEvents;', '["inputB", "inputC"]');
+
+    debug('\nA child iframe, iframe1, has an element with accesskey of "d", which should be ignored.');
+    clearEventRecords();
+    shouldBe('document.getElementById("inputB").focus(); pressAccessKey("d"); targetsOfFocusEvents', '["inputB"]');
+
+    debug('\nAn accesskey defined in an ancestor iframe should be ignored. "inputD" has accesskey of "b", which should not be selected from descendant iframes, iframe1 and iframe2.');
+    clearEventRecords();
+    shouldBe('iframe1.contentDocument.getElementById("inputG").focus(); pressAccessKey("b"); targetsOfFocusEvents', '["inputG"]');
+    clearEventRecords();
+    shouldBe('iframe2.contentDocument.getElementById("inputK").focus(); pressAccessKey("b"); targetsOfFocusEvents', '["inputK"]');
+}
+
+test();
+
+var successfullyParsed = true;
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>