michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test that the markup-view nodes can be navigated to with the keyboard michael@0: michael@0: const TEST_URL = TEST_URL_ROOT + "doc_markup_navigation.html"; michael@0: const TEST_DATA = [ michael@0: ["pageup", "*doctype*"], michael@0: ["down", "html"], michael@0: ["down", "head"], michael@0: ["down", "body"], michael@0: ["down", "node0"], michael@0: ["right", "node0"], michael@0: ["down", "node1"], michael@0: ["down", "node2"], michael@0: ["down", "node3"], michael@0: ["down", "*comment*"], michael@0: ["down", "node4"], michael@0: ["right", "node4"], michael@0: ["down", "*text*"], michael@0: ["down", "node5"], michael@0: ["down", "node6"], michael@0: ["down", "*comment*"], michael@0: ["down" , "node7"], michael@0: ["right", "node7"], michael@0: ["down", "*text*"], michael@0: ["down", "node8"], michael@0: ["left", "node7"], michael@0: ["left", "node7"], michael@0: ["right", "node7"], michael@0: ["right", "*text*"], michael@0: ["down", "node8"], michael@0: ["right", "node8"], michael@0: ["left", "node8"], michael@0: ["down", "node9"], michael@0: ["down", "node10"], michael@0: ["down", "node11"], michael@0: ["down", "node12"], michael@0: ["right", "node12"], michael@0: ["down", "*text*"], michael@0: ["down", "node13"], michael@0: ["down", "node14"], michael@0: ["down", "node15"], michael@0: ["down", "node15"], michael@0: ["down", "node15"], michael@0: ["up", "node14"], michael@0: ["up", "node13"], michael@0: ["up", "*text*"], michael@0: ["up", "node12"], michael@0: ["left", "node12"], michael@0: ["down", "node14"], michael@0: ["home", "*doctype*"], michael@0: ["pagedown", "*text*"], michael@0: ["down", "node5"], michael@0: ["down", "node6"], michael@0: ["down", "*comment*"], michael@0: ["down", "node7"], michael@0: ["left", "node7"], michael@0: ["down", "node9"], michael@0: ["down", "node10"], michael@0: ["pageup", "node2"], michael@0: ["pageup", "*doctype*"], michael@0: ["down", "html"], michael@0: ["left", "html"], michael@0: ["down", "html"] michael@0: ]; michael@0: michael@0: let test = asyncTest(function*() { michael@0: let {inspector} = yield addTab(TEST_URL).then(openInspector); michael@0: michael@0: info("Making sure the markup-view frame is focused"); michael@0: inspector.markup._frame.focus(); michael@0: michael@0: info("Starting to iterate through the test data"); michael@0: for (let [key, className] of TEST_DATA) { michael@0: info("Testing step: " + key + " to navigate to " + className); michael@0: pressKey(key); michael@0: michael@0: info("Making sure markup-view children get updated"); michael@0: yield waitForChildrenUpdated(inspector); michael@0: michael@0: info("Checking the right node is selected"); michael@0: checkSelectedNode(key, className, inspector); michael@0: } michael@0: }); michael@0: michael@0: function pressKey(key) { michael@0: switch(key) { michael@0: case "right": michael@0: EventUtils.synthesizeKey("VK_RIGHT", {}); michael@0: break; michael@0: case "down": michael@0: EventUtils.synthesizeKey("VK_DOWN", {}); michael@0: break; michael@0: case "left": michael@0: EventUtils.synthesizeKey("VK_LEFT", {}); michael@0: break; michael@0: case "up": michael@0: EventUtils.synthesizeKey("VK_UP", {}); michael@0: break; michael@0: case "pageup": michael@0: EventUtils.synthesizeKey("VK_PAGE_UP", {}); michael@0: break; michael@0: case "pagedown": michael@0: EventUtils.synthesizeKey("VK_PAGE_DOWN", {}); michael@0: break; michael@0: case "home": michael@0: EventUtils.synthesizeKey("VK_HOME", {}); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: function checkSelectedNode(key, className, inspector) { michael@0: let node = inspector.selection.node; michael@0: michael@0: if (className == "*comment*") { michael@0: is(node.nodeType, Node.COMMENT_NODE, "Found a comment after pressing " + key); michael@0: } else if (className == "*text*") { michael@0: is(node.nodeType, Node.TEXT_NODE, "Found text after pressing " + key); michael@0: } else if (className == "*doctype*") { michael@0: is(node.nodeType, Node.DOCUMENT_TYPE_NODE, "Found the doctype after pressing " + key); michael@0: } else { michael@0: is(node.className, className, "Found node: " + className + " after pressing " + key); michael@0: } michael@0: }