Bug 1229224: Add an eslint plugin for importing all browser.js globals for browser-chrome tests. r=miker

This commit is contained in:
Dave Townsend 2015-12-17 15:33:32 -08:00
parent cfbe0118c9
commit 458d418853
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,12 @@
.. _import-browserjs-globals:
========================
import-browserjs-globals
========================
Rule Details
------------
When included files from the main browser UI scripts will be loaded and any
declared globals will be defined for the current file. This is mostly useful for
browser-chrome mochitests that call browser functions.

View File

@ -21,6 +21,7 @@ module.exports = {
"components-imports": require("../lib/rules/components-imports"),
"import-globals-from": require("../lib/rules/import-globals-from"),
"import-headjs-globals": require("../lib/rules/import-headjs-globals"),
"import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
"mark-test-function-used": require("../lib/rules/mark-test-function-used"),
"no-aArgs": require("../lib/rules/no-aArgs"),
"no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"),
@ -31,6 +32,7 @@ module.exports = {
"components-imports": 0,
"import-globals-from": 0,
"import-headjs-globals": 0,
"import-browserjs-globals": 0,
"mark-test-function-used": 0,
"no-aArgs": 0,
"no-cpows-in-tests": 0,

View File

@ -0,0 +1,78 @@
/**
* @fileoverview Import globals from browser.js.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
var fs = require("fs");
var path = require("path");
var helpers = require("../helpers");
const SCRIPTS = [
"toolkit/components/printing/content/printUtils.js",
"toolkit/content/viewZoomOverlay.js",
"browser/components/places/content/browserPlacesViews.js",
"browser/base/content/browser.js",
"browser/components/downloads/content/downloads.js",
"browser/components/downloads/content/indicator.js",
"browser/components/customizableui/content/panelUI.js",
"toolkit/obsolete/content/inlineSpellCheckUI.js",
"toolkit/components/viewsource/content/viewSourceUtils.js",
"browser/base/content/browser-addons.js",
"browser/base/content/browser-ctrlTab.js",
"browser/base/content/browser-customization.js",
"browser/base/content/browser-devedition.js",
"browser/base/content/browser-eme.js",
"browser/base/content/browser-feeds.js",
"browser/base/content/browser-fullScreen.js",
"browser/base/content/browser-fullZoom.js",
"browser/base/content/browser-gestureSupport.js",
"browser/base/content/browser-places.js",
"browser/base/content/browser-plugins.js",
"browser/base/content/browser-safebrowsing.js",
"browser/base/content/browser-sidebar.js",
"browser/base/content/browser-social.js",
"browser/base/content/browser-syncui.js",
"browser/base/content/browser-tabsintitlebar.js",
"browser/base/content/browser-thumbnails.js",
"browser/base/content/browser-trackingprotection.js",
"browser/base/content/browser-data-submission-info-bar.js",
"browser/base/content/browser-fxaccounts.js",
];
module.exports = function(context) {
return {
Program: function(node) {
if (!helpers.getIsBrowserMochitest(this)) {
return;
}
let root = helpers.getRootDir(context);
for (let script of SCRIPTS) {
let fileName = path.join(root, script);
try {
let globals = helpers.getGlobalsForFile(fileName);
helpers.addGlobals(globals, context);
}
catch (e) {
context.report(
node,
"Could not load globals from file {{filePath}}: {{error}}",
{
filePath: path.relative(root, fileName),
error: e
}
);
}
}
}
};
};