Preloaded plugins install updates
Take window.ASSETS_PATH into account, if provided. Flush preinstall callbacks, if provided. Change-Id: If1c0e29c7d70b91afc0a986173107c2c04caa7b3
This commit is contained in:
@@ -78,6 +78,16 @@ limitations under the License.
|
|||||||
assert.strictEqual(plugin, otherPlugin);
|
assert.strictEqual(plugin, otherPlugin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('flushes preinstalls if provided', () => {
|
||||||
|
assert.doesNotThrow(() => {
|
||||||
|
Gerrit._flushPreinstalls();
|
||||||
|
});
|
||||||
|
window.Gerrit.flushPreinstalls = sandbox.stub();
|
||||||
|
Gerrit._flushPreinstalls();
|
||||||
|
assert.isTrue(window.Gerrit.flushPreinstalls.calledOnce);
|
||||||
|
delete window.Gerrit.flushPreinstalls;
|
||||||
|
});
|
||||||
|
|
||||||
test('url', () => {
|
test('url', () => {
|
||||||
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
|
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
|
||||||
assert.equal(plugin.url('/static/test.js'),
|
assert.equal(plugin.url('/static/test.js'),
|
||||||
@@ -429,6 +439,16 @@ limitations under the License.
|
|||||||
assert.strictEqual(pluginApi.getPluginName(), 'foo');
|
assert.strictEqual(pluginApi.getPluginName(), 'foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('installing preloaded plugin', () => {
|
||||||
|
let plugin;
|
||||||
|
window.ASSETS_PATH = 'http://blips.com/chitz/';
|
||||||
|
Gerrit.install(p => { plugin = p; }, '0.1', 'preloaded:foo');
|
||||||
|
assert.strictEqual(plugin.getPluginName(), 'foo');
|
||||||
|
assert.strictEqual(plugin.url('/some/thing.html'),
|
||||||
|
'http://blips.com/plugins/foo/some/thing.html');
|
||||||
|
delete window.ASSETS_PATH;
|
||||||
|
});
|
||||||
|
|
||||||
suite('test plugin with base url', () => {
|
suite('test plugin with base url', () => {
|
||||||
setup(() => {
|
setup(() => {
|
||||||
sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('/r');
|
sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('/r');
|
||||||
|
@@ -103,6 +103,12 @@
|
|||||||
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
|
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
|
||||||
window.$wnd = window;
|
window.$wnd = window;
|
||||||
|
|
||||||
|
function flushPreinstalls() {
|
||||||
|
if (window.Gerrit.flushPreinstalls) {
|
||||||
|
window.Gerrit.flushPreinstalls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function installPreloadedPlugins() {
|
function installPreloadedPlugins() {
|
||||||
if (!Gerrit._preloadedPlugins) { return; }
|
if (!Gerrit._preloadedPlugins) { return; }
|
||||||
for (const name in Gerrit._preloadedPlugins) {
|
for (const name in Gerrit._preloadedPlugins) {
|
||||||
@@ -161,6 +167,13 @@
|
|||||||
|
|
||||||
this._url = new URL(opt_url);
|
this._url = new URL(opt_url);
|
||||||
this._name = getPluginNameFromUrl(this._url);
|
this._name = getPluginNameFromUrl(this._url);
|
||||||
|
if (this._url.protocol === PRELOADED_PROTOCOL) {
|
||||||
|
// Original plugin URL is used in plugin assets URLs calculation.
|
||||||
|
const assetsBaseUrl = window.ASSETS_PATH ||
|
||||||
|
(window.location.origin + Gerrit.BaseUrlBehavior.getBaseUrl());
|
||||||
|
this._url = new URL(assetsBaseUrl + '/plugins/' + this._name +
|
||||||
|
'/static/' + this._name + '.js');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin._sharedAPIElement = document.createElement('gr-js-api-interface');
|
Plugin._sharedAPIElement = document.createElement('gr-js-api-interface');
|
||||||
@@ -435,6 +448,8 @@
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
flushPreinstalls();
|
||||||
|
|
||||||
const Gerrit = window.Gerrit || {};
|
const Gerrit = window.Gerrit || {};
|
||||||
|
|
||||||
let _resolveAllPluginsLoaded = null;
|
let _resolveAllPluginsLoaded = null;
|
||||||
@@ -447,6 +462,7 @@
|
|||||||
if (!app) {
|
if (!app) {
|
||||||
// No gr-app found (running tests)
|
// No gr-app found (running tests)
|
||||||
Gerrit._installPreloadedPlugins = installPreloadedPlugins;
|
Gerrit._installPreloadedPlugins = installPreloadedPlugins;
|
||||||
|
Gerrit._flushPreinstalls = flushPreinstalls;
|
||||||
Gerrit._resetPlugins = () => {
|
Gerrit._resetPlugins = () => {
|
||||||
_allPluginsPromise = null;
|
_allPluginsPromise = null;
|
||||||
_pluginsInstalled = [];
|
_pluginsInstalled = [];
|
||||||
|
Reference in New Issue
Block a user