diff --git a/mozilla/testing/tests/l10n/extensions/coverage/Makefile.in b/mozilla/testing/tests/l10n/extensions/coverage/Makefile.in new file mode 100755 index 00000000000..7d9d6661110 --- /dev/null +++ b/mozilla/testing/tests/l10n/extensions/coverage/Makefile.in @@ -0,0 +1,57 @@ +# ***** 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 mozilla.org l10n testing. +# +# The Initial Developer of the Original Code is +# Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2006 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Axel Hecht +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = coverage +XPI_NAME = coverage +#INSTALL_EXTENSION_ID = coverage@l10n.mozilla.com +XPI_PKGNAME = coverage-$(EXTENSION_VERSION) +EXTENSION_VERSION = 0.5 + +USE_EXTENSION_MANIFEST = 1 +DIST_FILES = install.rdf +PREF_JS_EXPORTS = $(srcdir)/coverage-extension-prefs.js + +DEFINES += -DEXTENSION_VERSION=$(EXTENSION_VERSION) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-menu.js b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-menu.js new file mode 100755 index 00000000000..4c19c6c1ef6 --- /dev/null +++ b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-menu.js @@ -0,0 +1,104 @@ +/* ***** 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 mozilla.org l10n testing. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2066 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Axel Hecht + * + * 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 ***** */ + +/** + * Item to close a menu popup + * + * Used by OpenMenuObj. + */ +function CloseMenuObj(aPopup) { + this.args = [aPopup]; +} +CloseMenuObj.prototype = { + args: null, + method: function _openMenu(aPopup) { + aPopup.hidePopup(); + } +}; + +/** + * Item to open a menu popup + * + * Adds a CloseMenuObj item as well as potentially child popups to + * Stack + */ +function OpenMenuObj(aPopup) { + this.args = [aPopup]; +} +OpenMenuObj.prototype = { + args: null, + method: function _openMenu(aPopup) { + aPopup.showPopup(); + Stack.push(new CloseMenuObj(aPopup)); + for (var i = aPopup.childNodes.length - 1; i>=0; --i) { + var c = aPopup.childNodes[i]; + if (c.nodeName != 'menu' || c.childNodes.length == 0) { + continue; + } + for each (var childpop in c.childNodes) { + if (childpop.localName == "menupopup") { + Stack.push(new OpenMenuObj(childpop)); + } + } + } + } +}; + +/** + * Item to kick off menu coverage testing + * + * Pretty similar to OpenMenuObj, just that it works on the main-menubar + * instead of a given popup. + */ +function RootMenu(aWindow) { + this._w = aWindow; +}; +RootMenu.prototype = { + args: [], + method: function() { + var mb = this._w.document.getElementById('main-menubar'); + for (var i = mb.childNodes.length - 1; i>=0; --i) { + var m = mb.childNodes[i]; + Stack.push(new OpenMenuObj(m.firstChild)); + } + }, + _w: null +}; + +toRun.push(new TestDone('MENUS')); +toRun.push(new RootMenu(wins[0])); +toRun.push(new TestStart('MENUS')); diff --git a/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-neterror.js b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-neterror.js new file mode 100755 index 00000000000..934bceb9185 --- /dev/null +++ b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-neterror.js @@ -0,0 +1,113 @@ +/* ***** 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 mozilla.org l10n testing. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2066 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Axel Hecht + * + * 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 SBS = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService); +var bundle = SBS.createBundle("chrome://global/locale/appstrings.properties"); + +/** + * Item to wait on asynchronous loads + */ +var loadAction = { + isLoaded: false, + args: [], + method: function() { + if (!this.isLoaded) { + Stack.push(this); + } + } +}; +// onLoad handler for the iframe, sibling of loadAction +function onFrameLoad(aEvent) { + aEvent.stopPropagation(); + loadAction.isLoaded = true; + return false; +}; + +/** + * Item to load the next error page + * + * Uses the loadAction object to wait for asynchronous loading. + */ +function ErrPageLoad(aFrame, aProperty) { + this.args = [aFrame, aProperty.key, aProperty.value]; +}; +ErrPageLoad.prototype = { + args: null, + method: function(aFrame, aErr, aDesc) { + loadAction.isLoaded = false; + var q = 'e=' + encodeURIComponent(aErr); + q += '&u=' + encodeURIComponent('http://foo.bar'); + // Simple replacement, replace anything that's %s with aURL, + // see http://lxr.mozilla.org/mozilla1.8/source/docshell/base/nsDocShell.cpp#2907 + // on how to do this right. But that requires knowledge on each and + // every error, too much work for now. + aDesc = aDesc.replace('%S', 'http://foo.bar'); + q += '&d=' + encodeURIComponent(aDesc); + Stack.push(loadAction); + aFrame.setAttribute('src', 'about:neterror?' + q); + } +}; + +/** + * Item to start the neterror tests + * + * This item collects all the neterror pages we intend to test + * and adds them to the Stack. + */ +function RootNeterror() { + this.args = []; +}; +RootNeterror.prototype = { + args: null, + method: function(aIFrame) { + var frame = document.getElementById('neterror-pane'); + var nErrors = + [err for (err in SimpleGenerator(bundle.getSimpleEnumeration(), + Ci.nsIPropertyElement))]; + nErrors.sort(function(aPl, aPr) { + return aPl.key > aPr.key ? 1 : + aPl.key < aPr.key ? -1 : 0; + }); + for each (err in nErrors) { + Stack.push(new ErrPageLoad(frame, err)); + } + } +}; + +toRun.push(new TestDone('NETERROR')); +toRun.push(new RootNeterror()); +toRun.push(new TestStart('NETERROR')); diff --git a/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-prefs.js b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-prefs.js new file mode 100755 index 00000000000..282c9d98695 --- /dev/null +++ b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage-prefs.js @@ -0,0 +1,138 @@ +/* ***** 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 mozilla.org l10n testing. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2066 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Axel Hecht + * + * 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 ***** */ + +/** + * Item to show the next pane in a prefs window + */ +function ShowPaneObj(aPane, aLoader) { + this.args = [aPane, aLoader]; +} +ShowPaneObj.prototype = { + args: null, + method: function _openMenu(aPane, aLoader) { + Stack.push(aLoader); + aPane.parentNode.showPane(aPane); + } +}; + +/** + * Item to close the preferences window once the tests are done + */ +function ClosePreferences() { + this.args = []; +}; +ClosePreferences.prototype = { + args: [], + method: function() { + var pWin = WM.getMostRecentWindow("Browser:Preferences"); + if (pWin) { + pWin.close(); + } + else { + Components.utils.reportError("prefwindow not found, trying again"); + } + } +}; + +/** + * Item to wait for a preference pane to load + */ +function PrefPaneLoader() { +}; +PrefPaneLoader.prototype = { + _currentPane: null, + args: [], + method: function() { + if (!this._currentPane) { + // The pane we're waiting for hasn't been loaded yet, do me again + Stack.push(this); + return; + } + // the pane is loaded, kick off the load of the next one, if available + pane = this._currentPane.nextSibling; + this._currentPane = null; + while (pane) { + if (pane.nodeName == 'prefpane') { + Stack.push(new ShowPaneObj(pane, this)); + return; + } + pane = pane.nextSibling; + } + }, + // nsIDOMEventListener + handleEvent: function _hv(aEvent) { + this._currentPane = aEvent.target; + } +}; + +/** + * Item to start the preference dialog tests + * + * This item expects to have 'paneMain' as the ID of the first pane. + * That may be an over-simplification, but it guarantees to load + * the panes from left to right, and that all are not loaded yet. + * WFM. + */ +function RootPreference(aWindow) { + this.args = [aWindow]; +}; +RootPreference.prototype = { + args: [], + method: function(aWindow) { + WM.addListener(this); + aWindow.openPreferences('paneMain'); + }, + // nsIWindowMediatorListener + onWindowTitleChange: function(aWindow, newTitle){}, + onOpenWindow: function(aWindow) { + WM.removeListener(this); + // ensure the timer runs in the modal window, too + Stack._timer.initWithCallback({notify:function (aTimer) {Stack.pop();}}, + Stack._time, 1); + Stack.push(new ClosePreferences()); + var ppl = new PrefPaneLoader(); + aWindow.docShell.QueryInterface(Ci.nsIInterfaceRequestor); + var DOMwin = aWindow.docShell.getInterface(Ci.nsIDOMWindow); + DOMwin.addEventListener('paneload', ppl, false); + Stack.push(ppl); + }, + onCloseWindow: function(aWindow){} +}; + +toRun.push(new TestDone('PREFERENCES')); +toRun.push(new RootPreference(wins[0])); +toRun.push(new TestStart('PREFERENCES')); diff --git a/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage.js b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage.js new file mode 100755 index 00000000000..77571bea382 --- /dev/null +++ b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage.js @@ -0,0 +1,130 @@ +/* ***** 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 mozilla.org l10n testing. + * + * The Initial Developer of the Original Code is + * Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2066 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Axel Hecht + * + * 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 ***** */ + +/** + * Basic architecture for UI exposure tests + * + * Details on http://wiki.mozilla.org/SoftwareTesting:Tools:L10n:Coverage + */ + +var Ci = Components.interfaces; +var Cc = Components.classes; +var Cr = Components.results; + +var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); +var ds = Cc[NS_DIRECTORY_SERVICE_CONTRACTID].getService(Ci.nsIProperties); +const WM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); + +/** + * Global Stack object + * + * This object keeps the tests running with some time for visual inspection. + */ +var Stack = { + _stack: [], + _time: 250, + _timer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer), + notify: function _notify(aTimer) { + this.pop(); + }, + push: function _push(aItem) { + this._stack.push(aItem); + if (this._stack.length == 1) { + this._timer.initWithCallback({notify:function (aTimer) {Stack.pop();}}, + this._time, 1); + } + }, + pop: function _pop() { + var obj = this._stack.pop(); + try { + obj.method.apply(obj, obj.args); + } catch (e) { + Components.utils.reportError(e); + } + if (!this._stack.length) { + this._timer.cancel(); + } + } +}; +/** + * Add your test set to toRun. + * The onload handler will add them to the Stack and kick off the + * testing. + */ +var toRun = []; + +/** + * Utility to get array of xpcom objects from a nsISimpleEnumerator + * Requires JS1.7 + */ +function SimpleGenerator(enumr, interface) { + while (enumr.hasMoreElements()) { + yield enumr.getNext().QueryInterface(interface); + } +} + +var wins = [w for (w in SimpleGenerator(WM.getEnumerator(null), Ci.nsIDOMWindow))]; + +/** + * Helper items to log start and end of testing to the Error Console + */ +function MsgBase() { +} +MsgBase.prototype = { + args: [], + method: function() { + Components.utils.reportError(this._msg); + } +}; +function TestStart(aCat) { + this._msg = 'TESTING:START:COVERAGE:' + aCat; +} +TestStart.prototype = new MsgBase; +function TestDone(aCat) { + this._msg = 'TESTING:DONE:COVERAGE:' + aCat; +} +TestDone.prototype = new MsgBase; + +/** + * onload handler for the entry page. + * Copy the toRun items over to the stack and kick things off. + */ +function onLoad() { + for each (var obj in toRun) { + Stack.push(obj); + } +} diff --git a/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage.xul b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage.xul new file mode 100755 index 00000000000..e56af62fed7 --- /dev/null +++ b/mozilla/testing/tests/l10n/extensions/coverage/chrome/content/coverage.xul @@ -0,0 +1,48 @@ + + + + + +