From b3251139803c4f7dc2bfb18c0815440e8d5983cd Mon Sep 17 00:00:00 2001 From: Viktar Donich Date: Thu, 20 Dec 2018 10:26:25 -0800 Subject: [PATCH] Fix plugin .url() calculation when loaded from bundle Assets bundle contains plugin .js files but individual plugins' assets are loaded from window.ASSETS_PATH + "/plugins/${pluginName}/urlhere" This change updates expectations fixed in the test and excludes window.CANONICAL_PATH from calculations when plugin is loaded from another domain. Bug: Issue 10197 Change-Id: Iafc918e529eebacb46b8584f01b1014b0147db52 --- .../gr-js-api-interface/gr-js-api-interface_test.html | 4 ++-- .../shared/gr-js-api-interface/gr-public-js-api.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html index e0c7c37f04..78fba830bb 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html @@ -441,11 +441,11 @@ limitations under the License. test('installing preloaded plugin', () => { let plugin; - window.ASSETS_PATH = 'http://blips.com/chitz/'; + 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'); + 'http://blips.com/chitz/plugins/foo/some/thing.html'); delete window.ASSETS_PATH; }); diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js index 36a428d966..8bf4a2d800 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js @@ -217,9 +217,14 @@ }; Plugin.prototype.url = function(opt_path) { - const base = Gerrit.BaseUrlBehavior.getBaseUrl(); - return this._url.origin + base + '/plugins/' + - this._name + (opt_path || '/'); + const relPath = '/plugins/' + this._name + (opt_path || '/'); + if (window.location.origin === this._url.origin) { + // Plugin loaded from the same origin as gr-app, getBaseUrl in effect. + return this._url.origin + Gerrit.BaseUrlBehavior.getBaseUrl() + relPath; + } else { + // Plugin loaded from assets bundle, expect assets placed along with it. + return this._url.href.split('/plugins/' + this._name)[0] + relPath; + } }; Plugin.prototype.screenUrl = function(opt_screenName) {