Report loaded plugins to analytics
Change-Id: Ic537084dc0304e8a151fe968e6510a04f04e0b6c
This commit is contained in:
@@ -52,8 +52,11 @@ breaking changes to gr-change-actions won’t be noticed.
|
||||
|
||||
suite('early init', () => {
|
||||
setup(() => {
|
||||
Gerrit._resetPlugins();
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._setPluginsPending([]);
|
||||
changeActions = plugin.changeActions();
|
||||
element = fixture('basic');
|
||||
});
|
||||
@@ -71,6 +74,7 @@ breaking changes to gr-change-actions won’t be noticed.
|
||||
|
||||
suite('normal init', () => {
|
||||
setup(() => {
|
||||
Gerrit._resetPlugins();
|
||||
element = fixture('basic');
|
||||
sinon.stub(element, '_editStatusChanged');
|
||||
element.change = {};
|
||||
@@ -78,6 +82,8 @@ breaking changes to gr-change-actions won’t be noticed.
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
changeActions = plugin.changeActions();
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._setPluginsPending([]);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
|
||||
@@ -320,15 +320,19 @@ limitations under the License.
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
});
|
||||
|
||||
test('_pluginInstalled', done => {
|
||||
test('_pluginInstalled', () => {
|
||||
const pluginsLoadedStub = sandbox.stub();
|
||||
stub('gr-reporting', {
|
||||
pluginsLoaded() {
|
||||
done();
|
||||
},
|
||||
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
||||
});
|
||||
Gerrit._setPluginsCount(2);
|
||||
Gerrit._pluginInstalled();
|
||||
Gerrit._pluginInstalled();
|
||||
const plugins = [
|
||||
'http://test.com/plugins/foo/static/test.js',
|
||||
'http://test.com/plugins/bar/static/test.js',
|
||||
];
|
||||
Gerrit._setPluginsPending(plugins);
|
||||
Gerrit._pluginInstalled(plugins[0]);
|
||||
Gerrit._pluginInstalled(plugins[1]);
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['foo', 'bar']));
|
||||
});
|
||||
|
||||
test('install calls _pluginInstalled', () => {
|
||||
|
||||
@@ -27,8 +27,12 @@
|
||||
*/
|
||||
let _pluginsPending = {};
|
||||
|
||||
let _pluginsInstalled = [];
|
||||
|
||||
let _pluginsPendingCount = -1;
|
||||
|
||||
const UNKNOWN_PLUGIN = 'unknown';
|
||||
|
||||
const PANEL_ENDPOINTS_MAPPING = {
|
||||
CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK: 'change-view-integration',
|
||||
CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK: 'change-metadata-item',
|
||||
@@ -37,6 +41,7 @@
|
||||
const PLUGIN_LOADING_TIMEOUT_MS = 10000;
|
||||
|
||||
let _restAPI;
|
||||
|
||||
const getRestAPI = () => {
|
||||
if (!_restAPI) {
|
||||
_restAPI = document.createElement('gr-rest-api-interface');
|
||||
@@ -44,6 +49,14 @@
|
||||
return _restAPI;
|
||||
};
|
||||
|
||||
let _reporting;
|
||||
const getReporting = () => {
|
||||
if (!_reporting) {
|
||||
_reporting = document.createElement('gr-reporting');
|
||||
}
|
||||
return _reporting;
|
||||
};
|
||||
|
||||
// TODO (viktard): deprecate in favor of GrPluginRestApi.
|
||||
function send(method, url, opt_callback, opt_payload) {
|
||||
return getRestAPI().send(method, url, opt_payload).then(response => {
|
||||
@@ -420,9 +433,13 @@
|
||||
if (!app) {
|
||||
// No gr-app found (running tests)
|
||||
Gerrit._resetPlugins = () => {
|
||||
_resolveAllPluginsLoaded = null;
|
||||
_allPluginsPromise = null;
|
||||
Gerrit._setPluginsPending([]);
|
||||
_pluginsInstalled = [];
|
||||
_pluginsPending = {};
|
||||
_pluginsPendingCount = -1;
|
||||
_reporting = null;
|
||||
_resolveAllPluginsLoaded = null;
|
||||
_restAPI = null;
|
||||
Gerrit._endpoints = new GrPluginEndpoints();
|
||||
for (const k of Object.keys(_plugins)) {
|
||||
delete _plugins[k];
|
||||
@@ -558,7 +575,8 @@
|
||||
|
||||
Gerrit._setPluginsPending = function(plugins) {
|
||||
_pluginsPending = plugins.reduce((o, url) => {
|
||||
o[getPluginNameFromUrl(url)] = url;
|
||||
// TODO(viktard): Remove guard (@see Issue 8962)
|
||||
o[getPluginNameFromUrl(url) || UNKNOWN_PLUGIN] = url;
|
||||
return o;
|
||||
}, {});
|
||||
Gerrit._setPluginsCount(Object.keys(_pluginsPending).length);
|
||||
@@ -567,7 +585,7 @@
|
||||
Gerrit._setPluginsCount = function(count) {
|
||||
_pluginsPendingCount = count;
|
||||
if (Gerrit._arePluginsLoaded()) {
|
||||
document.createElement('gr-reporting').pluginsLoaded();
|
||||
getReporting().pluginsLoaded(_pluginsInstalled);
|
||||
if (_resolveAllPluginsLoaded) {
|
||||
_resolveAllPluginsLoaded();
|
||||
}
|
||||
@@ -585,17 +603,14 @@
|
||||
};
|
||||
|
||||
Gerrit._pluginInstalled = function(url) {
|
||||
const name = getPluginNameFromUrl(url);
|
||||
if (name && !_pluginsPending[name]) {
|
||||
console.warn(`Unexpected plugin from ${url}!`);
|
||||
const name = getPluginNameFromUrl(url) || UNKNOWN_PLUGIN;
|
||||
if (!_pluginsPending[name]) {
|
||||
console.warn(`Unexpected plugin ${name} installed from ${url}.`);
|
||||
} else {
|
||||
if (name) {
|
||||
delete _pluginsPending[name];
|
||||
console.log(`Plugin ${name} installed`);
|
||||
} else {
|
||||
console.log(`Plugin installed from ${url}`);
|
||||
}
|
||||
delete _pluginsPending[name];
|
||||
_pluginsInstalled.push(name);
|
||||
Gerrit._setPluginsCount(_pluginsPendingCount - 1);
|
||||
console.log(`Plugin ${name} installed.`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user