Add a layout test for the case where an accesskey is defined in shadow DOM.
authorhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Sep 2011 18:14:59 +0000 (18:14 +0000)
committerhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Sep 2011 18:14:59 +0000 (18:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67096

Reviewed by Dimitri Glazkov.

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

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

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

index 844c85ee74923ef5a1573778d2894f51a073311c..adb8829fadbfad681f137f84455a51bf225d21cc 100644 (file)
@@ -1,3 +1,14 @@
+2011-09-08  Hayato Ito  <hayato@chromium.org>
+
+        Add a layout test for the case where an accesskey is defined in shadow DOM.
+
+        https://bugs.webkit.org/show_bug.cgi?id=67096
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/dom/shadow/access-key-expected.txt: Added.
+        * fast/dom/shadow/access-key.html: Added.
+
 2011-09-08  Alexey Proskuryakov  <ap@apple.com>
 
         Some file-url-mimetypes subtests fail on rare extensions
diff --git a/LayoutTests/fast/dom/shadow/access-key-expected.txt b/LayoutTests/fast/dom/shadow/access-key-expected.txt
new file mode 100644 (file)
index 0000000..3f58fac
--- /dev/null
@@ -0,0 +1,13 @@
+Tests to ensure that accesskey works in regard to shadow DOM boundary. Can only run within DRT.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+PASS dispatchedEvent("focus") is ["inputE"]
+PASS dispatchedEvent("focus") is ["inputE"]
+PASS dispatchedEvent("focus") is ["inputE"]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/shadow/access-key.html b/LayoutTests/fast/dom/shadow/access-key.html
new file mode 100644 (file)
index 0000000..e7e46bf
--- /dev/null
@@ -0,0 +1,111 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="resources/create-dom.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="sandbox"></div>
+<pre id="console"></pre>
+<script>
+description("Tests to ensure that accesskey works in regard to shadow DOM boundary. Can only run within DRT.");
+
+function pressAccessKey(key)
+{
+    if (navigator.userAgent.search(/\bMac OS X\b/) != -1)
+        modifiers = ["ctrlKey", "altKey"];
+    else
+        modifiers = ["altKey"];
+    eventSender.keyDown(key, modifiers);
+}
+
+var eventRecords = {};
+
+function clearEventRecords()
+{
+    eventRecords = {};
+}
+
+function dispatchedEvent(eventType)
+{
+    var events = eventRecords[eventType];
+    if (!events)
+        return [];
+    return events;
+}
+
+function recordEvent(event)
+{
+    var eventType = event.type
+    if (!eventRecords[eventType]) {
+        eventRecords[eventType] = []
+    }
+    eventRecords[eventType].push(event.target.id);
+}
+
+function getElementInShadow(path)
+{
+    var ids = path.split('/');
+    var element = document.getElementById(ids[0]);
+    for (var i = 1; element != null && i < ids.length; ++i) {
+        var shadowRoot = internals.shadowRoot(element);
+        element = internals.getElementByIdInShadowRoot(shadowRoot, ids[i]);
+    }
+    return element;
+}
+
+function prepareDomTree(parent)
+{
+    parent.appendChild(
+        createDom('div', {'id': 'divA'},
+                  createDom('input', {'id': 'inputB'}),
+                  createShadow('div', {'id': 'shadowC', 'tabindex': 0},
+                               createDom('input', {'id': 'inputD'}),
+                               createDom('input', {'id': 'inputE', 'accesskey': 'a'}),
+                               createShadow('div', {'id': 'shadowF', 'tabindex': 0},
+                                            createDom('input', {'id': 'inputG'})))));
+
+    var ids = ['inputB',
+               'shadowC/inputD', 'shadowC/inputE',
+               'shadowC/shadowF/inputG'];
+    for (var i = 0; i < ids.length; ++i) {
+        var element = getElementInShadow(ids[i]);
+        element.addEventListener('focus', recordEvent, false);
+    }
+}
+
+function test()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    prepareDomTree(document.getElementById('sandbox'));
+
+    // Please see the discussion of https://bugs.webkit.org/show_bug.cgi?id=67096.
+    // We don't have a clear idea how accesskey should work in regard to shadow DOM.
+    // In current implementation, accesskeys defined inside of components are exposed to an outer document.
+    // Every accesskeys are flattened per each document.
+    document.getElementById('inputB').focus();
+    clearEventRecords();
+    pressAccessKey('a');
+    shouldBe('dispatchedEvent("focus")', '["inputE"]');
+
+    getElementInShadow('shadowC/inputD').focus();
+    clearEventRecords();
+    pressAccessKey('a');
+    shouldBe('dispatchedEvent("focus")', '["inputE"]');
+
+    getElementInShadow('shadowC/shadowF/inputG').focus();
+    clearEventRecords();
+    pressAccessKey('a');
+    shouldBe('dispatchedEvent("focus")', '["inputE"]');
+}
+
+test();
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>