browser/devtools/scratchpad/test/browser_scratchpad_ui.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_ui.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +function test()
     1.9 +{
    1.10 +  waitForExplicitFinish();
    1.11 +
    1.12 +  gBrowser.selectedTab = gBrowser.addTab();
    1.13 +  gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    1.14 +    gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    1.15 +    openScratchpad(runTests);
    1.16 +  }, true);
    1.17 +
    1.18 +  content.location = "data:text/html,<title>foobarBug636725</title>" +
    1.19 +    "<p>test inspect() in Scratchpad";
    1.20 +}
    1.21 +
    1.22 +function runTests()
    1.23 +{
    1.24 +  let sp = gScratchpadWindow.Scratchpad;
    1.25 +  let doc = gScratchpadWindow.document;
    1.26 +
    1.27 +  let methodsAndItems = {
    1.28 +    "sp-menu-newscratchpad": "openScratchpad",
    1.29 +    "sp-menu-open": "openFile",
    1.30 +    "sp-menu-save": "saveFile",
    1.31 +    "sp-menu-saveas": "saveFileAs",
    1.32 +    "sp-text-run": "run",
    1.33 +    "sp-text-inspect": "inspect",
    1.34 +    "sp-text-display": "display",
    1.35 +    "sp-text-reloadAndRun": "reloadAndRun",
    1.36 +    "sp-menu-content": "setContentContext",
    1.37 +    "sp-menu-browser": "setBrowserContext",
    1.38 +    "sp-menu-pprint": "prettyPrint",
    1.39 +    "sp-menu-line-numbers": "toggleEditorOption",
    1.40 +    "sp-menu-word-wrap": "toggleEditorOption",
    1.41 +    "sp-menu-highlight-trailing-space": "toggleEditorOption",
    1.42 +    "sp-menu-larger-font": "increaseFontSize",
    1.43 +    "sp-menu-smaller-font": "decreaseFontSize",
    1.44 +    "sp-menu-normal-size-font": "normalFontSize",
    1.45 +  };
    1.46 +
    1.47 +  let lastMethodCalled = null;
    1.48 +
    1.49 +  for (let id in methodsAndItems) {
    1.50 +    lastMethodCalled = null;
    1.51 +
    1.52 +    let methodName = methodsAndItems[id];
    1.53 +    let oldMethod = sp[methodName];
    1.54 +    ok(oldMethod, "found method " + methodName + " in Scratchpad object");
    1.55 +
    1.56 +    sp[methodName] = () => {
    1.57 +      lastMethodCalled = methodName;
    1.58 +    }
    1.59 +
    1.60 +    let menu = doc.getElementById(id);
    1.61 +    ok(menu, "found menuitem #" + id);
    1.62 +
    1.63 +    try {
    1.64 +      menu.doCommand();
    1.65 +    }
    1.66 +    catch (ex) {
    1.67 +      ok(false, "exception thrown while executing the command of menuitem #" + id);
    1.68 +    }
    1.69 +
    1.70 +    ok(lastMethodCalled == methodName,
    1.71 +       "method " + methodName + " invoked by the associated menuitem");
    1.72 +
    1.73 +    sp[methodName] = oldMethod;
    1.74 +  }
    1.75 +
    1.76 +  finish();
    1.77 +}

mercurial