browser/devtools/scratchpad/test/browser_scratchpad_ui.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:86a938012869
1 /* vim: set ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
4
5 function test()
6 {
7 waitForExplicitFinish();
8
9 gBrowser.selectedTab = gBrowser.addTab();
10 gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
11 gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
12 openScratchpad(runTests);
13 }, true);
14
15 content.location = "data:text/html,<title>foobarBug636725</title>" +
16 "<p>test inspect() in Scratchpad";
17 }
18
19 function runTests()
20 {
21 let sp = gScratchpadWindow.Scratchpad;
22 let doc = gScratchpadWindow.document;
23
24 let methodsAndItems = {
25 "sp-menu-newscratchpad": "openScratchpad",
26 "sp-menu-open": "openFile",
27 "sp-menu-save": "saveFile",
28 "sp-menu-saveas": "saveFileAs",
29 "sp-text-run": "run",
30 "sp-text-inspect": "inspect",
31 "sp-text-display": "display",
32 "sp-text-reloadAndRun": "reloadAndRun",
33 "sp-menu-content": "setContentContext",
34 "sp-menu-browser": "setBrowserContext",
35 "sp-menu-pprint": "prettyPrint",
36 "sp-menu-line-numbers": "toggleEditorOption",
37 "sp-menu-word-wrap": "toggleEditorOption",
38 "sp-menu-highlight-trailing-space": "toggleEditorOption",
39 "sp-menu-larger-font": "increaseFontSize",
40 "sp-menu-smaller-font": "decreaseFontSize",
41 "sp-menu-normal-size-font": "normalFontSize",
42 };
43
44 let lastMethodCalled = null;
45
46 for (let id in methodsAndItems) {
47 lastMethodCalled = null;
48
49 let methodName = methodsAndItems[id];
50 let oldMethod = sp[methodName];
51 ok(oldMethod, "found method " + methodName + " in Scratchpad object");
52
53 sp[methodName] = () => {
54 lastMethodCalled = methodName;
55 }
56
57 let menu = doc.getElementById(id);
58 ok(menu, "found menuitem #" + id);
59
60 try {
61 menu.doCommand();
62 }
63 catch (ex) {
64 ok(false, "exception thrown while executing the command of menuitem #" + id);
65 }
66
67 ok(lastMethodCalled == methodName,
68 "method " + methodName + " invoked by the associated menuitem");
69
70 sp[methodName] = oldMethod;
71 }
72
73 finish();
74 }

mercurial