Bug 710877 - allow reftest to use FileUtils and remove quit.js code. r=dbaron

This commit is contained in:
Joel Maher 2011-12-20 07:46:10 -05:00
parent b7bad66754
commit ba169896b6
4 changed files with 35 additions and 143 deletions

View File

@ -1,10 +1,8 @@
reftest.jar:
% content reftest %content/
* content/quit.js (quit.js)
* content/reftest.js (reftest.js)
content/reftest-content.js (reftest-content.js)
content/reftest.xul (reftest.xul)
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}

View File

@ -1,110 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is The Original Code is Mozilla Automated Testing Code
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Bob Clary <bob@bclary.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
From mozilla/toolkit/content
These files did not have a license
*/
function canQuitApplication()
{
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
if (!os)
{
return true;
}
try
{
var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
.createInstance(Components.interfaces.nsISupportsPRBool);
os.notifyObservers(cancelQuit, "quit-application-requested", null);
// Something aborted the quit process.
if (cancelQuit.data)
{
return false;
}
}
catch (ex)
{
}
return true;
}
function goQuitApplication()
{
if (!canQuitApplication())
{
return false;
}
const kAppStartup = '@mozilla.org/toolkit/app-startup;1';
const kAppShell = '@mozilla.org/appshell/appShellService;1';
var appService;
var forceQuit;
if (kAppStartup in Components.classes)
{
appService = Components.classes[kAppStartup].
getService(Components.interfaces.nsIAppStartup);
forceQuit = Components.interfaces.nsIAppStartup.eForceQuit;
}
else if (kAppShell in Components.classes)
{
appService = Components.classes[kAppShell].
getService(Components.interfaces.nsIAppShellService);
forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
}
else
{
throw 'goQuitApplication: no AppStartup/appShell';
}
try
{
appService.quit(forceQuit);
}
catch(ex)
{
throw('goQuitApplication: ' + ex);
}
return true;
}

View File

@ -62,6 +62,8 @@ const NS_DIRECTORY_SERVICE_CONTRACTID =
const NS_OBSERVER_SERVICE_CONTRACTID =
"@mozilla.org/observer-service;1";
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var gLoadTimeout = 0;
var gTimeoutHook = null;
var gRemote = false;
@ -261,55 +263,59 @@ function InitAndStartRefTests()
{
/* These prefs are optional, so we don't need to spit an error to the log */
try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch2);
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch2);
} catch(e) {
gDumpLog("REFTEST TEST-UNEXPECTED-FAIL | | EXCEPTION: " + e + "\n");
gDumpLog("REFTEST TEST-UNEXPECTED-FAIL | | EXCEPTION: " + e + "\n");
}
/* set the gLoadTimeout */
try {
gLoadTimeout = prefs.getIntPref("reftest.timeout");
gLoadTimeout = prefs.getIntPref("reftest.timeout");
} catch(e) {
gLoadTimeout = 5 * 60 * 1000; //5 minutes as per bug 479518
gLoadTimeout = 5 * 60 * 1000; //5 minutes as per bug 479518
}
/* Get the logfile for android tests */
try {
logFile = prefs.getCharPref("reftest.logFile");
if (logFile) {
try {
var mfl = new MozillaFileLogger(logFile);
// Set to mirror to stdout as well as the file
gDumpLog = function (msg) {dump(msg); mfl.log(msg);};
logFile = prefs.getCharPref("reftest.logFile");
if (logFile) {
try {
var f = FileUtils.File(logFile);
var mfl = FileUtils.openFileOutputStream(f, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE);
// Set to mirror to stdout as well as the file
gDumpLog = function (msg) {
dump(msg);
mfl.write(msg, msg.length);
};
}
catch(e) {
// If there is a problem, just use stdout
gDumpLog = dump;
}
}
catch(e) {
// If there is a problem, just use stdout
gDumpLog = dump;
}
}
} catch(e) {}
try {
gRemote = prefs.getBoolPref("reftest.remote");
gRemote = prefs.getBoolPref("reftest.remote");
} catch(e) {
gRemote = false;
gRemote = false;
}
try {
gIgnoreWindowSize = prefs.getBoolPref("reftest.ignoreWindowSize");
gIgnoreWindowSize = prefs.getBoolPref("reftest.ignoreWindowSize");
} catch(e) {
gIgnoreWindowSize = false;
gIgnoreWindowSize = false;
}
/* Support for running a chunk (subset) of tests. In separate try as this is optional */
try {
gTotalChunks = prefs.getIntPref("reftest.totalChunks");
gThisChunk = prefs.getIntPref("reftest.thisChunk");
gTotalChunks = prefs.getIntPref("reftest.totalChunks");
gThisChunk = prefs.getIntPref("reftest.thisChunk");
}
catch(e) {
gTotalChunks = 0;
gThisChunk = 0;
gTotalChunks = 0;
gThisChunk = 0;
}
try {
@ -326,10 +332,10 @@ function InitAndStartRefTests()
RegisterProcessCrashObservers();
if (gRemote) {
gServer = null;
gServer = null;
} else {
gServer = CC["@mozilla.org/server/jshttp;1"].
createInstance(CI.nsIHttpServer);
gServer = CC["@mozilla.org/server/jshttp;1"].
createInstance(CI.nsIHttpServer);
}
try {
if (gServer)
@ -405,7 +411,6 @@ function StartTests()
function OnRefTestUnload()
{
MozillaFileLogger.close();
}
// Read all available data from an input stream and return it
@ -993,7 +998,8 @@ function DoneTests()
gDumpLog("REFTEST TEST-START | Shutdown\n");
function onStopped() {
goQuitApplication();
let appStartup = CC["@mozilla.org/toolkit/app-startup;1"].getService(CI.nsIAppStartup);
appStartup.quit(CI.nsIAppStartup.eForceQuit);
}
if (gServer)
gServer.stop(onStopped);

View File

@ -49,8 +49,6 @@
onunload="OnRefTestUnload();"
style="background:white; overflow:hidden"
>
<script type="application/ecmascript" src="quit.js" />
<script type="application/ecmascript" src="reftest.js" />
<script type="application/ecmascript" src="MozillaLogger.js" />
<!-- The reftest browser element is dynamically created, here -->
</window>