зеркало из https://github.com/mozilla/pjs.git
Bug 668303 - convert mozillafilelogger to specialpowers. r=ctalbert, a=test-only
--HG-- rename : testing/mochitest/tests/SimpleTest/MozillaFileLogger.js => testing/mochitest/tests/SimpleTest/MozillaLogger.js
This commit is contained in:
Родитель
148dca410d
Коммит
78f99c3c76
|
@ -4,7 +4,7 @@ reftest.jar:
|
|||
* content/reftest.js (reftest.js)
|
||||
content/reftest-content.js (reftest-content.js)
|
||||
content/reftest.xul (reftest.xul)
|
||||
content/MozillaFileLogger.js (../../../testing/mochitest/tests/SimpleTest/MozillaFileLogger.js)
|
||||
content/MozillaLogger.js (../../../testing/mochitest/tests/SimpleTest/MozillaLogger.js)
|
||||
#ifdef XPI_NAME
|
||||
% component {32530271-8c1b-4b7d-a812-218e42c6bb23} components/reftest-cmdline.js
|
||||
% contract @mozilla.org/commandlinehandler/general-startup;1?type=reftest {32530271-8c1b-4b7d-a812-218e42c6bb23}
|
||||
|
|
|
@ -264,9 +264,9 @@ function InitAndStartRefTests()
|
|||
logFile = prefs.getCharPref("reftest.logFile");
|
||||
if (logFile) {
|
||||
try {
|
||||
MozillaFileLogger.init(logFile);
|
||||
var mfl = new MozillaFileLogger(logFile);
|
||||
// Set to mirror to stdout as well as the file
|
||||
gDumpLog = function (msg) {dump(msg); MozillaFileLogger.log(msg);};
|
||||
gDumpLog = function (msg) {dump(msg); mfl.log(msg);};
|
||||
}
|
||||
catch(e) {
|
||||
// If there is a problem, just use stdout
|
||||
|
|
|
@ -51,6 +51,6 @@
|
|||
>
|
||||
<script type="application/ecmascript" src="quit.js" />
|
||||
<script type="application/ecmascript" src="reftest.js" />
|
||||
<script type="application/ecmascript" src="MozillaFileLogger.js" />
|
||||
<script type="application/ecmascript" src="MozillaLogger.js" />
|
||||
<!-- The reftest browser element is dynamically created, here -->
|
||||
</window>
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
onload="TestStart();"
|
||||
title="Browser chrome tests"
|
||||
width="1024">
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/MozillaLogger.js"/>
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
|
||||
<script src="chrome://mochikit/content/chrome-harness.js"/>
|
||||
<style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
|
||||
|
@ -106,8 +106,7 @@
|
|||
let logger = null;
|
||||
if (gConfig.logFile) {
|
||||
try {
|
||||
MozillaFileLogger.init(gConfig.logFile);
|
||||
logger = MozillaFileLogger;
|
||||
logger = new MozillaFileLogger(gConfig.logFile)
|
||||
} catch (ex) {
|
||||
dump("TEST-UNEXPECTED-FAIL | (browser-harness.xul) | " +
|
||||
"Error trying to log to " + gConfig.logFile + ": " + ex + "\n");
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<script type="text/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/TestRunner.js"/>
|
||||
<script type="text/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
|
||||
src="chrome://mochikit/content/tests/SimpleTest/MozillaLogger.js"/>
|
||||
<script type="text/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/quit.js" />
|
||||
<script type="application/javascript"
|
||||
|
|
|
@ -65,7 +65,6 @@ function messageHandler(m) {
|
|||
|
||||
function setup() {
|
||||
window.removeEventListener("load", setup, false);
|
||||
messageManager.loadFrameScript("chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js", true);
|
||||
messageManager.loadFrameScript("chrome://mochikit/content/ipc.js", true);
|
||||
messageManager.addMessageListener("chromeEvent", messageHandler);
|
||||
}
|
||||
|
|
|
@ -45,16 +45,6 @@ function ipcEvent(e) {
|
|||
var data = JSON.parse(e.getData("data"));
|
||||
|
||||
switch(type) {
|
||||
case 'LoggerInit':
|
||||
MozillaFileLogger.init(data.filename);
|
||||
break;
|
||||
case 'Logger':
|
||||
var logger = MozillaFileLogger.getLogCallback();
|
||||
logger({"num":data.num, "level":data.level, "info": Array(data.info)});
|
||||
break;
|
||||
case 'LoggerClose':
|
||||
MozillaFileLogger.close();
|
||||
break;
|
||||
case 'waitForFocus':
|
||||
if (content)
|
||||
var wrapper = content.wrappedJSObject.frames[0].SimpleTest;
|
||||
|
|
|
@ -15,7 +15,7 @@ mochikit.jar:
|
|||
content/dynamic/getMyDirectory.sjs (dynamic/getMyDirectory.sjs)
|
||||
content/static/harness.css (static/harness.css)
|
||||
content/tests/SimpleTest/EventUtils.js (tests/SimpleTest/EventUtils.js)
|
||||
content/tests/SimpleTest/MozillaFileLogger.js (tests/SimpleTest/MozillaFileLogger.js)
|
||||
content/tests/SimpleTest/MozillaLogger.js (tests/SimpleTest/MozillaLogger.js)
|
||||
content/tests/SimpleTest/PluginUtils.js (tests/SimpleTest/PluginUtils.js)
|
||||
content/tests/SimpleTest/quit.js (tests/SimpleTest/quit.js)
|
||||
content/tests/SimpleTest/setup.js (tests/SimpleTest/setup.js)
|
||||
|
|
|
@ -617,7 +617,7 @@ function testListing(metadata, response)
|
|||
SCRIPT({type: "text/javascript",
|
||||
src: "/tests/SimpleTest/TestRunner.js"}),
|
||||
SCRIPT({type: "text/javascript",
|
||||
src: "/tests/SimpleTest/MozillaFileLogger.js"}),
|
||||
src: "/tests/SimpleTest/MozillaLogger.js"}),
|
||||
SCRIPT({type: "text/javascript",
|
||||
src: "/tests/SimpleTest/quit.js"}),
|
||||
SCRIPT({type: "text/javascript",
|
||||
|
|
|
@ -50,6 +50,7 @@ const Cc = Components.classes;
|
|||
const Ci = Components.interfaces;
|
||||
|
||||
const CHILD_SCRIPT = "chrome://specialpowers/content/specialpowers.js"
|
||||
const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js"
|
||||
|
||||
/**
|
||||
* Special Powers Exception - used to throw exceptions nicely
|
||||
|
@ -91,6 +92,7 @@ SpecialPowersObserver.prototype = {
|
|||
this._messageManager.addMessageListener("SPProcessCrashService", this);
|
||||
this._messageManager.addMessageListener("SPPingService", this);
|
||||
|
||||
this._messageManager.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
|
||||
this._messageManager.loadFrameScript(CHILD_SCRIPT, true);
|
||||
this._isFrameScriptLoaded = true;
|
||||
}
|
||||
|
|
|
@ -303,15 +303,27 @@ SpecialPowers.prototype = {
|
|||
},
|
||||
|
||||
addSystemEventListener: function(target, type, listener, useCapture) {
|
||||
Components.classes["@mozilla.org/eventlistenerservice;1"].
|
||||
getService(Components.interfaces.nsIEventListenerService).
|
||||
Cc["@mozilla.org/eventlistenerservice;1"].
|
||||
getService(Ci.nsIEventListenerService).
|
||||
addSystemEventListener(target, type, listener, useCapture);
|
||||
},
|
||||
removeSystemEventListener: function(target, type, listener, useCapture) {
|
||||
Components.classes["@mozilla.org/eventlistenerservice;1"].
|
||||
getService(Components.interfaces.nsIEventListenerService).
|
||||
Cc["@mozilla.org/eventlistenerservice;1"].
|
||||
getService(Ci.nsIEventListenerService).
|
||||
removeSystemEventListener(target, type, listener, useCapture);
|
||||
}
|
||||
},
|
||||
|
||||
setLogFile: function(path) {
|
||||
this._mfl = new MozillaFileLogger(path);
|
||||
},
|
||||
|
||||
log: function(data) {
|
||||
this._mfl.log(data);
|
||||
},
|
||||
|
||||
closeLogFile: function() {
|
||||
this._mfl.close();
|
||||
},
|
||||
};
|
||||
|
||||
// Expose everything but internal APIs (starting with underscores) to
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
specialpowers.jar:
|
||||
% content specialpowers %content/
|
||||
content/specialpowers.js (content/specialpowers.js)
|
||||
content/MozillaLogger.js (../tests/SimpleTest/MozillaLogger.js)
|
||||
|
|
|
@ -42,7 +42,7 @@ relativesrcdir = testing/mochitest/tests/SimpleTest
|
|||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
_SIMPLETEST_FILES = MozillaFileLogger.js \
|
||||
_SIMPLETEST_FILES = MozillaLogger.js \
|
||||
quit.js \
|
||||
SimpleTest.js \
|
||||
test.css \
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
/**
|
||||
* MozillaFileLogger, a log listener that can write to a local file.
|
||||
*/
|
||||
|
||||
try {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
if (Cc === undefined) {
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
}
|
||||
} catch (ex) {} //running in ipcMode-chrome
|
||||
|
||||
try {
|
||||
const FOSTREAM_CID = "@mozilla.org/network/file-output-stream;1";
|
||||
const LF_CID = "@mozilla.org/file/local;1";
|
||||
|
||||
// File status flags. It is a bitwise OR of the following bit flags.
|
||||
// Only one of the first three flags below may be used.
|
||||
const PR_READ_ONLY = 0x01; // Open for reading only.
|
||||
const PR_WRITE_ONLY = 0x02; // Open for writing only.
|
||||
const PR_READ_WRITE = 0x04; // Open for reading and writing.
|
||||
|
||||
// If the file does not exist, the file is created.
|
||||
// If the file exists, this flag has no effect.
|
||||
const PR_CREATE_FILE = 0x08;
|
||||
|
||||
// The file pointer is set to the end of the file prior to each write.
|
||||
const PR_APPEND = 0x10;
|
||||
|
||||
// If the file exists, its length is truncated to 0.
|
||||
const PR_TRUNCATE = 0x20;
|
||||
|
||||
// If set, each write will wait for both the file data
|
||||
// and file status to be physically updated.
|
||||
const PR_SYNC = 0x40;
|
||||
|
||||
// If the file does not exist, the file is created. If the file already
|
||||
// exists, no action and NULL is returned.
|
||||
const PR_EXCL = 0x80;
|
||||
} catch (ex) {
|
||||
// probably not running in the test harness
|
||||
}
|
||||
|
||||
/** Init the file logger with the absolute path to the file.
|
||||
It will create and append if the file already exists **/
|
||||
var MozillaFileLogger = {};
|
||||
|
||||
var ipcMode = false;
|
||||
try {
|
||||
if (typeof(TestRunner) != undefined)
|
||||
ipcMode = TestRunner.ipcMode;
|
||||
} catch(e) { };
|
||||
|
||||
MozillaFileLogger.init = function(path) {
|
||||
if (ipcMode) {
|
||||
contentAsyncEvent("LoggerInit", {"filename": path});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
} catch (ex) {} //running in ipcMode-chrome
|
||||
|
||||
MozillaFileLogger._file = Cc[LF_CID].createInstance(Ci.nsILocalFile);
|
||||
MozillaFileLogger._file.initWithPath(path);
|
||||
MozillaFileLogger._foStream = Cc[FOSTREAM_CID].createInstance(Ci.nsIFileOutputStream);
|
||||
MozillaFileLogger._foStream.init(this._file, PR_WRITE_ONLY | PR_CREATE_FILE | PR_APPEND,
|
||||
0664, 0);
|
||||
}
|
||||
|
||||
MozillaFileLogger.getLogCallback = function() {
|
||||
if (ipcMode) {
|
||||
return function(msg) {
|
||||
contentAsyncEvent("Logger", {"num": msg.num, "level": msg.level, "info": msg.info.join(' ')});
|
||||
}
|
||||
}
|
||||
|
||||
return function (msg) {
|
||||
try {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
} catch(ex) {} //running in ipcMode-chrome
|
||||
|
||||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n";
|
||||
if (MozillaFileLogger._foStream)
|
||||
MozillaFileLogger._foStream.write(data, data.length);
|
||||
|
||||
if (data.indexOf("SimpleTest FINISH") >= 0) {
|
||||
MozillaFileLogger.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is only used from chrome space by the reftest harness
|
||||
MozillaFileLogger.log = function(msg) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
if (MozillaFileLogger._foStream)
|
||||
MozillaFileLogger._foStream.write(msg, msg.length);
|
||||
}
|
||||
|
||||
MozillaFileLogger.close = function() {
|
||||
if (ipcMode) {
|
||||
contentAsyncEvent("LoggerClose");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
} catch(ex) {} //running in ipcMode-chrome
|
||||
|
||||
if(MozillaFileLogger._foStream)
|
||||
MozillaFileLogger._foStream.close();
|
||||
|
||||
MozillaFileLogger._foStream = null;
|
||||
MozillaFileLogger._file = null;
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
* MozillaLogger, a base class logger that just logs to stdout.
|
||||
*/
|
||||
|
||||
function MozillaLogger(aPath) {
|
||||
}
|
||||
|
||||
MozillaLogger.prototype = {
|
||||
|
||||
init : function(path) {},
|
||||
|
||||
getLogCallback : function() {
|
||||
return function (msg) {
|
||||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n";
|
||||
dump(data);
|
||||
}
|
||||
},
|
||||
|
||||
log : function(msg) {
|
||||
dump(msg);
|
||||
},
|
||||
|
||||
close : function() {}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* SpecialPowersLogger, inherits from MozillaLogger and utilizes SpecialPowers.
|
||||
* intented to be used in content scripts to write to a file
|
||||
*/
|
||||
function SpecialPowersLogger(aPath) {
|
||||
// Call the base constructor
|
||||
MozillaLogger.call(this);
|
||||
this.prototype = new MozillaLogger(aPath);
|
||||
this.init(aPath);
|
||||
}
|
||||
|
||||
SpecialPowersLogger.prototype = {
|
||||
init : function (path) {
|
||||
SpecialPowers.setLogFile(path);
|
||||
},
|
||||
|
||||
getLogCallback : function () {
|
||||
return function (msg) {
|
||||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n";
|
||||
SpecialPowers.log(data);
|
||||
|
||||
if (data.indexOf("SimpleTest FINISH") >= 0) {
|
||||
SpecialPowers.closeLogFile();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
log : function (msg) {
|
||||
SpecialPowers.log(msg);
|
||||
},
|
||||
|
||||
close : function () {
|
||||
SpecialPowers.closeLogFile();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* MozillaFileLogger, a log listener that can write to a local file.
|
||||
* intended to be run from chrome space
|
||||
*/
|
||||
|
||||
/** Init the file logger with the absolute path to the file.
|
||||
It will create and append if the file already exists **/
|
||||
function MozillaFileLogger(aPath) {
|
||||
// Call the base constructor
|
||||
MozillaLogger.call(this);
|
||||
this.prototype = new MozillaLogger(aPath);
|
||||
this.init(aPath);
|
||||
}
|
||||
|
||||
MozillaFileLogger.prototype = {
|
||||
|
||||
init : function (path) {
|
||||
var PR_WRITE_ONLY = 0x02; // Open for writing only.
|
||||
var PR_CREATE_FILE = 0x08;
|
||||
var PR_APPEND = 0x10;
|
||||
this._file = Components.classes["@mozilla.org/file/local;1"].
|
||||
createInstance(Components.interfaces.nsILocalFile);
|
||||
this._file.initWithPath(path);
|
||||
this._foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
|
||||
createInstance(Components.interfaces.nsIFileOutputStream);
|
||||
this._foStream.init(this._file, PR_WRITE_ONLY | PR_CREATE_FILE | PR_APPEND,
|
||||
0664, 0);
|
||||
},
|
||||
|
||||
getLogCallback : function() {
|
||||
return function (msg) {
|
||||
var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n";
|
||||
if (MozillaFileLogger._foStream)
|
||||
this._foStream.write(data, data.length);
|
||||
|
||||
if (data.indexOf("SimpleTest FINISH") >= 0) {
|
||||
MozillaFileLogger.close();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
log : function(msg) {
|
||||
if (this._foStream)
|
||||
this._foStream.write(msg, msg.length);
|
||||
},
|
||||
|
||||
close : function() {
|
||||
if(this._foStream)
|
||||
this._foStream.close();
|
||||
|
||||
this._foStream = null;
|
||||
this._file = null;
|
||||
}
|
||||
};
|
||||
|
|
@ -81,8 +81,8 @@ if (params.closeWhenDone) {
|
|||
|
||||
// logFile to write our results
|
||||
if (params.logFile) {
|
||||
MozillaFileLogger.init(params.logFile);
|
||||
TestRunner.logger.addListener("mozLogger", fileLevel + "", MozillaFileLogger.getLogCallback());
|
||||
var spl = new SpecialPowersLogger(params.logFile);
|
||||
TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback());
|
||||
}
|
||||
|
||||
// if we get a quiet param, don't log to the console
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<!-- This harness does not work locally in Safari -->
|
||||
<script type="text/javascript" src="../MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="SimpleTest/TestRunner.js"></script>
|
||||
<script type="text/javascript" src="SimpleTest/MozillaFileLogger.js"></script>
|
||||
<script type="text/javascript" src="SimpleTest/MozillaLogger.js"></script>
|
||||
<script type="text/javascript" src="SimpleTest/quit.js"></script>
|
||||
<!--<link rel="stylesheet" type="text/css" href="/static/main.css" />-->
|
||||
</head>
|
||||
|
@ -29,8 +29,8 @@ if (params.closeWhenDone) {
|
|||
|
||||
// logFile to write our results
|
||||
if (params.logFile) {
|
||||
MozillaFileLogger.init(params.logFile);
|
||||
TestRunner.logger.addListener("mozLogger", fileLevel + "", MozillaFileLogger.getLogCallback());
|
||||
var spl = SpecialPowersLogger(params.logFile);
|
||||
TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback());
|
||||
}
|
||||
|
||||
// if we get a quiet param, don't log to the console
|
||||
|
|
Загрузка…
Ссылка в новой задаче