michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let TargetFactory = gDevTools.TargetFactory; michael@0: michael@0: let tempScope = {}; michael@0: Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope); michael@0: let console = tempScope.console; michael@0: Components.utils.import("resource://gre/modules/Promise.jsm", tempScope); michael@0: let promise = tempScope.Promise; michael@0: michael@0: let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: let TargetFactory = devtools.TargetFactory; michael@0: michael@0: gDevTools.testing = true; michael@0: SimpleTest.registerCleanupFunction(() => { michael@0: gDevTools.testing = false; michael@0: }); michael@0: michael@0: /** michael@0: * Open a new tab at a URL and call a callback on load michael@0: */ michael@0: function addTab(aURL, aCallback) michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: if (aURL != null) { michael@0: content.location = aURL; michael@0: } michael@0: michael@0: let deferred = promise.defer(); michael@0: michael@0: let tab = gBrowser.selectedTab; michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: let browser = gBrowser.getBrowserForTab(tab); michael@0: michael@0: function onTabLoad() { michael@0: browser.removeEventListener("load", onTabLoad, true); michael@0: michael@0: if (aCallback != null) { michael@0: aCallback(browser, tab, browser.contentDocument); michael@0: } michael@0: michael@0: deferred.resolve({ browser: browser, tab: tab, target: target }); michael@0: } michael@0: michael@0: browser.addEventListener("load", onTabLoad, true); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function tearDown() { michael@0: while (gBrowser.tabs.length > 1) { michael@0: gBrowser.removeCurrentTab(); michael@0: } michael@0: }); michael@0: michael@0: function synthesizeKeyFromKeyTag(aKeyId, document) { michael@0: let key = document.getElementById(aKeyId); michael@0: isnot(key, null, "Successfully retrieved the node"); michael@0: michael@0: let modifiersAttr = key.getAttribute("modifiers"); michael@0: michael@0: let name = null; michael@0: michael@0: if (key.getAttribute("keycode")) michael@0: name = key.getAttribute("keycode"); michael@0: else if (key.getAttribute("key")) michael@0: name = key.getAttribute("key"); michael@0: michael@0: isnot(name, null, "Successfully retrieved keycode/key"); michael@0: michael@0: let modifiers = { michael@0: shiftKey: modifiersAttr.match("shift"), michael@0: ctrlKey: modifiersAttr.match("ctrl"), michael@0: altKey: modifiersAttr.match("alt"), michael@0: metaKey: modifiersAttr.match("meta"), michael@0: accelKey: modifiersAttr.match("accel") michael@0: } michael@0: michael@0: EventUtils.synthesizeKey(name, modifiers); michael@0: }