Revert "Revert "Use only Gerrit.install as a plugin loaded signal""
This reverts commit96d037968f. It also contains the underyling fix for loading plugins correctly. The importHref function expected functions for onload and onerror arguments and passing null instead was causing the unexplained behavior. Change-Id: Ic2a36d9bfcf85e5769c26ab49caf15e572d9463e (cherry picked from commit7ab0d543e5)
This commit is contained in:
committed by
Paladox none
parent
8d67ea4d38
commit
7dacf252ec
@@ -47,12 +47,12 @@
|
||||
* States that it expects no more than 3 parameters, but that's not true.
|
||||
* @todo (beckysiegel) check Polymer annotations and submit change.
|
||||
*/
|
||||
|
||||
_importHtmlPlugins(plugins) {
|
||||
for (const url of plugins) {
|
||||
// onload (second param) needs to be a function. When null or undefined
|
||||
// were passed, plugins were not loaded correctly.
|
||||
this.importHref(
|
||||
this._urlFor(url), Gerrit._pluginInstalled, Gerrit._pluginInstalled,
|
||||
true);
|
||||
this._urlFor(url), () => {}, Gerrit._pluginInstalled, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ limitations under the License.
|
||||
<link rel="import" href="../../../test/common-test-setup.html"/>
|
||||
<link rel="import" href="gr-plugin-host.html">
|
||||
|
||||
<script>void(0);</script>
|
||||
|
||||
<test-fixture id="basic">
|
||||
<template>
|
||||
<gr-plugin-host></gr-plugin-host>
|
||||
@@ -60,22 +62,38 @@ limitations under the License.
|
||||
element.config = {
|
||||
plugin: {html_resource_paths: ['foo/bar', 'baz']},
|
||||
};
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'/foo/bar', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
|
||||
assert.equal(element.importHref.firstCall.args[0], '/foo/bar');
|
||||
assert.equal(element.importHref.firstCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.firstCall.args[3]);
|
||||
|
||||
assert.equal(element.importHref.secondCall.args[0], '/baz');
|
||||
assert.equal(element.importHref.secondCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.secondCall.args[3]);
|
||||
});
|
||||
|
||||
test('imports relative html plugins from config with a base url', () => {
|
||||
sandbox.stub(element, 'getBaseUrl').returns('/the-base');
|
||||
element.config = {
|
||||
plugin: {html_resource_paths: ['foo/bar', 'baz']}};
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'/the-base/foo/bar', Gerrit._pluginInstalled, Gerrit._pluginInstalled,
|
||||
true));
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'/the-base/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled,
|
||||
true));
|
||||
assert.equal(element.importHref.firstCall.args[0], '/the-base/foo/bar');
|
||||
assert.equal(element.importHref.firstCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.firstCall.args[3]);
|
||||
|
||||
assert.equal(element.importHref.secondCall.args[0], '/the-base/baz');
|
||||
assert.equal(element.importHref.secondCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.secondCall.args[3]);
|
||||
});
|
||||
|
||||
test('inportHref is not called with null callback functions', () => {
|
||||
const plugins = ['path/to/plugin'];
|
||||
element._importHtmlPlugins(plugins);
|
||||
assert.isTrue(element.importHref.calledOnce);
|
||||
assert.isFunction(element.importHref.lastCall.args[1]);
|
||||
assert.isFunction(element.importHref.lastCall.args[2]);
|
||||
});
|
||||
|
||||
test('imports absolute html plugins from config', () => {
|
||||
@@ -87,12 +105,17 @@ limitations under the License.
|
||||
],
|
||||
},
|
||||
};
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'http://example.com/foo/bar', Gerrit._pluginInstalled,
|
||||
Gerrit._pluginInstalled, true));
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'https://example.com/baz', Gerrit._pluginInstalled,
|
||||
Gerrit._pluginInstalled, true));
|
||||
assert.equal(element.importHref.firstCall.args[0],
|
||||
'http://example.com/foo/bar');
|
||||
assert.equal(element.importHref.firstCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.firstCall.args[3]);
|
||||
|
||||
assert.equal(element.importHref.secondCall.args[0],
|
||||
'https://example.com/baz');
|
||||
assert.equal(element.importHref.secondCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.secondCall.args[3]);
|
||||
});
|
||||
|
||||
test('adds js plugins from config to the body', () => {
|
||||
@@ -138,10 +161,15 @@ limitations under the License.
|
||||
html_resource_paths: ['some'],
|
||||
},
|
||||
};
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'/oof', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
|
||||
assert.isTrue(element.importHref.calledWith(
|
||||
'/some', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
|
||||
assert.equal(element.importHref.firstCall.args[0], '/oof');
|
||||
assert.equal(element.importHref.firstCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.firstCall.args[3]);
|
||||
|
||||
assert.equal(element.importHref.secondCall.args[0], '/some');
|
||||
assert.equal(element.importHref.secondCall.args[2],
|
||||
Gerrit._pluginInstalled);
|
||||
assert.isTrue(element.importHref.secondCall.args[3]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user