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:
@@ -337,6 +337,13 @@ limitations under the License.
|
|||||||
sandbox.stub(Gerrit, '_pluginInstalled');
|
sandbox.stub(Gerrit, '_pluginInstalled');
|
||||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||||
'http://test.com/plugins/testplugin/static/test.js');
|
'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);
|
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -427,14 +427,18 @@
|
|||||||
const src = opt_src || (document.currentScript &&
|
const src = opt_src || (document.currentScript &&
|
||||||
(document.currentScript.src || document.currentScript.baseURI));
|
(document.currentScript.src || document.currentScript.baseURI));
|
||||||
const name = getPluginNameFromUrl(new URL(src));
|
const name = getPluginNameFromUrl(new URL(src));
|
||||||
const plugin = plugins[name] || new Plugin(src);
|
const existingPlugin = plugins[name];
|
||||||
|
const plugin = existingPlugin || new Plugin(src);
|
||||||
try {
|
try {
|
||||||
callback(plugin);
|
callback(plugin);
|
||||||
plugins[name] = plugin;
|
plugins[name] = plugin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`${name} install failed: ${e.name}: ${e.message}`);
|
console.warn(`${name} install failed: ${e.name}: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
// Don't double count plugins that may have an html and js install.
|
||||||
|
if (!existingPlugin) {
|
||||||
Gerrit._pluginInstalled();
|
Gerrit._pluginInstalled();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Gerrit.getLoggedIn = function() {
|
Gerrit.getLoggedIn = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user