mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1245153 - Employ new modules throughout Marionette; r=automatedtester
This change removes almost all the remaining uses of loadSubScript and global scope pollution. The only remaining use is for common.js, which is resolved by a later bug for evaluating scripts. --HG-- extra : commitid : 8XlX4zVZQUN extra : rebase_source : b5420c4ba5298a7e972e7b14a13325bb8ea1a540 extra : histedit_source : 70f70a8aeffef3fca18addfa3fca575a9128e11a
This commit is contained in:
parent
2d7e73d027
commit
0414e11cb2
@ -7,6 +7,8 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Log.jsm");
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
|
||||
Cu.import("chrome://marionette/content/event.js");
|
||||
|
||||
const CONTEXT_MENU_DELAY_PREF = "ui.click_hold_context_menus.delay";
|
||||
const DEFAULT_CONTEXT_MENU_DELAY = 750; // ms
|
||||
|
||||
@ -19,7 +21,7 @@ this.actions = {};
|
||||
/**
|
||||
* Functionality for (single finger) action chains.
|
||||
*/
|
||||
actions.Chain = function(utils, checkForInterrupted) {
|
||||
actions.Chain = function(checkForInterrupted) {
|
||||
// for assigning unique ids to all touches
|
||||
this.nextTouchId = 1000;
|
||||
// keep track of active Touches
|
||||
@ -43,9 +45,6 @@ actions.Chain = function(utils, checkForInterrupted) {
|
||||
|
||||
// determines if we create touch events
|
||||
this.inputSource = null;
|
||||
|
||||
// test utilities providing some event synthesis code
|
||||
this.utils = utils;
|
||||
};
|
||||
|
||||
actions.Chain.prototype.dispatchActions = function(
|
||||
@ -127,7 +126,7 @@ actions.Chain.prototype.emitMouseEvent = function(
|
||||
|
||||
let mods;
|
||||
if (typeof modifiers != "undefined") {
|
||||
mods = this.utils._parseModifiers(modifiers);
|
||||
mods = event.parseModifiers_(modifiers);
|
||||
} else {
|
||||
mods = 0;
|
||||
}
|
||||
@ -187,12 +186,12 @@ actions.Chain.prototype.actions = function(chain, touchId, i, keyModifiers) {
|
||||
|
||||
switch(command) {
|
||||
case "keyDown":
|
||||
this.utils.sendKeyDown(pack[1], keyModifiers, this.container.frame);
|
||||
event.sendKeyDown(pack[1], keyModifiers, this.container.frame);
|
||||
this.actions(chain, touchId, i, keyModifiers);
|
||||
break;
|
||||
|
||||
case "keyUp":
|
||||
this.utils.sendKeyUp(pack[1], keyModifiers, this.container.frame);
|
||||
event.sendKeyUp(pack[1], keyModifiers, this.container.frame);
|
||||
this.actions(chain, touchId, i, keyModifiers);
|
||||
break;
|
||||
|
||||
|
@ -24,8 +24,11 @@ XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "cookieManager", "@mozilla.org/cookiemanager;1", "nsICookieManager2");
|
||||
|
||||
Cu.import("chrome://marionette/content/actions.js");
|
||||
Cu.import("chrome://marionette/content/atoms.js");
|
||||
Cu.import("chrome://marionette/content/interactions.js");
|
||||
Cu.import("chrome://marionette/content/elements.js");
|
||||
Cu.import("chrome://marionette/content/event.js");
|
||||
Cu.import("chrome://marionette/content/frame-manager.js");
|
||||
Cu.import("chrome://marionette/content/error.js");
|
||||
Cu.import("chrome://marionette/content/modal.js");
|
||||
Cu.import("chrome://marionette/content/proxy.js");
|
||||
@ -33,14 +36,6 @@ Cu.import("chrome://marionette/content/simpletest.js");
|
||||
|
||||
loader.loadSubScript("chrome://marionette/content/common.js");
|
||||
|
||||
// preserve this import order:
|
||||
var utils = {};
|
||||
loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/sendkeys.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/frame-manager.js");
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"];
|
||||
|
||||
var FRAME_SCRIPT = "chrome://marionette/content/listener.js";
|
||||
@ -138,7 +133,7 @@ this.GeckoDriver = function(appName, device, stopSignal, emulator) {
|
||||
this.oopFrameId = null;
|
||||
this.observing = null;
|
||||
this._browserIds = new WeakMap();
|
||||
this.actions = new actions.Chain(utils);
|
||||
this.actions = new actions.Chain();
|
||||
|
||||
this.sessionCapabilities = {
|
||||
// mandated capabilities
|
||||
@ -166,7 +161,7 @@ this.GeckoDriver = function(appName, device, stopSignal, emulator) {
|
||||
"version": Services.appinfo.version,
|
||||
};
|
||||
|
||||
this.interactions = new Interactions(utils, () => this.sessionCapabilities);
|
||||
this.interactions = new Interactions(() => this.sessionCapabilities);
|
||||
|
||||
this.mm = globalMessageManager;
|
||||
this.listener = proxy.toListener(() => this.mm, this.sendAsync.bind(this));
|
||||
@ -354,8 +349,6 @@ GeckoDriver.prototype.startBrowser = function(win, isNewSession=false) {
|
||||
* True if this is the first time we're talking to this browser.
|
||||
*/
|
||||
GeckoDriver.prototype.whenBrowserStarted = function(win, isNewSession) {
|
||||
utils.window = win;
|
||||
|
||||
try {
|
||||
let mm = win.window.messageManager;
|
||||
if (!isNewSession) {
|
||||
@ -390,7 +383,7 @@ GeckoDriver.prototype.whenBrowserStarted = function(win, isNewSession) {
|
||||
*/
|
||||
GeckoDriver.prototype.getVisibleText = function(el, lines) {
|
||||
try {
|
||||
if (utils.isElementDisplayed(el)) {
|
||||
if (atom.isElementDisplayed(el, this.getCurrentWindow())) {
|
||||
if (el.value) {
|
||||
lines.push(el.value);
|
||||
}
|
||||
@ -785,7 +778,6 @@ GeckoDriver.prototype.createExecuteSandbox = function(win, mn, sandboxName) {
|
||||
let sb = new Cu.Sandbox(principal,
|
||||
{sandboxPrototype: win, wantXrays: false, sandboxName: ""});
|
||||
sb.global = sb;
|
||||
sb.testUtils = utils;
|
||||
sb.proto = win;
|
||||
|
||||
mn.exports.forEach(function(fn) {
|
||||
@ -1591,7 +1583,6 @@ GeckoDriver.prototype.switchToWindow = function(cmd, resp) {
|
||||
yield browserListening;
|
||||
}
|
||||
} else {
|
||||
utils.window = found.win;
|
||||
this.curBrowser = this.browsers[found.outerId];
|
||||
|
||||
if ("tabIndex" in found) {
|
||||
@ -2021,7 +2012,7 @@ GeckoDriver.prototype.getElementAttribute = function(cmd, resp) {
|
||||
case Context.CHROME:
|
||||
let win = this.getCurrentWindow();
|
||||
let el = this.curBrowser.elementManager.getKnownElement(id, {frame: win});
|
||||
resp.body.value = utils.getElementAttribute(el, name);
|
||||
resp.body.value = atom.getElementAttribute(el, name, this.getCurrentWindow());
|
||||
break;
|
||||
|
||||
case Context.CONTENT:
|
||||
@ -2797,11 +2788,11 @@ GeckoDriver.prototype.sendKeysToDialog = function(cmd, resp) {
|
||||
}
|
||||
|
||||
let win = this.dialog.window ? this.dialog.window : this.getCurrentWindow();
|
||||
utils.sendKeysToElement(
|
||||
win,
|
||||
loginTextbox,
|
||||
event.sendKeysToElement(
|
||||
cmd.parameters.value,
|
||||
true /* ignore visibility check */);
|
||||
loginTextbox,
|
||||
{ignoreVisibility: true},
|
||||
win);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -3073,7 +3064,7 @@ var BrowserObj = function(win, driver) {
|
||||
this.pendingCommands = [];
|
||||
|
||||
// we should have one FM per BO so that we can handle modals in each Browser
|
||||
this.frameManager = new FrameManager(driver);
|
||||
this.frameManager = new frame.Manager(driver);
|
||||
this.frameRegsPending = 0;
|
||||
|
||||
// register all message listeners
|
||||
|
@ -5,19 +5,21 @@
|
||||
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
var uuidGen = Cc["@mozilla.org/uuid-generator;1"]
|
||||
.getService(Ci.nsIUUIDGenerator);
|
||||
.getService(Ci.nsIUUIDGenerator);
|
||||
|
||||
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Ci.mozIJSSubScriptLoader);
|
||||
.getService(Ci.mozIJSSubScriptLoader);
|
||||
|
||||
loader.loadSubScript("chrome://marionette/content/simpletest.js");
|
||||
loader.loadSubScript("chrome://marionette/content/common.js");
|
||||
|
||||
Cu.import("chrome://marionette/content/actions.js");
|
||||
Cu.import("chrome://marionette/content/atoms.js");
|
||||
Cu.import("chrome://marionette/content/capture.js");
|
||||
Cu.import("chrome://marionette/content/cookies.js");
|
||||
Cu.import("chrome://marionette/content/elements.js");
|
||||
Cu.import("chrome://marionette/content/error.js");
|
||||
Cu.import("chrome://marionette/content/event.js");
|
||||
Cu.import("chrome://marionette/content/proxy.js");
|
||||
Cu.import("chrome://marionette/content/interactions.js");
|
||||
|
||||
@ -25,13 +27,6 @@ Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
var utils = {};
|
||||
utils.window = content;
|
||||
// Load Event/ChromeUtils for use with JS scripts:
|
||||
loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
|
||||
loader.loadSubScript("chrome://marionette/content/sendkeys.js", utils);
|
||||
|
||||
var marionetteLogObj = new MarionetteLogObj();
|
||||
|
||||
@ -48,9 +43,9 @@ var elementManager = new ElementManager([]);
|
||||
|
||||
// Holds session capabilities.
|
||||
var capabilities = {};
|
||||
var interactions = new Interactions(utils, () => capabilities);
|
||||
var interactions = new Interactions(() => capabilities);
|
||||
|
||||
var actions = new actions.Chain(utils, checkForInterrupted);
|
||||
var actions = new actions.Chain(checkForInterrupted);
|
||||
var importedScripts = null;
|
||||
|
||||
// Contains the last file input element that was the target of
|
||||
@ -529,7 +524,6 @@ function createExecuteContentSandbox(win, timeout) {
|
||||
sandbox.window = win;
|
||||
sandbox.document = sandbox.window.document;
|
||||
sandbox.navigator = sandbox.window.navigator;
|
||||
sandbox.testUtils = utils;
|
||||
sandbox.asyncTestCommandId = asyncTestCommandId;
|
||||
sandbox.marionette = mn;
|
||||
|
||||
@ -893,67 +887,13 @@ function coordinates(target, x, y) {
|
||||
return coords;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function returns true if the given coordinates are in the viewport.
|
||||
* @param 'x', and 'y' are the coordinates relative to the target.
|
||||
* If they are not specified, then the center of the target is used.
|
||||
*/
|
||||
function elementInViewport(el, x, y) {
|
||||
let c = coordinates(el, x, y);
|
||||
let curFrame = curContainer.frame;
|
||||
let viewPort = {top: curFrame.pageYOffset,
|
||||
left: curFrame.pageXOffset,
|
||||
bottom: (curFrame.pageYOffset + curFrame.innerHeight),
|
||||
right:(curFrame.pageXOffset + curFrame.innerWidth)};
|
||||
return (viewPort.left <= c.x + curFrame.pageXOffset &&
|
||||
c.x + curFrame.pageXOffset <= viewPort.right &&
|
||||
viewPort.top <= c.y + curFrame.pageYOffset &&
|
||||
c.y + curFrame.pageYOffset <= viewPort.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function throws the visibility of the element error if the element is
|
||||
* not displayed or the given coordinates are not within the viewport.
|
||||
* @param 'x', and 'y' are the coordinates relative to the target.
|
||||
* If they are not specified, then the center of the target is used.
|
||||
*/
|
||||
function checkVisible(el, x, y) {
|
||||
// Bug 1094246 - Webdriver's isShown doesn't work with content xul
|
||||
if (utils.getElementAttribute(el, "namespaceURI").indexOf("there.is.only.xul") == -1) {
|
||||
//check if the element is visible
|
||||
let visible = utils.isElementDisplayed(el);
|
||||
if (!visible) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (el.tagName.toLowerCase() === 'body') {
|
||||
return true;
|
||||
}
|
||||
if (!elementInViewport(el, x, y)) {
|
||||
//check if scroll function exist. If so, call it.
|
||||
if (el.scrollIntoView) {
|
||||
el.scrollIntoView(false);
|
||||
if (!elementInViewport(el)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function that perform a single tap
|
||||
*/
|
||||
function singleTap(id, corx, cory) {
|
||||
let el = elementManager.getKnownElement(id, curContainer);
|
||||
// after this block, the element will be scrolled into view
|
||||
let visible = checkVisible(el, corx, cory);
|
||||
let visible = elements.checkVisible(el, curContainer.frame, corx, cory);
|
||||
if (!visible) {
|
||||
throw new ElementNotVisibleError("Element is not currently visible and may not be manipulated");
|
||||
}
|
||||
@ -1393,7 +1333,7 @@ function clickElement(id) {
|
||||
*/
|
||||
function getElementAttribute(id, name) {
|
||||
let el = elementManager.getKnownElement(id, curContainer);
|
||||
return utils.getElementAttribute(el, name);
|
||||
return atom.getElementAttribute(el, name, curContainer.frame);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1407,7 +1347,7 @@ function getElementAttribute(id, name) {
|
||||
*/
|
||||
function getElementText(id) {
|
||||
let el = elementManager.getKnownElement(id, curContainer);
|
||||
return utils.getElementText(el);
|
||||
return atom.getElementText(el, curContainer.frame);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1511,11 +1451,11 @@ function sendKeysToElement(msg) {
|
||||
// so pass the filename to driver.js, which in turn passes them back
|
||||
// to this frame script in receiveFiles.
|
||||
sendSyncMessage("Marionette:getFiles",
|
||||
{value: p, command_id: command_id});
|
||||
{value: p, command_id: command_id});
|
||||
} else {
|
||||
interactions.sendKeysToElement(curContainer, elementManager, id, val)
|
||||
.then(() => sendOk(command_id))
|
||||
.catch(e => sendError(e, command_id));
|
||||
.then(() => sendOk(command_id))
|
||||
.catch(e => sendError(e, command_id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1528,7 +1468,7 @@ function clearElement(id) {
|
||||
if (el.type == "file") {
|
||||
el.value = null;
|
||||
} else {
|
||||
utils.clearElement(el);
|
||||
atom.clearElement(el, curContainer.frame);
|
||||
}
|
||||
} catch (e) {
|
||||
// Bug 964738: Newer atoms contain status codes which makes wrapping
|
||||
|
@ -23,9 +23,7 @@ loader.loadSubScript("resource://devtools/shared/transport/transport.js");
|
||||
|
||||
// Preserve this import order:
|
||||
var events = {};
|
||||
loader.loadSubScript("chrome://marionette/content/EventUtils.js", events);
|
||||
loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", events);
|
||||
loader.loadSubScript("chrome://marionette/content/frame-manager.js");
|
||||
|
||||
const logger = Log.repository.getLogger("Marionette");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user