Make sure plugins are not double counted

In the event that a plugin with the same name was attempted to be
installed more than once, the plugin count would double count, and
result in a negative total plugin count.

This prevents actions from taking place, such as opening a popup plugin,
because it verifies that the plugin count is 0 first.

Change-Id: I5805caaa4448117d6ee86f2e2ce5681ab6b6c324
This commit is contained in:
Becky Siegel
2018-03-23 13:05:50 -07:00
parent 688b1f25a2
commit f1d423290e
2 changed files with 13 additions and 2 deletions

View File

@@ -337,6 +337,13 @@ limitations under the License.
sandbox.stub(Gerrit, '_pluginInstalled');
Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
// testplugin has already been installed once (in setup).
assert.isFalse(Gerrit._pluginInstalled.called);
// testplugin2 plugin has not yet been installed.
Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin2/static/test.js');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});

View File

@@ -427,14 +427,18 @@
const src = opt_src || (document.currentScript &&
(document.currentScript.src || document.currentScript.baseURI));
const name = getPluginNameFromUrl(new URL(src));
const plugin = plugins[name] || new Plugin(src);
const existingPlugin = plugins[name];
const plugin = existingPlugin || new Plugin(src);
try {
callback(plugin);
plugins[name] = plugin;
} catch (e) {
console.warn(`${name} install failed: ${e.name}: ${e.message}`);
}
Gerrit._pluginInstalled();
// Don't double count plugins that may have an html and js install.
if (!existingPlugin) {
Gerrit._pluginInstalled();
}
};
Gerrit.getLoggedIn = function() {