Skip to content

Commit

Permalink
Add getWindow and sleep functions; include test_resizeWindow.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ahal-test committed Nov 11, 2011
1 parent 3509b4b commit d5208f8
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 125 deletions.
86 changes: 44 additions & 42 deletions peptest/extension/chrome/content/pepinit.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
/* ***** 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 peptest.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011.
* the Initial Developer. All Rights Reserved.
*
/* ***** 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 peptest.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011.
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Andrew Halberstadt <halbersa@gmail.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 ***** */
* Andrew Halberstadt <halbersa@gmail.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 ***** */

Components.utils.import('resource://gre/modules/NetUtil.jsm');
var broker = {}; Components.utils.import('resource://mozmill/driver/msgbroker.js', broker);
Expand Down Expand Up @@ -79,7 +79,7 @@ function runTests(tests) {
// TODO Figure out why they interfere with each other
utils.sleep(1000);
}
utils.dumpLine('FINISHED');
utils.dumpLine('INFO FINISHED');
// quit the application
goQuitApplication();
}
Expand All @@ -93,11 +93,11 @@ function runFile(test) {
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(test.path);
let uri = gIOS.newFileURI(file).spec;

try {
// initialize test scope
let testScope = new pep.PepAPI(test.name);

utils.dumpLine('TEST-START ' + test.name);
let startTime = Date.now();
subscriptLoader.loadSubScript(uri, testScope);
Expand All @@ -118,18 +118,20 @@ function runFile(test) {
*/
function loadManifest(manifest) {
let data = utils.readFile(manifest);
let json = data.join(' ');
let json = data.join(' ');
return JSON.parse(json);
};


function MozmillMsgListener() {}
MozmillMsgListener.prototype.pass = function(obj) {
utils.dumpLine('MOZMILL pass ' + JSON.stringify(obj) + '\n');
utils.dumpLine('MOZMILL pass ' + JSON.stringify(obj) + '\n');
}
MozmillMsgListener.prototype.fail = function(obj) {
utils.dumpLine('MOZMILL fail ' + JSON.stringify(obj) + '\n');
// TODO Should this cause an error?
utils.dumpLine('WARNING MOZMILL fail ' + JSON.stringify(obj) + '\n');
}
MozmillMsgListener.prototype.log = function(obj) {
utils.dumpLine('MOZMILL log ' + JSON.stringify(obj) + '\n');
utils.dumpLine('MOZMILL log ' + JSON.stringify(obj) + '\n');
}
broker.addObject(new MozmillMsgListener());
4 changes: 2 additions & 2 deletions peptest/extension/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.6</em:minVersion>
<em:maxVersion>10.*</em:maxVersion>
<em:maxVersion>15.*</em:maxVersion>
</Description>
</em:targetApplication>
<em:targetApplication>
<!-- Thunderbird -->
<Description>
<em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
<em:minVersion>3.0a1pre</em:minVersion>
<em:maxVersion>10.*</em:maxVersion>
<em:maxVersion>15.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
Expand Down
82 changes: 46 additions & 36 deletions peptest/extension/resource/pep/pep.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
/* ***** 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 peptest.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011.
* the Initial Developer. All Rights Reserved.
*
/* ***** 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 peptest.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011.
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Andrew Halberstadt <halbersa@gmail.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 ***** */
* Andrew Halberstadt <halbersa@gmail.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 ***** */

var EXPORTED_SYMBOLS = ['PepAPI'];
var results = {}; Components.utils.import('resource://pep/results.js', results);
var utils = {}; Components.utils.import('resource://pep/utils.js', utils);

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);

/**
* This is the API exposed to tests
* Any properties of this object will be directly injected into test scope
Expand All @@ -53,8 +56,15 @@ PepAPI.prototype.performAction = function(actionName, func) {
func();
this.resultHandler.endAction();
}
PepAPI.prototype.getWindow = function() {
// TODO Return other windows depending on app (e.g Mail3Pane)
return wm.getMostRecentWindow("navigator:browser");
}
PepAPI.prototype.sleep = function(milliseconds) {
utils.sleep(milliseconds);
}

// Logging wrapper for tests
// Logging wrapper for tests
function Log(testName) {
this.testName = testName;
}
Expand Down
76 changes: 41 additions & 35 deletions peptest/extension/resource/pep/results.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
/* ***** 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 peptest.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011.
* the Initial Developer. All Rights Reserved.
*
/* ***** 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 peptest.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2011.
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Andrew Halberstadt <halbersa@gmail.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 ***** */
* Andrew Halberstadt <halbersa@gmail.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 ***** */

var EXPORTED_SYMBOLS = ['ResultHandler'];

Expand All @@ -55,6 +55,12 @@ ResultHandler.prototype.startAction = function(actionName) {

ResultHandler.prototype.endAction = function() {
if (this.currentAction['start_time']) {
// Sleep for 200 milliseconds
// This is here because there may still be event tracer events
// propagating through the event loop. We don't want to miss
// unresponsiveness caused by operations executed towards the
// end of a performAction call.
utils.sleep(200);
this.currentAction['end_time'] = Date.now();
this.results.push(this.currentAction);
utils.dumpLine('ACTION-END ' + this.testName + ' ' + this.currentAction['action_name']);
Expand Down
2 changes: 1 addition & 1 deletion peptest/pepprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def processOutputLine(self, line):
line = line[len('PEP ' + tokens[1]):]
getattr(self.logger, tokens[1].lower())(line.strip())
if tokens[1] == 'ERROR':
results.fails[results.currentTest].append(tokens[3].rstrip())
results.fails[results.currentTest].append("fail")
else:
line = line[len('PEP'):]
self.logger.debug(line.strip())
Expand Down
3 changes: 1 addition & 2 deletions peptest/runpeptests.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ def __init__(self, **kwargs):
self.add_option("--timeout",
type="int", dest="timeout",
default=None,
help="global timeout in seconds")

help="global timeout in seconds (with no output)")
LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR")
LEVEL_STRING = ", ".join(LOG_LEVELS)
self.add_option("--log-level",
Expand Down
1 change: 1 addition & 0 deletions tests/firefox/all_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
[test_openBookmarksMenu.js]
[test_searchGoogle.js]
[test_openWindow.js]
[test_resizeWindow.js]
4 changes: 3 additions & 1 deletion tests/firefox/test_contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ c.open("http://mozilla.org");
c.waitForPageLoad();

// Grab reference to element on page (this is the <body> element in this case)
let page = findElement.ID(c.tabs.activeTab, 'home');
let page = findElement.ID(c.tabs.activeTab, 'header');
// Perform our first action, reload.
// It is very important to only place things that we
// are interested in testing inside of a performAction call
Expand Down Expand Up @@ -40,6 +40,7 @@ performAction('content_scroll', function() {
page.rightClick();
for (let i = 0; i < 15; ++i) {
page.keypress('VK_DOWN');
// Sleep to emulate a user better
c.sleep(10);
}
});
Expand All @@ -61,6 +62,7 @@ performAction('chrome_scroll', function() {
bar.rightClick();
for (let i = 0; i < 15; ++i) {
page.keypress('VK_DOWN');
// Sleep to emulate a user better
c.sleep(10);
}
});
Expand Down
3 changes: 0 additions & 3 deletions tests/firefox/test_openBlankTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ c.waitForPageLoad();
let page = findElement.ID(c.tabs.activeTab, "home");
performAction('open_blank_tab', function() {
page.keypress('t', {'ctrlKey': true});
// Sleep so that the consequences of pushing new tab get tested for responsiveness
c.sleep(100);
});

performAction('close_blank_tab', function() {
page.keypress('w', {'ctrlKey': true});
c.sleep(100);
});
Loading

0 comments on commit d5208f8

Please sign in to comment.