1 const utils = require("utils");
2 const { module } = utils;
4 var jumlib = module("resource://mozmill/modules/jum.js");
5 var dactyllib = module("dactyl");
7 const { Services } = module("resource://gre/modules/Services.jsm");
9 var setupModule = function (module) {
10 controller = mozmill.getBrowserController();
11 dactyl = new dactyllib.Controller(controller);
14 var teardownModule = function (module) {
18 var setupTest = function (test) {
19 dactyl.runViCommand([["VK_ESCAPE"]]);
22 function urlTarget(url) Services.io.newChannel(url, null, null).name;
24 __defineGetter__("doesNotExist", function () {
25 delete this.doesNotExist;
26 return this.doesNotExist = urlTarget("dactyl://help-tag/non-existent-help-tag-url-thingy");
29 const HELP_FILES = ["all", "tutorial", "intro", "starting", "browsing",
30 "buffer", "cmdline", "editing", "options", "pattern", "tabs", "hints",
31 "map", "eval", "marks", "repeat", "autocommands", "print", "gui",
32 "styling", "message", "privacy", "developer", "various", "plugins", "faq",
35 var testViHelpCommand_OpensIntroHelpPage = function () {
36 assertHelpOpensPageWithTag({
37 HELP_COMMAND: function () { dactyl.runViCommand([["VK_F1"]]); },
38 EXPECTED_HELP_TAG: "intro.xml"
42 var testViHelpAllCommand_OpensAllHelpPage = function () {
43 assertHelpOpensPageWithTag({
44 HELP_COMMAND: function () { dactyl.runViCommand([["VK_F1", { altKey: true }]]); },
45 EXPECTED_HELP_TAG: "all.xml"
49 var testExHelpCommand_NoArgs_OpensIntroHelpPage = function () {
50 assertHelpOpensPageWithTag({
51 HELP_COMMAND: function () { dactyl.runExCommand("help"); },
52 EXPECTED_HELP_TAG: "intro.xml"
56 var testExHelpAllCommand_NoArgs_OpensAllHelpPage = function () {
57 assertHelpOpensPageWithTag({
58 HELP_COMMAND: function () { dactyl.runExCommand("helpall"); },
59 EXPECTED_HELP_TAG: "all.xml"
63 var testExHelpCommand_PageTagArg_OpensHelpPageContainingTag = function () {
64 for (let [, file] in Iterator(HELP_FILES)) {
65 let tag = file + ".xml";
66 assertHelpOpensPageWithTag({
67 HELP_COMMAND: function () { dactyl.runExCommand("help " + tag); },
68 EXPECTED_HELP_TAG: tag
71 let links = controller.tabs.activeTab.querySelectorAll("a[href^='dactyl:']");
73 let missing = Array.filter(links, function (link) urlTarget(link.href) === doesNotExist)
74 .map(function (link) link.textContent + " -> " + link.href);
76 utils.assertEqual("testHelpCommands.assertNoDeadLinks", 0, missing.length,
77 "Found dead links in " + tag + ": " + missing.join(", "));
81 function assertHelpOpensPageWithTag({ HELP_COMMAND, EXPECTED_HELP_TAG }) {
83 controller.waitForPageLoad(controller.tabs.activeTab);
84 controller.assertNode(new elementslib.ID(controller.tabs.activeTab, EXPECTED_HELP_TAG));