|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const { InspectorService } = require("../lib/inspector-service"); |
| 4 | + |
| 5 | +const { Cu } = require("chrome"); |
| 6 | +const { getMostRecentBrowserWindow } = require("sdk/window/utils"); |
| 7 | + |
| 8 | +// DevTools |
| 9 | +const { gDevTools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); |
| 10 | +const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
| 11 | + |
| 12 | +function showToolbox(toolId) { |
| 13 | + let browser = getMostRecentBrowserWindow(); |
| 14 | + let tab = browser.gBrowser.mCurrentTab; |
| 15 | + let target = devtools.TargetFactory.forTab(tab); |
| 16 | + return gDevTools.showToolbox(target, toolId); |
| 17 | +} |
| 18 | + |
| 19 | +function formatException(e) { |
| 20 | + return `\n\t${e.fileName}:${e.lineNumber}\n\t${e}`; |
| 21 | +} |
| 22 | + |
| 23 | +exports["test InspectorService"] = function(assert, done) { |
| 24 | + showToolbox("webconsole").then((toolbox) => { |
| 25 | + assert.ok(toolbox, "toolbox should be defined"); |
| 26 | + |
| 27 | + InspectorService.getInspectorClients(toolbox).then((inspectorClients) => { |
| 28 | + assert.ok(inspectorClients, "inspectorClients should be defined"); |
| 29 | + assert.deepEqual(Object.keys(inspectorClients), ["global", "tab"], |
| 30 | + "global and tab keys should be defined"); |
| 31 | + let { global, tab } = inspectorClients; |
| 32 | + assert.equal(typeof global.getActors, "function", "global.getActors function is defined"); |
| 33 | + assert.equal(typeof tab.getActors, "function", "tab.getActors function is defined"); |
| 34 | + |
| 35 | + Promise.all([global.getActors(), tab.getActors()]).then(([tabActors, globalActors]) => { |
| 36 | + const EXPECTED_ACTOR_KEYS = ["actorPool", "extraPools", "factories", "from"]; |
| 37 | + |
| 38 | + assert.deepEqual(Object.keys(globalActors), EXPECTED_ACTOR_KEYS, "globalActors should have the expected attributes"); |
| 39 | + assert.deepEqual(Object.keys(tabActors), EXPECTED_ACTOR_KEYS, "tabActors should have the expected attributes"); |
| 40 | + |
| 41 | + done(); |
| 42 | + }).catch((e) => { |
| 43 | + assert.fail(`Exception catched during getActors: ${formatException(e)}`); |
| 44 | + done(); |
| 45 | + }); |
| 46 | + }).catch((e) => { |
| 47 | + assert.fail(`Exception catched during getInspectorClients: ${formatException(e)}`); |
| 48 | + done(); |
| 49 | + }); |
| 50 | + }).catch((e) => { |
| 51 | + assert.fail(`Exception catched during showToolbox: ${formatException(e)}`); |
| 52 | + done(); |
| 53 | + }); |
| 54 | +}; |
| 55 | + |
| 56 | +require("sdk/test").run(exports); |
0 commit comments