Skip to content

Commit

Permalink
Use quit.js instead of re-inventing the wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
ahal-test committed Oct 14, 2011
1 parent 9d9643a commit dd3d09a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 15 deletions.
19 changes: 5 additions & 14 deletions peptest/extension/chrome/content/pepinit.js
Expand Up @@ -45,13 +45,10 @@ const gIOS = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService)
const subscriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1'] const subscriptLoader = Cc['@mozilla.org/moz/jssubscript-loader;1']
.getService(Components.interfaces.mozIJSSubScriptLoader); .getService(Components.interfaces.mozIJSSubScriptLoader);


var noisy = false;
var appContent; var appContent;


function pepInit(args) { function pepInit(args) {
try { try {
if (args.noisy) noisy = true;

let manifest = args.manifest; let manifest = args.manifest;
let obj = loadManifest(manifest); let obj = loadManifest(manifest);
let firstRun = true; let firstRun = true;
Expand All @@ -70,13 +67,13 @@ function pepInit(args) {
function runTests(tests) { function runTests(tests) {
for (let i = 0; i < tests.length; ++i) { for (let i = 0; i < tests.length; ++i) {
runFile(tests[i]); runFile(tests[i]);
// Sleep for half a second because tests will interfere with each other if loaded too quickly // Sleep for a second because tests will interfere with each other if loaded too quickly
utils.sleep(500); // TODO Figure out why they interfere with each other
utils.sleep(1000);
} }
// quit the application // quit the application
let app = Components.classes['@mozilla.org/toolkit/app-startup;1'] subscriptLoader.loadSubScript('resource://pep/quit.js')
.getService(Components.interfaces.nsIAppStartup); goQuitApplication();
app.quit(Components.interfaces.nsIAppStartup.eForceQuit);
} }


/** /**
Expand Down Expand Up @@ -113,9 +110,3 @@ MozmillMsgListener.prototype.update = function(msgType, obj) {
utils.dumpLine('MOZMILL ' + msgType + ' ' + JSON.stringify(obj) + '\n'); utils.dumpLine('MOZMILL ' + msgType + ' ' + JSON.stringify(obj) + '\n');
} }
msg.broker.addListener(new MozmillMsgListener()); msg.broker.addListener(new MozmillMsgListener());

function debugLine(str) {
if (noisy) {
utils.dumpLine(str);
}
};
93 changes: 93 additions & 0 deletions peptest/extension/resource/pep/quit.js
@@ -0,0 +1,93 @@
/* ***** 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;
}
1 change: 0 additions & 1 deletion peptest/runpeptests.py
Expand Up @@ -111,7 +111,6 @@ def __init__(self, options, **kwargs):
# TODO Make browserArgs a list # TODO Make browserArgs a list
cmdargs.extend(self.options.browserArgs) cmdargs.extend(self.options.browserArgs)
cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)]) cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)])
cmdargs.append('-pep-noisy')


# run with managed process handler # run with managed process handler
self.runner = self.runner_class(profile=self.profile, self.runner = self.runner_class(profile=self.profile,
Expand Down

0 comments on commit dd3d09a

Please sign in to comment.