2012-03-22 08:19:57 -07:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-05-11 13:06:53 -07:00
|
|
|
let {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
let uuidGen = Cc["@mozilla.org/uuid-generator;1"]
|
|
|
|
.getService(Ci.nsIUUIDGenerator);
|
|
|
|
|
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
2012-03-22 08:19:57 -07:00
|
|
|
|
|
|
|
loader.loadSubScript("chrome://marionette/content/marionette-simpletest.js");
|
|
|
|
loader.loadSubScript("chrome://marionette/content/marionette-log-obj.js");
|
2012-06-10 16:44:50 -07:00
|
|
|
loader.loadSubScript("chrome://marionette/content/marionette-perf.js");
|
2012-05-11 13:06:53 -07:00
|
|
|
Cu.import("chrome://marionette/content/marionette-elements.js");
|
2012-06-04 10:50:06 -07:00
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2012-04-10 17:28:08 -07:00
|
|
|
let utils = {};
|
|
|
|
utils.window = content;
|
2012-05-11 13:06:53 -07:00
|
|
|
// Load Event/ChromeUtils for use with JS scripts:
|
|
|
|
loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils);
|
2012-04-10 17:28:08 -07:00
|
|
|
loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
|
|
|
|
loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
|
2012-08-05 12:49:42 -07:00
|
|
|
loader.loadSubScript("chrome://marionette/content/marionette-sendkeys.js", utils);
|
2012-05-18 13:30:13 -07:00
|
|
|
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js");
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/specialpowers.js");
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
let marionetteLogObj = new MarionetteLogObj();
|
2012-06-10 16:44:50 -07:00
|
|
|
let marionettePerf = new MarionettePerfData();
|
2012-03-22 08:19:57 -07:00
|
|
|
|
|
|
|
let isB2G = false;
|
|
|
|
|
|
|
|
let marionetteTimeout = null;
|
2012-10-31 15:36:57 -07:00
|
|
|
let marionetteTestName;
|
2012-05-11 13:06:53 -07:00
|
|
|
let winUtil = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
2012-03-22 08:19:57 -07:00
|
|
|
let listenerId = null; //unique ID of this listener
|
|
|
|
let activeFrame = null;
|
2012-05-02 07:21:05 -07:00
|
|
|
let curWindow = content;
|
2012-03-22 08:19:57 -07:00
|
|
|
let elementManager = new ElementManager([]);
|
2012-06-04 10:50:06 -07:00
|
|
|
let importedScripts = FileUtils.getFile('TmpD', ['marionettescript']);
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-05-09 12:05:39 -07:00
|
|
|
// The sandbox we execute test scripts in. Gets lazily created in
|
|
|
|
// createExecuteContentSandbox().
|
|
|
|
let sandbox;
|
|
|
|
|
|
|
|
// Flag to indicate whether an async script is currently running or not.
|
|
|
|
let asyncTestRunning = false;
|
|
|
|
let asyncTestCommandId;
|
|
|
|
let asyncTestTimeoutId;
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Called when listener is first started up.
|
|
|
|
* The listener sends its unique window ID and its current URI to the actor.
|
|
|
|
* If the actor returns an ID, we start the listeners. Otherwise, nothing happens.
|
|
|
|
*/
|
|
|
|
function registerSelf() {
|
2012-09-19 13:31:03 -07:00
|
|
|
Services.io.manageOfflineStatus = false;
|
|
|
|
Services.io.offline = false;
|
2012-03-22 08:19:57 -07:00
|
|
|
let register = sendSyncMessage("Marionette:register", {value: winUtil.outerWindowID, href: content.location.href});
|
|
|
|
|
|
|
|
if (register[0]) {
|
|
|
|
listenerId = register[0];
|
|
|
|
startListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-11 13:06:53 -07:00
|
|
|
/**
|
|
|
|
* Add a message listener that's tied to our listenerId.
|
|
|
|
*/
|
|
|
|
function addMessageListenerId(messageName, handler) {
|
|
|
|
addMessageListener(messageName + listenerId, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a message listener that's tied to our listenerId.
|
|
|
|
*/
|
|
|
|
function removeMessageListenerId(messageName, handler) {
|
|
|
|
removeMessageListener(messageName + listenerId, handler);
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Start all message listeners
|
|
|
|
*/
|
|
|
|
function startListeners() {
|
2012-05-11 13:06:53 -07:00
|
|
|
addMessageListenerId("Marionette:newSession", newSession);
|
|
|
|
addMessageListenerId("Marionette:executeScript", executeScript);
|
|
|
|
addMessageListenerId("Marionette:setScriptTimeout", setScriptTimeout);
|
|
|
|
addMessageListenerId("Marionette:executeAsyncScript", executeAsyncScript);
|
|
|
|
addMessageListenerId("Marionette:executeJSScript", executeJSScript);
|
|
|
|
addMessageListenerId("Marionette:setSearchTimeout", setSearchTimeout);
|
|
|
|
addMessageListenerId("Marionette:goUrl", goUrl);
|
|
|
|
addMessageListenerId("Marionette:getUrl", getUrl);
|
2012-07-10 13:30:21 -07:00
|
|
|
addMessageListenerId("Marionette:getTitle", getTitle);
|
2012-08-09 12:31:12 -07:00
|
|
|
addMessageListenerId("Marionette:getPageSource", getPageSource);
|
2012-05-11 13:06:53 -07:00
|
|
|
addMessageListenerId("Marionette:goBack", goBack);
|
|
|
|
addMessageListenerId("Marionette:goForward", goForward);
|
|
|
|
addMessageListenerId("Marionette:refresh", refresh);
|
|
|
|
addMessageListenerId("Marionette:findElementContent", findElementContent);
|
|
|
|
addMessageListenerId("Marionette:findElementsContent", findElementsContent);
|
|
|
|
addMessageListenerId("Marionette:clickElement", clickElement);
|
|
|
|
addMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
|
|
|
|
addMessageListenerId("Marionette:getElementText", getElementText);
|
2012-08-08 13:21:50 -07:00
|
|
|
addMessageListenerId("Marionette:getElementTagName", getElementTagName);
|
2012-05-11 13:06:53 -07:00
|
|
|
addMessageListenerId("Marionette:isElementDisplayed", isElementDisplayed);
|
2012-10-19 13:59:15 -07:00
|
|
|
addMessageListenerId("Marionette:getElementSize", getElementSize);
|
2012-05-11 13:06:53 -07:00
|
|
|
addMessageListenerId("Marionette:isElementEnabled", isElementEnabled);
|
|
|
|
addMessageListenerId("Marionette:isElementSelected", isElementSelected);
|
|
|
|
addMessageListenerId("Marionette:sendKeysToElement", sendKeysToElement);
|
2012-10-19 13:35:30 -07:00
|
|
|
addMessageListenerId("Marionette:getElementPosition", getElementPosition);
|
2012-05-11 13:06:53 -07:00
|
|
|
addMessageListenerId("Marionette:clearElement", clearElement);
|
|
|
|
addMessageListenerId("Marionette:switchToFrame", switchToFrame);
|
|
|
|
addMessageListenerId("Marionette:deleteSession", deleteSession);
|
|
|
|
addMessageListenerId("Marionette:sleepSession", sleepSession);
|
2012-05-18 13:30:43 -07:00
|
|
|
addMessageListenerId("Marionette:emulatorCmdResult", emulatorCmdResult);
|
2012-06-04 10:50:06 -07:00
|
|
|
addMessageListenerId("Marionette:importScript", importScript);
|
2012-08-23 15:07:16 -07:00
|
|
|
addMessageListenerId("Marionette:getAppCacheStatus", getAppCacheStatus);
|
2012-10-31 15:36:57 -07:00
|
|
|
addMessageListenerId("Marionette:setTestName", setTestName);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when we start a new session. It registers the
|
|
|
|
* current environment, and resets all values
|
|
|
|
*/
|
|
|
|
function newSession(msg) {
|
|
|
|
isB2G = msg.json.B2G;
|
|
|
|
resetValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Puts the current session to sleep, so all listeners are removed except
|
|
|
|
* for the 'restart' listener. This is used to keep the content listener
|
|
|
|
* alive for reuse in B2G instead of reloading it each time.
|
|
|
|
*/
|
|
|
|
function sleepSession(msg) {
|
|
|
|
deleteSession();
|
|
|
|
addMessageListener("Marionette:restart", restart);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restarts all our listeners after this listener was put to sleep
|
|
|
|
*/
|
|
|
|
function restart() {
|
|
|
|
removeMessageListener("Marionette:restart", restart);
|
|
|
|
registerSelf();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all listeners
|
|
|
|
*/
|
|
|
|
function deleteSession(msg) {
|
2012-05-11 13:06:53 -07:00
|
|
|
removeMessageListenerId("Marionette:newSession", newSession);
|
|
|
|
removeMessageListenerId("Marionette:executeScript", executeScript);
|
|
|
|
removeMessageListenerId("Marionette:setScriptTimeout", setScriptTimeout);
|
|
|
|
removeMessageListenerId("Marionette:executeAsyncScript", executeAsyncScript);
|
|
|
|
removeMessageListenerId("Marionette:executeJSScript", executeJSScript);
|
|
|
|
removeMessageListenerId("Marionette:setSearchTimeout", setSearchTimeout);
|
|
|
|
removeMessageListenerId("Marionette:goUrl", goUrl);
|
2012-07-10 13:30:21 -07:00
|
|
|
removeMessageListenerId("Marionette:getTitle", getTitle);
|
2012-08-09 12:31:12 -07:00
|
|
|
removeMessageListenerId("Marionette:getPageSource", getPageSource);
|
2012-05-11 13:06:53 -07:00
|
|
|
removeMessageListenerId("Marionette:getUrl", getUrl);
|
|
|
|
removeMessageListenerId("Marionette:goBack", goBack);
|
|
|
|
removeMessageListenerId("Marionette:goForward", goForward);
|
|
|
|
removeMessageListenerId("Marionette:refresh", refresh);
|
|
|
|
removeMessageListenerId("Marionette:findElementContent", findElementContent);
|
|
|
|
removeMessageListenerId("Marionette:findElementsContent", findElementsContent);
|
|
|
|
removeMessageListenerId("Marionette:clickElement", clickElement);
|
|
|
|
removeMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
|
2012-08-08 13:21:50 -07:00
|
|
|
removeMessageListenerId("Marionette:getElementTagName", getElementTagName);
|
2012-05-11 13:06:53 -07:00
|
|
|
removeMessageListenerId("Marionette:isElementDisplayed", isElementDisplayed);
|
2012-10-19 13:59:15 -07:00
|
|
|
removeMessageListenerId("Marionette:getElementSize", getElementSize);
|
2012-05-11 13:06:53 -07:00
|
|
|
removeMessageListenerId("Marionette:isElementEnabled", isElementEnabled);
|
|
|
|
removeMessageListenerId("Marionette:isElementSelected", isElementSelected);
|
|
|
|
removeMessageListenerId("Marionette:sendKeysToElement", sendKeysToElement);
|
2012-10-19 13:35:30 -07:00
|
|
|
removeMessageListenerId("Marionette:getElementPosition", getElementPosition);
|
2012-05-11 13:06:53 -07:00
|
|
|
removeMessageListenerId("Marionette:clearElement", clearElement);
|
|
|
|
removeMessageListenerId("Marionette:switchToFrame", switchToFrame);
|
|
|
|
removeMessageListenerId("Marionette:deleteSession", deleteSession);
|
|
|
|
removeMessageListenerId("Marionette:sleepSession", sleepSession);
|
2012-05-18 13:30:43 -07:00
|
|
|
removeMessageListenerId("Marionette:emulatorCmdResult", emulatorCmdResult);
|
2012-06-04 10:50:06 -07:00
|
|
|
removeMessageListenerId("Marionette:importScript", importScript);
|
2012-08-23 15:07:16 -07:00
|
|
|
removeMessageListenerId("Marionette:getAppCacheStatus", getAppCacheStatus);
|
2012-10-31 15:36:57 -07:00
|
|
|
removeMessageListenerId("Marionette:setTestName", setTestName);
|
2012-03-22 08:19:57 -07:00
|
|
|
this.elementManager.reset();
|
2012-06-04 10:50:06 -07:00
|
|
|
try {
|
|
|
|
importedScripts.remove(false);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic method to send a message to the server
|
|
|
|
*/
|
|
|
|
function sendToServer(msg, value, command_id) {
|
|
|
|
if (command_id) {
|
|
|
|
value.command_id = command_id;
|
|
|
|
}
|
|
|
|
sendAsyncMessage(msg, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send response back to server
|
|
|
|
*/
|
|
|
|
function sendResponse(value, command_id) {
|
|
|
|
sendToServer("Marionette:done", value, command_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send ack back to server
|
|
|
|
*/
|
|
|
|
function sendOk(command_id) {
|
|
|
|
sendToServer("Marionette:ok", {}, command_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send log message to server
|
|
|
|
*/
|
|
|
|
function sendLog(msg) {
|
|
|
|
sendToServer("Marionette:log", { message: msg });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send error message to server
|
|
|
|
*/
|
|
|
|
function sendError(message, status, trace, command_id) {
|
|
|
|
let error_msg = { message: message, status: status, stacktrace: trace };
|
|
|
|
sendToServer("Marionette:error", error_msg, command_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear test values after completion of test
|
|
|
|
*/
|
|
|
|
function resetValues() {
|
2012-05-09 12:05:39 -07:00
|
|
|
sandbox = null;
|
2012-03-22 08:19:57 -07:00
|
|
|
marionetteTimeout = null;
|
2012-05-02 07:21:05 -07:00
|
|
|
curWin = content;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send error when we detect an unload event during async scripts
|
|
|
|
*/
|
|
|
|
function errUnload() {
|
|
|
|
sendError("unload was called", 17, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Marionette Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a content sandbox that can be used by the execute_foo functions.
|
|
|
|
*/
|
2012-05-09 12:05:39 -07:00
|
|
|
function createExecuteContentSandbox(aWindow) {
|
2012-03-22 08:19:57 -07:00
|
|
|
let sandbox = new Cu.Sandbox(aWindow);
|
2012-05-09 12:05:39 -07:00
|
|
|
sandbox.global = sandbox;
|
2012-03-22 08:19:57 -07:00
|
|
|
sandbox.window = aWindow;
|
|
|
|
sandbox.document = sandbox.window.document;
|
|
|
|
sandbox.navigator = sandbox.window.navigator;
|
|
|
|
sandbox.__proto__ = sandbox.window;
|
2012-04-10 17:28:08 -07:00
|
|
|
sandbox.testUtils = utils;
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-10-31 23:51:30 -07:00
|
|
|
let marionette = new Marionette(this, aWindow, "content",
|
|
|
|
marionetteLogObj, marionettePerf,
|
2012-10-31 15:36:57 -07:00
|
|
|
marionetteTimeout, marionetteTestName);
|
2012-05-09 12:05:39 -07:00
|
|
|
sandbox.marionette = marionette;
|
2012-03-22 08:19:57 -07:00
|
|
|
marionette.exports.forEach(function(fn) {
|
2012-09-14 14:34:38 -07:00
|
|
|
try {
|
|
|
|
sandbox[fn] = marionette[fn].bind(marionette);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
sandbox[fn] = marionette[fn];
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
});
|
|
|
|
|
2012-05-18 13:30:13 -07:00
|
|
|
sandbox.SpecialPowers = new SpecialPowers(aWindow);
|
|
|
|
|
2012-05-09 12:05:39 -07:00
|
|
|
sandbox.asyncComplete = function sandbox_asyncComplete(value, status) {
|
2012-05-23 17:23:36 -07:00
|
|
|
if (Object.keys(_emu_cbs).length) {
|
|
|
|
_emu_cbs = {};
|
|
|
|
value = "Emulator callback still pending when finish() called";
|
|
|
|
status = 500;
|
|
|
|
}
|
|
|
|
|
2012-05-09 12:05:39 -07:00
|
|
|
curWindow.removeEventListener("unload", errUnload, false);
|
|
|
|
|
|
|
|
/* clear all timeouts potentially generated by the script*/
|
|
|
|
for (let i = 0; i <= asyncTestTimeoutId; i++) {
|
|
|
|
curWindow.clearTimeout(i);
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
sendSyncMessage("Marionette:shareData", {log: elementManager.wrapValue(marionetteLogObj.getLogs()),
|
|
|
|
perf: elementManager.wrapValue(marionettePerf.getPerfData())});
|
2012-05-09 12:05:39 -07:00
|
|
|
marionetteLogObj.clearLogs();
|
2012-06-10 16:44:50 -07:00
|
|
|
marionettePerf.clearPerfData();
|
2012-05-09 12:05:39 -07:00
|
|
|
if (status == 0){
|
|
|
|
sendResponse({value: elementManager.wrapValue(value), status: status}, asyncTestCommandId);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendError(value, status, null, asyncTestCommandId);
|
|
|
|
}
|
|
|
|
|
|
|
|
asyncTestRunning = false;
|
|
|
|
asyncTestTimeoutId = undefined;
|
|
|
|
asyncTestCommandId = undefined;
|
|
|
|
};
|
|
|
|
sandbox.finish = function sandbox_finish() {
|
|
|
|
if (asyncTestRunning) {
|
|
|
|
sandbox.asyncComplete(marionette.generate_results(), 0);
|
|
|
|
} else {
|
|
|
|
return marionette.generate_results();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
sandbox.marionetteScriptFinished = function sandbox_marionetteScriptFinished(value) {
|
|
|
|
return sandbox.asyncComplete(value, 0);
|
|
|
|
};
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
return sandbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the given script either as a function body (executeScript)
|
|
|
|
* or directly (for 'mochitest' like JS Marionette tests)
|
|
|
|
*/
|
|
|
|
function executeScript(msg, directInject) {
|
|
|
|
let script = msg.json.value;
|
|
|
|
|
2012-05-09 12:05:39 -07:00
|
|
|
if (msg.json.newSandbox || !sandbox) {
|
|
|
|
sandbox = createExecuteContentSandbox(curWindow);
|
|
|
|
if (!sandbox) {
|
|
|
|
sendError("Could not create sandbox!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (directInject) {
|
2012-06-04 10:50:06 -07:00
|
|
|
if (importedScripts.exists()) {
|
|
|
|
let stream = Components.classes["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Components.interfaces.nsIFileInputStream);
|
|
|
|
stream.init(importedScripts, -1, 0, 0);
|
|
|
|
let data = NetUtil.readInputStreamToString(stream, stream.available());
|
|
|
|
script = data + script;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
let res = Cu.evalInSandbox(script, sandbox, "1.8");
|
2012-06-10 16:44:50 -07:00
|
|
|
sendSyncMessage("Marionette:shareData", {log: elementManager.wrapValue(marionetteLogObj.getLogs()),
|
|
|
|
perf: elementManager.wrapValue(marionettePerf.getPerfData())});
|
2012-03-22 08:19:57 -07:00
|
|
|
marionetteLogObj.clearLogs();
|
2012-06-10 16:44:50 -07:00
|
|
|
marionettePerf.clearPerfData();
|
2012-03-22 08:19:57 -07:00
|
|
|
if (res == undefined || res.passed == undefined) {
|
|
|
|
sendError("Marionette.finish() not called", 17, null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendResponse({value: elementManager.wrapValue(res)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-09 12:05:39 -07:00
|
|
|
try {
|
|
|
|
sandbox.__marionetteParams = elementManager.convertWrappedArguments(
|
|
|
|
msg.json.args, curWindow);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-05-09 12:05:39 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
let scriptSrc = "let __marionetteFunc = function(){" + script + "};" +
|
|
|
|
"__marionetteFunc.apply(null, __marionetteParams);";
|
2012-06-04 10:50:06 -07:00
|
|
|
if (importedScripts.exists()) {
|
|
|
|
let stream = Components.classes["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Components.interfaces.nsIFileInputStream);
|
|
|
|
stream.init(importedScripts, -1, 0, 0);
|
|
|
|
let data = NetUtil.readInputStreamToString(stream, stream.available());
|
|
|
|
scriptSrc = data + scriptSrc;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
let res = Cu.evalInSandbox(scriptSrc, sandbox, "1.8");
|
2012-06-10 16:44:50 -07:00
|
|
|
sendSyncMessage("Marionette:shareData", {log: elementManager.wrapValue(marionetteLogObj.getLogs()),
|
|
|
|
perf: elementManager.wrapValue(marionettePerf.getPerfData())});
|
2012-03-22 08:19:57 -07:00
|
|
|
marionetteLogObj.clearLogs();
|
2012-06-10 16:44:50 -07:00
|
|
|
marionettePerf.clearPerfData();
|
2012-03-22 08:19:57 -07:00
|
|
|
sendResponse({value: elementManager.wrapValue(res)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// 17 = JavascriptException
|
|
|
|
sendError(e.name + ': ' + e.message, 17, e.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 15:36:57 -07:00
|
|
|
/**
|
|
|
|
* Sets the test name, used in logging messages.
|
|
|
|
*/
|
|
|
|
function setTestName(msg) {
|
|
|
|
marionetteTestName = msg.json.value;
|
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Function to set the timeout of asynchronous scripts
|
|
|
|
*/
|
|
|
|
function setScriptTimeout(msg) {
|
|
|
|
marionetteTimeout = msg.json.value;
|
2012-08-01 09:53:37 -07:00
|
|
|
sendOk();
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute async script
|
|
|
|
*/
|
|
|
|
function executeAsyncScript(msg) {
|
|
|
|
executeWithCallback(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute pure JS test. Handles both async and sync cases.
|
|
|
|
*/
|
|
|
|
function executeJSScript(msg) {
|
|
|
|
if (msg.json.timeout) {
|
|
|
|
executeWithCallback(msg, msg.json.timeout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
executeScript(msg, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by executeAsync and executeJSScript to execute a script
|
|
|
|
* in a sandbox.
|
|
|
|
*
|
|
|
|
* For executeJSScript, it will return a message only when the finish() method is called.
|
|
|
|
* For executeAsync, it will return a response when marionetteScriptFinished/arguments[arguments.length-1]
|
|
|
|
* method is called, or if it times out.
|
|
|
|
*/
|
|
|
|
function executeWithCallback(msg, timeout) {
|
2012-05-02 07:21:05 -07:00
|
|
|
curWindow.addEventListener("unload", errUnload, false);
|
2012-03-22 08:19:57 -07:00
|
|
|
let script = msg.json.value;
|
2012-05-09 12:05:39 -07:00
|
|
|
asyncTestCommandId = msg.json.id;
|
2012-03-22 08:19:57 -07:00
|
|
|
|
2012-05-10 16:07:07 -07:00
|
|
|
if (msg.json.newSandbox || !sandbox) {
|
|
|
|
sandbox = createExecuteContentSandbox(curWindow);
|
|
|
|
if (!sandbox) {
|
|
|
|
sendError("Could not create sandbox!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
// Error code 28 is scriptTimeout, but spec says execute_async should return 21 (Timeout),
|
|
|
|
// see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute_async.
|
|
|
|
// However Selenium code returns 28, see
|
|
|
|
// http://code.google.com/p/selenium/source/browse/trunk/javascript/firefox-driver/js/evaluate.js.
|
|
|
|
// We'll stay compatible with the Selenium code.
|
2012-05-09 12:05:39 -07:00
|
|
|
asyncTestTimeoutId = curWindow.setTimeout(function() {
|
|
|
|
sandbox.asyncComplete('timed out', 28);
|
2012-03-22 08:19:57 -07:00
|
|
|
}, marionetteTimeout);
|
2012-05-10 16:07:07 -07:00
|
|
|
|
2012-05-02 07:21:05 -07:00
|
|
|
curWindow.addEventListener('error', function win__onerror(evt) {
|
|
|
|
curWindow.removeEventListener('error', win__onerror, true);
|
2012-05-09 12:05:39 -07:00
|
|
|
sandbox.asyncComplete(evt, 17);
|
2012-03-22 08:19:57 -07:00
|
|
|
return true;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
let scriptSrc;
|
|
|
|
if (timeout) {
|
|
|
|
if (marionetteTimeout == null || marionetteTimeout == 0) {
|
|
|
|
sendError("Please set a timeout", 21, null);
|
|
|
|
}
|
|
|
|
scriptSrc = script;
|
|
|
|
}
|
|
|
|
else {
|
2012-05-09 12:05:39 -07:00
|
|
|
try {
|
|
|
|
sandbox.__marionetteParams = elementManager.convertWrappedArguments(
|
|
|
|
msg.json.args, curWindow);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-05-09 12:05:39 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptSrc = "__marionetteParams.push(marionetteScriptFinished);" +
|
2012-03-22 08:19:57 -07:00
|
|
|
"let __marionetteFunc = function() { " + script + "};" +
|
|
|
|
"__marionetteFunc.apply(null, __marionetteParams); ";
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2012-05-09 12:05:39 -07:00
|
|
|
asyncTestRunning = true;
|
2012-06-04 10:50:06 -07:00
|
|
|
if (importedScripts.exists()) {
|
2012-08-31 13:59:48 -07:00
|
|
|
let stream = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
2012-06-04 10:50:06 -07:00
|
|
|
stream.init(importedScripts, -1, 0, 0);
|
|
|
|
let data = NetUtil.readInputStreamToString(stream, stream.available());
|
|
|
|
scriptSrc = data + scriptSrc;
|
|
|
|
}
|
2012-05-09 12:05:39 -07:00
|
|
|
Cu.evalInSandbox(scriptSrc, sandbox, "1.8");
|
2012-03-22 08:19:57 -07:00
|
|
|
} catch (e) {
|
|
|
|
// 17 = JavascriptException
|
2012-08-31 13:59:48 -07:00
|
|
|
sandbox.asyncComplete(e.name + ': ' + e.message, 17);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to set the timeout period for element searching
|
|
|
|
*/
|
|
|
|
function setSearchTimeout(msg) {
|
|
|
|
try {
|
|
|
|
elementManager.setSearchTimeout(msg.json.value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-03-22 08:19:57 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigate to URI. Handles the case where we navigate within an iframe.
|
|
|
|
* All other navigation is handled by the server (in chrome space).
|
|
|
|
*/
|
|
|
|
function goUrl(msg) {
|
2012-08-21 14:00:44 -07:00
|
|
|
addEventListener("DOMContentLoaded", function onDOMContentLoaded(event) {
|
|
|
|
// Prevent DOMContentLoaded events from frames from invoking this code,
|
|
|
|
// unless the event is coming from the frame associated with the current
|
|
|
|
// window (i.e., someone has used switch_to_frame).
|
|
|
|
if (!event.originalTarget.defaultView.frameElement ||
|
|
|
|
event.originalTarget.defaultView.frameElement == curWindow.frameElement) {
|
|
|
|
removeEventListener("DOMContentLoaded", onDOMContentLoaded, false);
|
|
|
|
|
|
|
|
let errorRegex = /about:.+(error)|(blocked)\?/;
|
|
|
|
if (curWindow.document.readyState == "interactive" && errorRegex.exec(curWindow.document.baseURI)) {
|
|
|
|
sendError("Error loading page", 13, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-11 13:06:53 -07:00
|
|
|
sendOk();
|
2012-08-21 14:00:44 -07:00
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
curWindow.location = msg.json.value;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current URI
|
|
|
|
*/
|
|
|
|
function getUrl(msg) {
|
2012-05-02 07:21:05 -07:00
|
|
|
sendResponse({value: curWindow.location.href});
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-10 13:30:21 -07:00
|
|
|
/**
|
|
|
|
* Get the current Title of the window
|
|
|
|
*/
|
|
|
|
function getTitle(msg) {
|
|
|
|
sendResponse({value: curWindow.top.document.title});
|
|
|
|
}
|
|
|
|
|
2012-08-09 12:31:12 -07:00
|
|
|
/**
|
|
|
|
* Get the current page source
|
|
|
|
*/
|
|
|
|
function getPageSource(msg) {
|
|
|
|
var XMLSerializer = curWindow.XMLSerializer;
|
|
|
|
var pageSource = new XMLSerializer().serializeToString(curWindow.document);
|
|
|
|
sendResponse({value: pageSource });
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
/**
|
|
|
|
* Go back in history
|
|
|
|
*/
|
|
|
|
function goBack(msg) {
|
2012-05-02 07:21:05 -07:00
|
|
|
curWindow.history.back();
|
2012-03-22 08:19:57 -07:00
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go forward in history
|
|
|
|
*/
|
|
|
|
function goForward(msg) {
|
2012-05-02 07:21:05 -07:00
|
|
|
curWindow.history.forward();
|
2012-03-22 08:19:57 -07:00
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh the page
|
|
|
|
*/
|
|
|
|
function refresh(msg) {
|
2012-05-02 07:21:05 -07:00
|
|
|
curWindow.location.reload(true);
|
2012-03-22 08:19:57 -07:00
|
|
|
let listen = function() { removeEventListener("DOMContentLoaded", arguments.callee, false); sendOk() } ;
|
|
|
|
addEventListener("DOMContentLoaded", listen, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an element in the document using requested search strategy
|
|
|
|
*/
|
|
|
|
function findElementContent(msg) {
|
|
|
|
try {
|
2012-08-27 13:50:34 -07:00
|
|
|
let on_success = function(id) { sendResponse({value:id}); };
|
|
|
|
let on_error = sendError;
|
|
|
|
elementManager.find(curWindow, msg.json, on_success, on_error, false);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find elements in the document using requested search strategy
|
|
|
|
*/
|
|
|
|
function findElementsContent(msg) {
|
|
|
|
try {
|
2012-08-27 13:50:34 -07:00
|
|
|
let on_success = function(id) { sendResponse({value:id}); };
|
|
|
|
let on_error = sendError;
|
|
|
|
elementManager.find(curWindow, msg.json, on_success, on_error, true);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send click event to element
|
|
|
|
*/
|
|
|
|
function clickElement(msg) {
|
|
|
|
let el;
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-04-10 17:28:08 -07:00
|
|
|
utils.click(el);
|
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a given attribute of an element
|
|
|
|
*/
|
2012-05-01 12:37:34 -07:00
|
|
|
function getElementAttribute(msg) {
|
2012-04-10 17:28:08 -07:00
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-05-01 12:37:34 -07:00
|
|
|
sendResponse({value: utils.getElementAttribute(el, msg.json.name)});
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the text of this element. This includes text from child elements.
|
|
|
|
*/
|
|
|
|
function getElementText(msg) {
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-04-10 17:28:08 -07:00
|
|
|
sendResponse({value: utils.getElementText(el)});
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 13:21:50 -07:00
|
|
|
/**
|
|
|
|
* Get the tag name of an element.
|
|
|
|
*/
|
|
|
|
function getElementTagName(msg) {
|
|
|
|
try {
|
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
|
|
|
sendResponse({value: el.tagName.toLowerCase()});
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
sendError(e.message, e.code, e.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Check if element is displayed
|
|
|
|
*/
|
|
|
|
function isElementDisplayed(msg) {
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-04-10 17:28:08 -07:00
|
|
|
sendResponse({value: utils.isElementDisplayed(el)});
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 13:59:15 -07:00
|
|
|
/**
|
|
|
|
* Get the size of the element and return it
|
|
|
|
*/
|
|
|
|
function getElementSize(msg){
|
|
|
|
try {
|
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
|
|
|
let clientRect = el.getBoundingClientRect();
|
|
|
|
sendResponse({value: {width: clientRect.width, height: clientRect.height}});
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
sendError(e.message, e.code, e.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Check if element is enabled
|
|
|
|
*/
|
|
|
|
function isElementEnabled(msg) {
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-04-10 17:28:08 -07:00
|
|
|
sendResponse({value: utils.isElementEnabled(el)});
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is selected
|
|
|
|
*/
|
|
|
|
function isElementSelected(msg) {
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-04-10 17:28:08 -07:00
|
|
|
sendResponse({value: utils.isElementSelected(el)});
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send keys to element
|
|
|
|
*/
|
|
|
|
function sendKeysToElement(msg) {
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-08-05 12:49:42 -07:00
|
|
|
utils.type(curWindow.document, el, msg.json.value.join(""), true);
|
2012-04-10 17:28:08 -07:00
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-04-10 17:28:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 13:35:30 -07:00
|
|
|
/**
|
|
|
|
* Get the position of an element
|
|
|
|
*/
|
|
|
|
function getElementPosition(msg) {
|
|
|
|
try{
|
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
|
|
|
var x = el.offsetLeft;
|
|
|
|
var y = el.offsetTop;
|
|
|
|
var elementParent = el.offsetParent;
|
|
|
|
while (elementParent != null) {
|
|
|
|
if (elementParent.tagName == "TABLE") {
|
|
|
|
var parentBorder = parseInt(elementParent.border);
|
|
|
|
if (isNaN(parentBorder)) {
|
|
|
|
var parentFrame = elementParent.getAttribute('frame');
|
|
|
|
if (parentFrame != null) {
|
|
|
|
x += 1;
|
|
|
|
y += 1;
|
|
|
|
}
|
|
|
|
} else if (parentBorder > 0) {
|
|
|
|
x += parentBorder;
|
|
|
|
y += parentBorder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x += elementParent.offsetLeft;
|
|
|
|
y += elementParent.offsetTop;
|
|
|
|
elementParent = elementParent.offsetParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
let location = {};
|
|
|
|
location.x = x;
|
|
|
|
location.y = y;
|
|
|
|
|
|
|
|
sendResponse({value: location});
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
sendError(e.message, e.code, e.stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:28:08 -07:00
|
|
|
/**
|
|
|
|
* Clear the text of an element
|
|
|
|
*/
|
|
|
|
function clearElement(msg) {
|
|
|
|
try {
|
2012-05-02 07:21:05 -07:00
|
|
|
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
2012-04-10 17:28:08 -07:00
|
|
|
utils.clearElement(el);
|
|
|
|
sendOk();
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch to frame given either the server-assigned element id,
|
|
|
|
* its index in window.frames, or the iframe's name or id.
|
|
|
|
*/
|
|
|
|
function switchToFrame(msg) {
|
|
|
|
let foundFrame = null;
|
2012-11-06 10:54:09 -08:00
|
|
|
let frames = curWindow.document.getElementsByTagName("iframe");
|
|
|
|
//Until Bug 761935 lands, we won't have multiple nested OOP iframes. We will only have one.
|
|
|
|
//parWindow will refer to the iframe above the nested OOP frame.
|
|
|
|
let parWindow = curWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
|
2012-03-22 08:19:57 -07:00
|
|
|
if ((msg.json.value == null) && (msg.json.element == null)) {
|
2012-05-02 07:21:05 -07:00
|
|
|
curWindow = content;
|
|
|
|
curWindow.focus();
|
2012-03-22 08:19:57 -07:00
|
|
|
sendOk();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (msg.json.element != undefined) {
|
|
|
|
if (elementManager.seenItems[msg.json.element] != undefined) {
|
2012-05-02 07:21:05 -07:00
|
|
|
let wantedFrame = elementManager.getKnownElement(msg.json.element, curWindow); //HTMLIFrameElement
|
2012-10-19 11:46:58 -07:00
|
|
|
for (let i = 0; i < frames.length; i++) {
|
|
|
|
if (frames[i] == wantedFrame) {
|
|
|
|
curWindow = frames[i];
|
2012-11-06 10:54:09 -08:00
|
|
|
foundFrame = i;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-06 10:54:09 -08:00
|
|
|
if (foundFrame == null) {
|
|
|
|
switch(typeof(msg.json.value)) {
|
|
|
|
case "string" :
|
|
|
|
let foundById = null;
|
|
|
|
for (let i = 0; i < frames.length; i++) {
|
|
|
|
//give precedence to name
|
|
|
|
let frame = frames[i];
|
|
|
|
let name = utils.getElementAttribute(frame, 'name');
|
|
|
|
let id = utils.getElementAttribute(frame, 'id');
|
|
|
|
if (name == msg.json.value) {
|
|
|
|
foundFrame = i;
|
|
|
|
break;
|
|
|
|
} else if ((foundById == null) && (id == msg.json.value)) {
|
|
|
|
foundById = i;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-11-06 10:54:09 -08:00
|
|
|
if ((foundFrame == null) && (foundById != null)) {
|
|
|
|
foundFrame = foundById;
|
|
|
|
curWindow = frames[foundFrame];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "number":
|
|
|
|
if (frames[msg.json.value] != undefined) {
|
|
|
|
foundFrame = msg.json.value;
|
|
|
|
curWindow = frames[foundFrame];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-05-09 12:05:39 -07:00
|
|
|
if (foundFrame == null) {
|
2012-03-22 08:19:57 -07:00
|
|
|
sendError("Unable to locate frame: " + msg.json.value, 8, null);
|
2012-05-09 12:05:39 -07:00
|
|
|
return;
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
2012-05-09 12:05:39 -07:00
|
|
|
|
|
|
|
sandbox = null;
|
2012-09-28 16:16:22 -07:00
|
|
|
|
|
|
|
if (curWindow.contentWindow == null) {
|
|
|
|
// The frame we want to switch to is a remote frame; notify our parent to handle
|
|
|
|
// the switch.
|
|
|
|
curWindow = content;
|
2012-11-06 10:54:09 -08:00
|
|
|
sendToServer('Marionette:switchToFrame', {frame: foundFrame, win: parWindow});
|
2012-09-28 16:16:22 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
curWindow = curWindow.contentWindow;
|
|
|
|
curWindow.focus();
|
|
|
|
sendOk();
|
|
|
|
}
|
2012-03-22 08:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-08-23 15:07:16 -07:00
|
|
|
function getAppCacheStatus() {
|
|
|
|
sendResponse({ value: curWindow.applicationCache.status });
|
|
|
|
}
|
|
|
|
|
2012-05-23 17:23:36 -07:00
|
|
|
// emulator callbacks
|
2012-05-18 13:30:43 -07:00
|
|
|
let _emu_cb_id = 0;
|
|
|
|
let _emu_cbs = {};
|
2012-05-23 17:23:36 -07:00
|
|
|
|
2012-05-18 13:30:43 -07:00
|
|
|
function runEmulatorCmd(cmd, callback) {
|
2012-05-25 10:37:21 -07:00
|
|
|
if (callback) {
|
|
|
|
_emu_cbs[_emu_cb_id] = callback;
|
2012-05-18 13:30:43 -07:00
|
|
|
}
|
|
|
|
sendAsyncMessage("Marionette:runEmulatorCmd", {emulator_cmd: cmd, id: _emu_cb_id});
|
|
|
|
_emu_cb_id += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function emulatorCmdResult(msg) {
|
|
|
|
let message = msg.json;
|
2012-05-25 10:37:21 -07:00
|
|
|
if (!sandbox) {
|
2012-05-23 17:23:36 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-05-18 13:30:43 -07:00
|
|
|
let cb = _emu_cbs[message.id];
|
|
|
|
delete _emu_cbs[message.id];
|
2012-05-25 10:37:21 -07:00
|
|
|
if (!cb) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-18 13:30:43 -07:00
|
|
|
try {
|
|
|
|
cb(message.result);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2012-06-21 13:47:13 -07:00
|
|
|
sendError(e.message, e.code, e.stack);
|
2012-05-18 13:30:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 10:50:06 -07:00
|
|
|
function importScript(msg) {
|
|
|
|
let file;
|
|
|
|
if (importedScripts.exists()) {
|
2012-06-18 11:59:39 -07:00
|
|
|
file = FileUtils.openFileOutputStream(importedScripts, FileUtils.MODE_APPEND | FileUtils.MODE_WRONLY);
|
2012-06-04 10:50:06 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-10-24 08:36:43 -07:00
|
|
|
//Note: The permission bits here don't actually get set (bug 804563)
|
|
|
|
importedScripts.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, parseInt("0666", 8));
|
2012-06-04 10:50:06 -07:00
|
|
|
file = FileUtils.openFileOutputStream(importedScripts, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE);
|
2012-10-24 08:36:43 -07:00
|
|
|
importedScripts.permissions = parseInt("0666", 8); //actually set permissions
|
2012-06-04 10:50:06 -07:00
|
|
|
}
|
|
|
|
file.write(msg.json.script, msg.json.script.length);
|
|
|
|
file.close();
|
|
|
|
sendOk();
|
|
|
|
}
|
|
|
|
|
2012-03-22 08:19:57 -07:00
|
|
|
//call register self when we get loaded
|
|
|
|
registerSelf();
|
2012-05-23 17:23:36 -07:00
|
|
|
|