diff --git a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.html b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.html
index a3c44e2412..ad4e2b0f8f 100644
--- a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.html
+++ b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.html
@@ -15,6 +15,7 @@ limitations under the License.
-->
+
diff --git a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js
index 3868534b7b..efad106464 100644
--- a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js
+++ b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js
@@ -24,6 +24,10 @@
},
},
+ behaviors: [
+ Gerrit.BaseUrlBehavior,
+ ],
+
_configChanged(config) {
const jsPlugins = config.js_resource_paths || [];
const htmlPlugins = config.html_resource_paths || [];
@@ -33,21 +37,16 @@
},
_importHtmlPlugins(plugins) {
- for (let url of plugins) {
- if (!url.startsWith('http')) {
- url = '/' + url;
- }
+ for (const url of plugins) {
this.importHref(
- url, Gerrit._pluginInstalled, Gerrit._pluginInstalled, true);
+ this._urlFor(url), Gerrit._pluginInstalled, Gerrit._pluginInstalled,
+ true);
}
},
_loadJsPlugins(plugins) {
- for (let url of plugins) {
- if (!url.startsWith('http')) {
- url = '/' + url;
- }
- this._createScriptTag(url);
+ for (const url of plugins) {
+ this._createScriptTag(this._urlFor(url));
}
},
@@ -58,5 +57,12 @@
el.onerror = Gerrit._pluginInstalled;
return document.body.appendChild(el);
},
+
+ _urlFor(pathOrUrl) {
+ if (pathOrUrl.startsWith('http')) {
+ return pathOrUrl;
+ }
+ return this.getBaseUrl() + '/' + pathOrUrl;
+ },
});
})();
diff --git a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html
index b746a3364d..ead07819ed 100644
--- a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html
+++ b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html
@@ -54,7 +54,7 @@ limitations under the License.
assert.isTrue(Gerrit._setPluginsCount.calledWith(3));
});
- test('imports html plugins from config', () => {
+ test('imports relative html plugins from config', () => {
element.config = {
html_resource_paths: ['foo/bar', 'baz'],
};
@@ -64,13 +64,72 @@ limitations under the License.
'/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
});
- test('imports js plugins from config', () => {
+ test('imports relative html plugins from config with a base url', () => {
+ sandbox.stub(element, 'getBaseUrl').returns('/the-base');
+ element.config = {
+ 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));
+ });
+
+ test('imports absolute html plugins from config', () => {
+ element.config = {
+ html_resource_paths: [
+ 'http://example.com/foo/bar',
+ 'https://example.com/baz',
+ ],
+ };
+ 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));
+ });
+
+ test('adds js plugins from config to the body', () => {
+ element.config = {
+ js_resource_paths: ['foo/bar', 'baz'],
+ };
+ assert.isTrue(document.body.appendChild.calledTwice);
+ });
+
+ test('imports relative js plugins from config', () => {
sandbox.stub(element, '_createScriptTag');
element.config = {
- js_resource_paths: ['foo/bar', 'http://baz'],
+ js_resource_paths: ['foo/bar', 'baz'],
};
assert.isTrue(element._createScriptTag.calledWith('/foo/bar'));
- assert.isTrue(element._createScriptTag.calledWith('http://baz'));
+ assert.isTrue(element._createScriptTag.calledWith('/baz'));
+ });
+
+ test('imports relative html plugins from config with a base url', () => {
+ sandbox.stub(element, '_createScriptTag');
+ sandbox.stub(element, 'getBaseUrl').returns('/the-base');
+ element.config = {
+ js_resource_paths: ['foo/bar', 'baz'],
+ };
+ assert.isTrue(element._createScriptTag.calledWith('/the-base/foo/bar'));
+ assert.isTrue(element._createScriptTag.calledWith('/the-base/baz'));
+ });
+
+ test('imports absolute html plugins from config', () => {
+ sandbox.stub(element, '_createScriptTag');
+ element.config = {
+ js_resource_paths: [
+ 'http://example.com/foo/bar',
+ 'https://example.com/baz',
+ ],
+ };
+ assert.isTrue(element._createScriptTag.calledWith(
+ 'http://example.com/foo/bar'));
+ assert.isTrue(element._createScriptTag.calledWith(
+ 'https://example.com/baz'));
});
});
diff --git a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.html b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.html
index 32b6f6729e..4095d3e7c0 100644
--- a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.html
+++ b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.html
@@ -16,6 +16,7 @@ limitations under the License.
+
diff --git a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js
index 166204bf59..5fca577814 100644
--- a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js
+++ b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js
@@ -28,6 +28,10 @@
},
},
+ behaviors: [
+ Gerrit.BaseUrlBehavior,
+ ],
+
created() {
this.hidden = true;
},
@@ -64,7 +68,8 @@
return avatars[i].url;
}
}
- return '/accounts/' + account._account_id + '/avatar?s=' + this.imageSize;
+ return this.getBaseUrl() + '/accounts/' +
+ account._account_id + '/avatar?s=' + this.imageSize;
},
});
})();