Remove mutable export from plugin loader

Change-Id: Id92bc80e7228ccda155ed965837ccb2793a3a3f7
This commit is contained in:
Dhruv Srivastava
2020-09-01 16:40:21 +02:00
parent 003b225260
commit 12e2c99dee
37 changed files with 212 additions and 192 deletions

View File

@@ -39,7 +39,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-admin-view_html.js'; import {htmlTemplate} from './gr-admin-view_html.js';
import {getBaseUrl} from '../../../utils/url-util.js'; import {getBaseUrl} from '../../../utils/url-util.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {getAdminLinks} from '../../../utils/admin-nav-util.js'; import {getAdminLinks} from '../../../utils/admin-nav-util.js';
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/; const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
@@ -112,7 +112,7 @@ class GrAdminView extends GestureEventListeners(
reload() { reload() {
const promises = [ const promises = [
this.$.restAPI.getAccount(), this.$.restAPI.getAccount(),
pluginLoader.awaitPluginsLoaded(), getPluginLoader().awaitPluginsLoaded(),
]; ];
return Promise.all(promises).then(result => { return Promise.all(promises).then(result => {
this._account = result[0]; this._account = result[0];

View File

@@ -19,7 +19,7 @@ import '../../../test/common-test-setup-karma.js';
import './gr-admin-view.js'; import './gr-admin-view.js';
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js'; import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {stubBaseUrl} from '../../../test/test-utils.js'; import {stubBaseUrl} from '../../../test/test-utils.js';
const basicFixture = fixtureFromElement('gr-admin-view'); const basicFixture = fixtureFromElement('gr-admin-view');
@@ -35,7 +35,7 @@ suite('gr-admin-view tests', () => {
}, },
}); });
const pluginsLoaded = Promise.resolve(); const pluginsLoaded = Promise.resolve();
sinon.stub(pluginLoader, 'awaitPluginsLoaded').returns(pluginsLoaded); sinon.stub(getPluginLoader(), 'awaitPluginsLoaded').returns(pluginsLoaded);
pluginsLoaded.then(() => flush(done)); pluginsLoaded.then(() => flush(done));
}); });

View File

@@ -34,7 +34,7 @@ import {ChangeTableMixin} from '../../../mixins/gr-change-table-mixin/gr-change-
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {getDisplayName} from '../../../utils/display-name-util.js'; import {getDisplayName} from '../../../utils/display-name-util.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {appContext} from '../../../services/app-context.js'; import {appContext} from '../../../services/app-context.js';
import {truncatePath} from '../../../utils/path-list-util.js'; import {truncatePath} from '../../../utils/path-list-util.js';
import {changeStatuses} from '../../../utils/change-util.js'; import {changeStatuses} from '../../../utils/change-util.js';
@@ -107,10 +107,11 @@ class GrChangeListItem extends ChangeTableMixin(GestureEventListeners(
/** @override */ /** @override */
attached() { attached() {
super.attached(); super.attached();
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader().awaitPluginsLoaded()
this._dynamicCellEndpoints = getPluginEndpoints().getDynamicEndpoints( .then(() => {
'change-list-item-cell'); this._dynamicCellEndpoints = getPluginEndpoints().getDynamicEndpoints(
}); 'change-list-item-cell');
});
} }
_changeStatuses(change) { _changeStatuses(change) {

View File

@@ -31,7 +31,7 @@ import {ChangeTableMixin} from '../../../mixins/gr-change-table-mixin/gr-change-
import {KeyboardShortcutMixin, Shortcut} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.js'; import {KeyboardShortcutMixin, Shortcut} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {changeIsOpen} from '../../../utils/change-util.js'; import {changeIsOpen} from '../../../utils/change-util.js';
const NUMBER_FIXED_COLUMNS = 3; const NUMBER_FIXED_COLUMNS = 3;
@@ -166,10 +166,11 @@ class GrChangeList extends ChangeTableMixin(
/** @override */ /** @override */
attached() { attached() {
super.attached(); super.attached();
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader().awaitPluginsLoaded()
this._dynamicHeaderEndpoints = getPluginEndpoints().getDynamicEndpoints( .then(() => {
'change-list-header'); this._dynamicHeaderEndpoints = getPluginEndpoints().
}); getDynamicEndpoints('change-list-header');
});
} }
/** /**

View File

@@ -37,7 +37,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-change-actions_html.js'; import {htmlTemplate} from './gr-change-actions_html.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {appContext} from '../../../services/app-context.js'; import {appContext} from '../../../services/app-context.js';
import { import {
fetchChangeUpdates, fetchChangeUpdates,
@@ -551,7 +551,8 @@ class GrChangeActions extends GestureEventListeners(
} }
_handleLoadingComplete() { _handleLoadingComplete() {
pluginLoader.awaitPluginsLoaded().then(() => this._loading = false); getPluginLoader().awaitPluginsLoaded()
.then(() => this._loading = false);
} }
_sendShowRevisionActions(detail) { _sendShowRevisionActions(detail) {

View File

@@ -19,7 +19,7 @@ import '../../../test/common-test-setup-karma.js';
import './gr-change-actions.js'; import './gr-change-actions.js';
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js'; import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {generateChange} from '../../../test/test-utils.js'; import {generateChange} from '../../../test/test-utils.js';
const basicFixture = fixtureFromElement('gr-change-actions'); const basicFixture = fixtureFromElement('gr-change-actions');
@@ -85,7 +85,7 @@ suite('gr-change-actions tests', () => {
getProjectConfig() { return Promise.resolve({}); }, getProjectConfig() { return Promise.resolve({}); },
}); });
sinon.stub(pluginLoader, 'awaitPluginsLoaded') sinon.stub(getPluginLoader(), 'awaitPluginsLoaded')
.returns(Promise.resolve()); .returns(Promise.resolve());
element = basicFixture.instantiate(); element = basicFixture.instantiate();
@@ -2013,7 +2013,7 @@ suite('gr-change-actions tests', () => {
getProjectConfig() { return Promise.resolve({}); }, getProjectConfig() { return Promise.resolve({}); },
}); });
sinon.stub(pluginLoader, 'awaitPluginsLoaded') sinon.stub(getPluginLoader(), 'awaitPluginsLoaded')
.returns(Promise.resolve()); .returns(Promise.resolve());
element = basicFixture.instantiate(); element = basicFixture.instantiate();

View File

@@ -19,7 +19,7 @@ import '../../../test/common-test-setup-karma.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
import './gr-change-metadata.js'; import './gr-change-metadata.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
const testHtmlPlugin = document.createElement('dom-module'); const testHtmlPlugin = document.createElement('dom-module');
@@ -117,10 +117,11 @@ suite('gr-change-metadata integration tests', () => {
plugin.registerStyleModule('change-metadata', 'my-plugin-style'); plugin.registerStyleModule('change-metadata', 'my-plugin-style');
}, undefined, 'http://test.com/plugins/style.js'); }, undefined, 'http://test.com/plugins/style.js');
element = createElement(); element = createElement();
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader().awaitPluginsLoaded()
flush(done); .then(() => {
}); flush(done);
});
}); });
teardown(() => { teardown(() => {
@@ -143,8 +144,8 @@ suite('gr-change-metadata integration tests', () => {
plugin = p; plugin = p;
plugin.registerStyleModule('change-metadata', 'my-plugin-style'); plugin.registerStyleModule('change-metadata', 'my-plugin-style');
}, undefined, 'http://test.com/plugins/style.js'); }, undefined, 'http://test.com/plugins/style.js');
sinon.stub(pluginLoader, 'arePluginsLoaded').returns(true); sinon.stub(getPluginLoader(), 'arePluginsLoaded').returns(true);
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
element = createElement(); element = createElement();
}); });

View File

@@ -19,7 +19,7 @@ import '../../../test/common-test-setup-karma.js';
import '../../core/gr-router/gr-router.js'; import '../../core/gr-router/gr-router.js';
import './gr-change-metadata.js'; import './gr-change-metadata.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
const basicFixture = fixtureFromElement('gr-change-metadata'); const basicFixture = fixtureFromElement('gr-change-metadata');
@@ -763,7 +763,7 @@ suite('gr-change-metadata tests', () => {
}, },
'0.1', '0.1',
'http://some/plugins/url.html'); 'http://some/plugins/url.html');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
flush(() => { flush(() => {
assert.strictEqual(hookEl.plugin, plugin); assert.strictEqual(hookEl.plugin, plugin);
assert.strictEqual(hookEl.change, element.change); assert.strictEqual(hookEl.change, element.change);

View File

@@ -56,7 +56,7 @@ import {GrCountStringFormatter} from '../../shared/gr-count-string-formatter/gr-
import {getComputedStyleValue} from '../../../utils/dom-util.js'; import {getComputedStyleValue} from '../../../utils/dom-util.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {RevisionInfo} from '../../shared/revision-info/revision-info.js'; import {RevisionInfo} from '../../shared/revision-info/revision-info.js';
import {PrimaryTab, SecondaryTab} from '../../../constants/constants.js'; import {PrimaryTab, SecondaryTab} from '../../../constants/constants.js';
import {NO_ROBOT_COMMENTS_THREADS_MSG} from '../../../constants/messages.js'; import {NO_ROBOT_COMMENTS_THREADS_MSG} from '../../../constants/messages.js';
@@ -498,7 +498,7 @@ class GrChangeView extends KeyboardShortcutMixin(
this._setDiffViewMode(); this._setDiffViewMode();
}); });
pluginLoader.awaitPluginsLoaded() getPluginLoader().awaitPluginsLoaded()
.then(() => { .then(() => {
this._dynamicTabHeaderEndpoints = this._dynamicTabHeaderEndpoints =
getPluginEndpoints().getDynamicEndpoints('change-view-tab-header'); getPluginEndpoints().getDynamicEndpoints('change-view-tab-header');
@@ -1075,9 +1075,10 @@ class GrChangeView extends KeyboardShortcutMixin(
this._performPostLoadTasks(); this._performPostLoadTasks();
}); });
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader().awaitPluginsLoaded()
this._initActiveTabs(value); .then(() => {
}); this._initActiveTabs(value);
});
} }
_initActiveTabs(params = {}) { _initActiveTabs(params = {}) {
@@ -1180,7 +1181,7 @@ class GrChangeView extends KeyboardShortcutMixin(
} }
_maybeShowRevertDialog() { _maybeShowRevertDialog() {
pluginLoader.awaitPluginsLoaded() getPluginLoader().awaitPluginsLoaded()
.then(this._getLoggedIn.bind(this)) .then(this._getLoggedIn.bind(this))
.then(loggedIn => { .then(loggedIn => {
if (!loggedIn || !this._change || if (!loggedIn || !this._change ||

View File

@@ -25,7 +25,7 @@ import {GrEditConstants} from '../../edit/gr-edit-constants.js';
import {_testOnly_resetEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {_testOnly_resetEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {getComputedStyleValue} from '../../../utils/dom-util.js'; import {getComputedStyleValue} from '../../../utils/dom-util.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {EventType} from '../../plugins/gr-plugin-types.js'; import {EventType} from '../../plugins/gr-plugin-types.js';
@@ -301,7 +301,7 @@ suite('gr-change-view tests', () => {
}); });
element = fixture.instantiate(); element = fixture.instantiate();
sinon.stub(element.$.actions, 'reload').returns(Promise.resolve()); sinon.stub(element.$.actions, 'reload').returns(Promise.resolve());
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
pluginApi.install( pluginApi.install(
plugin => { plugin => {
plugin.registerDynamicCustomComponent( plugin.registerDynamicCustomComponent(
@@ -1642,7 +1642,7 @@ suite('gr-change-view tests', () => {
test('revert dialog opened with revert param', done => { test('revert dialog opened with revert param', done => {
sinon.stub(element.$.restAPI, 'getLoggedIn') sinon.stub(element.$.restAPI, 'getLoggedIn')
.callsFake(() => Promise.resolve(true)); .callsFake(() => Promise.resolve(true));
sinon.stub(pluginLoader, 'awaitPluginsLoaded') sinon.stub(getPluginLoader(), 'awaitPluginsLoaded')
.callsFake(() => Promise.resolve()); .callsFake(() => Promise.resolve());
element._patchRange = { element._patchRange = {
@@ -1671,7 +1671,7 @@ suite('gr-change-view tests', () => {
done); done);
element._maybeShowRevertDialog(); element._maybeShowRevertDialog();
assert.isTrue(pluginLoader.awaitPluginsLoaded.called); assert.isTrue(getPluginLoader().awaitPluginsLoaded.called);
}); });
suite('scroll related tests', () => { suite('scroll related tests', () => {

View File

@@ -38,7 +38,7 @@ import {GrFileListConstants} from '../gr-file-list-constants.js';
import {GrCountStringFormatter} from '../../shared/gr-count-string-formatter/gr-count-string-formatter.js'; import {GrCountStringFormatter} from '../../shared/gr-count-string-formatter/gr-count-string-formatter.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {appContext} from '../../../services/app-context.js'; import {appContext} from '../../../services/app-context.js';
import {SpecialFilePath} from '../../../constants/constants.js'; import {SpecialFilePath} from '../../../constants/constants.js';
import {descendedFromClass} from '../../../utils/dom-util.js'; import {descendedFromClass} from '../../../utils/dom-util.js';
@@ -310,34 +310,35 @@ class GrFileList extends KeyboardShortcutMixin(
/** @override */ /** @override */
attached() { attached() {
super.attached(); super.attached();
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader().awaitPluginsLoaded()
this._dynamicHeaderEndpoints = getPluginEndpoints() .then(() => {
.getDynamicEndpoints('change-view-file-list-header'); this._dynamicHeaderEndpoints = getPluginEndpoints()
this._dynamicContentEndpoints = getPluginEndpoints() .getDynamicEndpoints('change-view-file-list-header');
.getDynamicEndpoints('change-view-file-list-content'); this._dynamicContentEndpoints = getPluginEndpoints()
this._dynamicPrependedHeaderEndpoints = getPluginEndpoints() .getDynamicEndpoints('change-view-file-list-content');
.getDynamicEndpoints('change-view-file-list-header-prepend'); this._dynamicPrependedHeaderEndpoints = getPluginEndpoints()
this._dynamicPrependedContentEndpoints = getPluginEndpoints() .getDynamicEndpoints('change-view-file-list-header-prepend');
.getDynamicEndpoints('change-view-file-list-content-prepend'); this._dynamicPrependedContentEndpoints = getPluginEndpoints()
this._dynamicSummaryEndpoints = getPluginEndpoints() .getDynamicEndpoints('change-view-file-list-content-prepend');
.getDynamicEndpoints('change-view-file-list-summary'); this._dynamicSummaryEndpoints = getPluginEndpoints()
.getDynamicEndpoints('change-view-file-list-summary');
if (this._dynamicHeaderEndpoints.length !== if (this._dynamicHeaderEndpoints.length !==
this._dynamicContentEndpoints.length) { this._dynamicContentEndpoints.length) {
console.warn( console.warn(
'Different number of dynamic file-list header and content.'); 'Different number of dynamic file-list header and content.');
} }
if (this._dynamicPrependedHeaderEndpoints.length !== if (this._dynamicPrependedHeaderEndpoints.length !==
this._dynamicPrependedContentEndpoints.length) { this._dynamicPrependedContentEndpoints.length) {
console.warn( console.warn(
'Different number of dynamic file-list header and content.'); 'Different number of dynamic file-list header and content.');
} }
if (this._dynamicHeaderEndpoints.length !== if (this._dynamicHeaderEndpoints.length !==
this._dynamicSummaryEndpoints.length) { this._dynamicSummaryEndpoints.length) {
console.warn( console.warn(
'Different number of dynamic file-list headers and summary.'); 'Different number of dynamic file-list headers and summary.');
} }
}); });
} }
/** @override */ /** @override */

View File

@@ -18,7 +18,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import './gr-related-changes-list.js'; import './gr-related-changes-list.js';
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
@@ -581,7 +581,7 @@ suite('gr-related-changes-list plugin tests', () => {
}, },
'0.1', '0.1',
'http://some/plugins/url1.html'); 'http://some/plugins/url1.html');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
flush(() => { flush(() => {
assert.strictEqual(hookEl.plugin, plugin); assert.strictEqual(hookEl.plugin, plugin);
assert.strictEqual(hookEl.change, element.change); assert.strictEqual(hookEl.change, element.change);
@@ -605,7 +605,7 @@ suite('gr-related-changes-list plugin tests', () => {
}, },
'0.1', '0.1',
'http://some/plugins/url2.html'); 'http://some/plugins/url2.html');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
flush(() => { flush(() => {
// No changes, and plugin without hidden attribute. So it's visible. // No changes, and plugin without hidden attribute. So it's visible.
element._resultsChanged({}, {}, [], [], []); element._resultsChanged({}, {}, [], [], []);

View File

@@ -19,7 +19,7 @@ import '../../../test/common-test-setup-karma.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
import './gr-reply-dialog.js'; import './gr-reply-dialog.js';
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js'; import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
const basicFixture = fixtureFromElement('gr-reply-dialog'); const basicFixture = fixtureFromElement('gr-reply-dialog');
const pluginApi = _testOnly_initGerritPluginApi(); const pluginApi = _testOnly_initGerritPluginApi();
@@ -122,20 +122,21 @@ suite('gr-reply-dialog-it tests', () => {
}, null, 'http://test.com/plugins/lgtm.js'); }, null, 'http://test.com/plugins/lgtm.js');
element = basicFixture.instantiate(); element = basicFixture.instantiate();
setupElement(element); setupElement(element);
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader().awaitPluginsLoaded()
flush(() => { .then(() => {
const textarea = element.$.textarea.getNativeTextarea(); flush(() => {
textarea.value = 'LGTM'; const textarea = element.$.textarea.getNativeTextarea();
textarea.dispatchEvent(new CustomEvent( textarea.value = 'LGTM';
'input', {bubbles: true, composed: true})); textarea.dispatchEvent(new CustomEvent(
const labelScoreRows = dom(element.$.labelScores.root) 'input', {bubbles: true, composed: true}));
.querySelector('gr-label-score-row[name="Code-Review"]'); const labelScoreRows = dom(element.$.labelScores.root)
const selectedBtn = dom(labelScoreRows.root) .querySelector('gr-label-score-row[name="Code-Review"]');
.querySelector('gr-button[data-value="+1"].iron-selected'); const selectedBtn = dom(labelScoreRows.root)
assert.isOk(selectedBtn); .querySelector('gr-button[data-value="+1"].iron-selected');
done(); assert.isOk(selectedBtn);
}); done();
}); });
});
}); });
}); });

View File

@@ -26,7 +26,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-main-header_html.js'; import {htmlTemplate} from './gr-main-header_html.js';
import {getBaseUrl, getDocsBaseUrl} from '../../../utils/url-util.js'; import {getBaseUrl, getDocsBaseUrl} from '../../../utils/url-util.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {getAdminLinks} from '../../../utils/admin-nav-util.js'; import {getAdminLinks} from '../../../utils/admin-nav-util.js';
const DEFAULT_LINKS = [{ const DEFAULT_LINKS = [{
@@ -259,7 +259,7 @@ class GrMainHeader extends GestureEventListeners(
const promises = [ const promises = [
this.$.restAPI.getAccount(), this.$.restAPI.getAccount(),
this.$.restAPI.getTopMenus(), this.$.restAPI.getTopMenus(),
pluginLoader.awaitPluginsLoaded(), getPluginLoader().awaitPluginsLoaded(),
]; ];
return Promise.all(promises).then(result => { return Promise.all(promises).then(result => {

View File

@@ -19,7 +19,7 @@ import '../test/common-test-setup-karma.js';
import {getComputedStyleValue} from '../utils/dom-util.js'; import {getComputedStyleValue} from '../utils/dom-util.js';
import './shared/gr-rest-api-interface/gr-rest-api-interface.js'; import './shared/gr-rest-api-interface/gr-rest-api-interface.js';
import './gr-app.js'; import './gr-app.js';
import {pluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js';
import {removeTheme} from '../styles/themes/dark-theme.js'; import {removeTheme} from '../styles/themes/dark-theme.js';
const basicFixture = fixtureFromElement('gr-app'); const basicFixture = fixtureFromElement('gr-app');
@@ -30,8 +30,9 @@ suite('gr-app custom dark theme tests', () => {
window.localStorage.setItem('dark-theme', 'true'); window.localStorage.setItem('dark-theme', 'true');
element = basicFixture.instantiate(); element = basicFixture.instantiate();
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
pluginLoader.awaitPluginsLoaded().then(() => flush(done)); getPluginLoader().awaitPluginsLoaded()
.then(() => flush(done));
}); });
teardown(() => { teardown(() => {

View File

@@ -19,7 +19,7 @@ import '../test/common-test-setup-karma.js';
import {getComputedStyleValue} from '../utils/dom-util.js'; import {getComputedStyleValue} from '../utils/dom-util.js';
import './shared/gr-rest-api-interface/gr-rest-api-interface.js'; import './shared/gr-rest-api-interface/gr-rest-api-interface.js';
import './gr-app.js'; import './gr-app.js';
import {pluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js';
const basicFixture = fixtureFromElement('gr-app'); const basicFixture = fixtureFromElement('gr-app');
@@ -36,8 +36,9 @@ suite('gr-app custom light theme tests', () => {
_fetchSharedCacheURL() { return Promise.resolve({}); }, _fetchSharedCacheURL() { return Promise.resolve({}); },
}); });
element = basicFixture.instantiate(); element = basicFixture.instantiate();
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
pluginLoader.awaitPluginsLoaded().then(() => flush(done)); getPluginLoader().awaitPluginsLoaded()
.then(() => flush(done));
}); });
teardown(() => { teardown(() => {
// The app sends requests to server. This can lead to // The app sends requests to server. This can lead to

View File

@@ -60,7 +60,7 @@ import {GrPluginRestApi} from './shared/gr-js-api-interface/gr-plugin-rest-api.j
import {GrRepoApi} from './plugins/gr-repo-api/gr-repo-api.js'; import {GrRepoApi} from './plugins/gr-repo-api/gr-repo-api.js';
import {GrSettingsApi} from './plugins/gr-settings-api/gr-settings-api.js'; import {GrSettingsApi} from './plugins/gr-settings-api/gr-settings-api.js';
import {GrStylesApi} from './plugins/gr-styles-api/gr-styles-api.js'; import {GrStylesApi} from './plugins/gr-styles-api/gr-styles-api.js';
import {pluginLoader, PluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader, PluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js';
import {GrPluginActionContext} from './shared/gr-js-api-interface/gr-plugin-action-context.js'; import {GrPluginActionContext} from './shared/gr-js-api-interface/gr-plugin-action-context.js';
import {getPluginNameFromUrl, getRestAPI, PLUGIN_LOADING_TIMEOUT_MS, PRELOADED_PROTOCOL, send} from './shared/gr-js-api-interface/gr-api-utils.js'; import {getPluginNameFromUrl, getRestAPI, PLUGIN_LOADING_TIMEOUT_MS, PRELOADED_PROTOCOL, send} from './shared/gr-js-api-interface/gr-api-utils.js';
import {getBaseUrl} from '../utils/url-util.js'; import {getBaseUrl} from '../utils/url-util.js';
@@ -138,7 +138,7 @@ export function initGlobalVariables() {
window.Gerrit.getRootElement = getRootElement; window.Gerrit.getRootElement = getRootElement;
window.Gerrit.Auth = appContext.authService; window.Gerrit.Auth = appContext.authService;
window.Gerrit._pluginLoader = pluginLoader; window.Gerrit._pluginLoader = getPluginLoader();
// TODO: should define as a getter // TODO: should define as a getter
window.Gerrit._endpoints = getPluginEndpoints(); window.Gerrit._endpoints = getPluginEndpoints();

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import '../../shared/gr-js-api-interface/gr-js-api-interface.js'; import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
const pluginApi = _testOnly_initGerritPluginApi(); const pluginApi = _testOnly_initGerritPluginApi();
@@ -29,7 +29,7 @@ suite('gr-admin-api tests', () => {
let plugin; let plugin;
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
adminApi = plugin.admin(); adminApi = plugin.admin();
}); });

View File

@@ -20,7 +20,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-endpoint-decorator_html.js'; import {htmlTemplate} from './gr-endpoint-decorator_html.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
const INIT_PROPERTIES_TIMEOUT_MS = 10000; const INIT_PROPERTIES_TIMEOUT_MS = 10000;
@@ -162,7 +162,7 @@ class GrEndpointDecorator extends GestureEventListeners(
this._endpointCallBack = this._initModule.bind(this); this._endpointCallBack = this._initModule.bind(this);
getPluginEndpoints().onNewEndpoint(this.name, this._endpointCallBack); getPluginEndpoints().onNewEndpoint(this.name, this._endpointCallBack);
if (this.name) { if (this.name) {
pluginLoader.awaitPluginsLoaded() getPluginLoader().awaitPluginsLoaded()
.then(() => getPluginEndpoints().getAndImportPlugins(this.name)) .then(() => getPluginEndpoints().getAndImportPlugins(this.name))
.then(() => .then(() =>
getPluginEndpoints() getPluginEndpoints()

View File

@@ -21,7 +21,7 @@ import '../gr-endpoint-param/gr-endpoint-param.js';
import '../gr-endpoint-slot/gr-endpoint-slot.js'; import '../gr-endpoint-slot/gr-endpoint-slot.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
@@ -71,7 +71,7 @@ suite('gr-endpoint-decorator', () => {
replacementHook = plugin.registerCustomComponent( replacementHook = plugin.registerCustomComponent(
'second', 'other-module', {replace: true}); 'second', 'other-module', {replace: true});
// Mimic all plugins loaded. // Mimic all plugins loaded.
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
flush(done); flush(done);
}); });

View File

@@ -21,7 +21,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-external-style_html.js'; import {htmlTemplate} from './gr-external-style_html.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
/** @extends PolymerElement */ /** @extends PolymerElement */
class GrExternalStyle extends GestureEventListeners( class GrExternalStyle extends GestureEventListeners(
@@ -75,7 +75,8 @@ class GrExternalStyle extends GestureEventListeners(
/** @override */ /** @override */
ready() { ready() {
super.ready(); super.ready();
pluginLoader.awaitPluginsLoaded().then(() => this._importAndApply()); getPluginLoader().awaitPluginsLoaded()
.then(() => this._importAndApply());
} }
} }

View File

@@ -18,7 +18,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
import './gr-external-style.js'; import './gr-external-style.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
@@ -68,7 +68,7 @@ suite('gr-external-style integration tests', () => {
setup(() => { setup(() => {
sinon.stub(getPluginEndpoints(), 'importUrl') sinon.stub(getPluginEndpoints(), 'importUrl')
.callsFake( url => Promise.resolve()); .callsFake( url => Promise.resolve());
sinon.stub(pluginLoader, 'awaitPluginsLoaded') sinon.stub(getPluginLoader(), 'awaitPluginsLoaded')
.returns(Promise.resolve()); .returns(Promise.resolve());
}); });

View File

@@ -18,7 +18,7 @@ import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js'; import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js'; import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
/** @extends PolymerElement */ /** @extends PolymerElement */
class GrPluginHost extends GestureEventListeners( class GrPluginHost extends GestureEventListeners(
@@ -42,7 +42,7 @@ class GrPluginHost extends GestureEventListeners(
plugins && plugins.js_resource_paths || [], htmlPlugins plugins && plugins.js_resource_paths || [], htmlPlugins
); );
const shouldLoadTheme = config.default_theme && const shouldLoadTheme = config.default_theme &&
!pluginLoader.isPluginPreloaded('preloaded:gerrit-theme'); !getPluginLoader().isPluginPreloaded('preloaded:gerrit-theme');
const themeToLoad = const themeToLoad =
shouldLoadTheme ? [config.default_theme] : []; shouldLoadTheme ? [config.default_theme] : [];
@@ -57,7 +57,7 @@ class GrPluginHost extends GestureEventListeners(
pluginOpts[config.default_theme] = {sync: true}; pluginOpts[config.default_theme] = {sync: true};
} }
pluginLoader.loadPlugins(pluginsPending, pluginOpts); getPluginLoader().loadPlugins(pluginsPending, pluginOpts);
} }
/** /**

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import './gr-plugin-host.js'; import './gr-plugin-host.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
const basicFixture = fixtureFromElement('gr-plugin-host'); const basicFixture = fixtureFromElement('gr-plugin-host');
@@ -31,21 +31,21 @@ suite('gr-plugin-host tests', () => {
}); });
test('load plugins should be called', () => { test('load plugins should be called', () => {
sinon.stub(pluginLoader, 'loadPlugins'); sinon.stub(getPluginLoader(), 'loadPlugins');
element.config = { element.config = {
plugin: { plugin: {
html_resource_paths: ['plugins/foo/bar', 'plugins/baz'], html_resource_paths: ['plugins/foo/bar', 'plugins/baz'],
js_resource_paths: ['plugins/42'], js_resource_paths: ['plugins/42'],
}, },
}; };
assert.isTrue(pluginLoader.loadPlugins.calledOnce); assert.isTrue(getPluginLoader().loadPlugins.calledOnce);
assert.isTrue(pluginLoader.loadPlugins.calledWith([ assert.isTrue(getPluginLoader().loadPlugins.calledWith([
'plugins/42', 'plugins/foo/bar', 'plugins/baz', 'plugins/42', 'plugins/foo/bar', 'plugins/baz',
], {})); ], {}));
}); });
test('theme plugins should be loaded if enabled', () => { test('theme plugins should be loaded if enabled', () => {
sinon.stub(pluginLoader, 'loadPlugins'); sinon.stub(getPluginLoader(), 'loadPlugins');
element.config = { element.config = {
default_theme: 'gerrit-theme.html', default_theme: 'gerrit-theme.html',
plugin: { plugin: {
@@ -53,23 +53,23 @@ suite('gr-plugin-host tests', () => {
js_resource_paths: ['plugins/42'], js_resource_paths: ['plugins/42'],
}, },
}; };
assert.isTrue(pluginLoader.loadPlugins.calledOnce); assert.isTrue(getPluginLoader().loadPlugins.calledOnce);
assert.isTrue(pluginLoader.loadPlugins.calledWith([ assert.isTrue(getPluginLoader().loadPlugins.calledWith([
'gerrit-theme.html', 'plugins/42', 'plugins/foo/bar', 'plugins/baz', 'gerrit-theme.html', 'plugins/42', 'plugins/foo/bar', 'plugins/baz',
], {'gerrit-theme.html': {sync: true}})); ], {'gerrit-theme.html': {sync: true}}));
}); });
test('skip theme if preloaded', () => { test('skip theme if preloaded', () => {
sinon.stub(pluginLoader, 'isPluginPreloaded') sinon.stub(getPluginLoader(), 'isPluginPreloaded')
.withArgs('preloaded:gerrit-theme') .withArgs('preloaded:gerrit-theme')
.returns(true); .returns(true);
sinon.stub(pluginLoader, 'loadPlugins'); sinon.stub(getPluginLoader(), 'loadPlugins');
element.config = { element.config = {
default_theme: '/oof', default_theme: '/oof',
plugin: {}, plugin: {},
}; };
assert.isTrue(pluginLoader.loadPlugins.calledOnce); assert.isTrue(getPluginLoader().loadPlugins.calledOnce);
assert.isTrue(pluginLoader.loadPlugins.calledWith([], {})); assert.isTrue(getPluginLoader().loadPlugins.calledWith([], {}));
}); });
}); });

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import '../gr-endpoint-decorator/gr-endpoint-decorator.js'; import '../gr-endpoint-decorator/gr-endpoint-decorator.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
@@ -35,7 +35,7 @@ suite('gr-repo-api tests', () => {
let plugin; let plugin;
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
repoApi = plugin.project(); repoApi = plugin.project();
}); });

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import '../gr-endpoint-decorator/gr-endpoint-decorator.js'; import '../gr-endpoint-decorator/gr-endpoint-decorator.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
@@ -37,7 +37,7 @@ suite('gr-settings-api tests', () => {
let plugin; let plugin;
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
settingsApi = plugin.settings(); settingsApi = plugin.settings();
}); });

View File

@@ -18,7 +18,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import '../../shared/gr-js-api-interface/gr-js-api-interface.js'; import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
@@ -41,7 +41,7 @@ suite('gr-styles-api tests', () => {
let plugin; let plugin;
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
stylesApi = plugin.styles(); stylesApi = plugin.styles();
}); });
@@ -68,7 +68,7 @@ suite('gr-styles-api tests', () => {
let plugin; let plugin;
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
stylesApi = plugin.styles(); stylesApi = plugin.styles();
displayInlineStyle = stylesApi.css('display: inline'); displayInlineStyle = stylesApi.css('display: inline');
displayNoneStyle = stylesApi.css('display: none'); displayNoneStyle = stylesApi.css('display: none');

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import '../gr-endpoint-decorator/gr-endpoint-decorator.js'; import '../gr-endpoint-decorator/gr-endpoint-decorator.js';
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js'; import {html} from '@polymer/polymer/lib/utils/html-tag.js';
@@ -56,7 +56,7 @@ suite('gr-theme-api tests', () => {
/** @override */ /** @override */
ready() { customHeader = this; }, ready() { customHeader = this; },
}); });
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
}); });
test('sets logo and title', done => { test('sets logo and title', done => {

View File

@@ -22,7 +22,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-avatar_html.js'; import {htmlTemplate} from './gr-avatar_html.js';
import {getBaseUrl} from '../../../utils/url-util.js'; import {getBaseUrl} from '../../../utils/url-util.js';
import {pluginLoader} from '../gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../gr-js-api-interface/gr-plugin-loader.js';
/** /**
* @extends PolymerElement * @extends PolymerElement
@@ -56,7 +56,7 @@ class GrAvatar extends GestureEventListeners(
super.attached(); super.attached();
Promise.all([ Promise.all([
this._getConfig(), this._getConfig(),
pluginLoader.awaitPluginsLoaded(), getPluginLoader().awaitPluginsLoaded(),
]).then(([cfg]) => { ]).then(([cfg]) => {
this._hasAvatars = !!(cfg && cfg.plugin && cfg.plugin.has_avatars); this._hasAvatars = !!(cfg && cfg.plugin && cfg.plugin.has_avatars);

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import './gr-avatar.js'; import './gr-avatar.js';
import {pluginLoader} from '../gr-js-api-interface/gr-plugin-loader.js'; import {getPluginLoader} from '../gr-js-api-interface/gr-plugin-loader.js';
const basicFixture = fixtureFromElement('gr-avatar'); const basicFixture = fixtureFromElement('gr-avatar');
@@ -101,11 +101,11 @@ suite('gr-avatar tests', () => {
assert.strictEqual(element.style.backgroundImage, ''); assert.strictEqual(element.style.backgroundImage, '');
// Emulate plugins loaded. // Emulate plugins loaded.
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
return Promise.all([ return Promise.all([
element.$.restAPI.getConfig(), element.$.restAPI.getConfig(),
pluginLoader.awaitPluginsLoaded(), getPluginLoader().awaitPluginsLoaded(),
]).then(() => { ]).then(() => {
assert.isFalse(element.hasAttribute('hidden')); assert.isFalse(element.hasAttribute('hidden'));
@@ -131,11 +131,11 @@ suite('gr-avatar tests', () => {
assert.isFalse(element.hasAttribute('hidden')); assert.isFalse(element.hasAttribute('hidden'));
// Emulate plugins loaded. // Emulate plugins loaded.
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
return Promise.all([ return Promise.all([
element.$.restAPI.getConfig(), element.$.restAPI.getConfig(),
pluginLoader.awaitPluginsLoaded(), getPluginLoader().awaitPluginsLoaded(),
]).then(() => { ]).then(() => {
assert.isTrue(element.hasAttribute('hidden')); assert.isTrue(element.hasAttribute('hidden'));
@@ -164,11 +164,11 @@ suite('gr-avatar tests', () => {
_account_id: 123, _account_id: 123,
}; };
// Emulate plugins loaded. // Emulate plugins loaded.
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
return Promise.all([ return Promise.all([
element.$.restAPI.getConfig(), element.$.restAPI.getConfig(),
pluginLoader.awaitPluginsLoaded(), getPluginLoader().awaitPluginsLoaded(),
]).then(() => { ]).then(() => {
assert.isTrue(element.hasAttribute('hidden')); assert.isTrue(element.hasAttribute('hidden'));
}); });

View File

@@ -18,7 +18,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import '../../change/gr-change-actions/gr-change-actions.js'; import '../../change/gr-change-actions/gr-change-actions.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
import {pluginLoader} from './gr-plugin-loader.js'; import {getPluginLoader} from './gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from './gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from './gr-gerrit.js';
const basicFixture = fixtureFromElement('gr-change-actions'); const basicFixture = fixtureFromElement('gr-change-actions');
@@ -44,7 +44,7 @@ suite('gr-change-actions-js-api-interface tests', () => {
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
// Mimic all plugins loaded. // Mimic all plugins loaded.
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
changeActions = plugin.changeActions(); changeActions = plugin.changeActions();
element = basicFixture.instantiate(); element = basicFixture.instantiate();
}); });
@@ -72,7 +72,7 @@ suite('gr-change-actions-js-api-interface tests', () => {
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
changeActions = plugin.changeActions(); changeActions = plugin.changeActions();
// Mimic all plugins loaded. // Mimic all plugins loaded.
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
}); });
teardown(() => { teardown(() => {

View File

@@ -19,7 +19,7 @@
* This defines the Gerrit instance. All methods directly attached to Gerrit * This defines the Gerrit instance. All methods directly attached to Gerrit
* should be defined or linked here. * should be defined or linked here.
*/ */
import {pluginLoader, PluginOptionMap} from './gr-plugin-loader'; import {getPluginLoader, PluginOptionMap} from './gr-plugin-loader';
import {getRestAPI, send} from './gr-api-utils'; import {getRestAPI, send} from './gr-api-utils';
import {appContext} from '../../../services/app-context'; import {appContext} from '../../../services/app-context';
import {PluginApi} from '../../plugins/gr-plugin-types'; import {PluginApi} from '../../plugins/gr-plugin-types';
@@ -81,7 +81,7 @@ export function initGerritPluginApi() {
// Preloaded plugins should be installed after Gerrit.install() is set, // Preloaded plugins should be installed after Gerrit.install() is set,
// since plugin preloader substitutes Gerrit.install() temporarily. // since plugin preloader substitutes Gerrit.install() temporarily.
// (Gerrit.install() is set in initGerritPluginsMethods) // (Gerrit.install() is set in initGerritPluginsMethods)
pluginLoader.installPreloadedPlugins(); getPluginLoader().installPreloadedPlugins();
} }
export function _testOnly_initGerritPluginApi(): GerritGlobal { export function _testOnly_initGerritPluginApi(): GerritGlobal {
@@ -136,7 +136,7 @@ function initGerritPluginsMethods(globalGerritObj: GerritGlobal) {
}; };
globalGerritObj.install = (callback, opt_version, opt_src) => { globalGerritObj.install = (callback, opt_version, opt_src) => {
pluginLoader.install(callback, opt_version, opt_src); getPluginLoader().install(callback, opt_version, opt_src);
}; };
globalGerritObj.getLoggedIn = () => { globalGerritObj.getLoggedIn = () => {
@@ -181,29 +181,29 @@ function initGerritPluginsMethods(globalGerritObj: GerritGlobal) {
}; };
globalGerritObj.awaitPluginsLoaded = () => { globalGerritObj.awaitPluginsLoaded = () => {
return pluginLoader.awaitPluginsLoaded(); return getPluginLoader().awaitPluginsLoaded();
}; };
// TODO(taoalpha): consider removing these proxy methods // TODO(taoalpha): consider removing these proxy methods
// and using pluginLoader directly // and using getPluginLoader() directly
globalGerritObj._loadPlugins = (plugins, opt_option) => { globalGerritObj._loadPlugins = (plugins, opt_option) => {
pluginLoader.loadPlugins(plugins, opt_option); getPluginLoader().loadPlugins(plugins, opt_option);
}; };
globalGerritObj._arePluginsLoaded = () => { globalGerritObj._arePluginsLoaded = () => {
return pluginLoader.arePluginsLoaded(); return getPluginLoader().arePluginsLoaded();
}; };
globalGerritObj._isPluginPreloaded = url => { globalGerritObj._isPluginPreloaded = url => {
return pluginLoader.isPluginPreloaded(url); return getPluginLoader().isPluginPreloaded(url);
}; };
globalGerritObj._isPluginEnabled = pathOrUrl => { globalGerritObj._isPluginEnabled = pathOrUrl => {
return pluginLoader.isPluginEnabled(pathOrUrl); return getPluginLoader().isPluginEnabled(pathOrUrl);
}; };
globalGerritObj._isPluginLoaded = pathOrUrl => { globalGerritObj._isPluginLoaded = pathOrUrl => {
return pluginLoader.isPluginLoaded(pathOrUrl); return getPluginLoader().isPluginLoaded(pathOrUrl);
}; };
const eventEmitter = appContext.eventEmitter; const eventEmitter = appContext.eventEmitter;

View File

@@ -17,7 +17,7 @@
import '../../../test/common-test-setup-karma.js'; import '../../../test/common-test-setup-karma.js';
import './gr-js-api-interface.js'; import './gr-js-api-interface.js';
import {pluginLoader} from './gr-plugin-loader.js'; import {getPluginLoader} from './gr-plugin-loader.js';
import {resetPlugins} from '../../../test/test-utils.js'; import {resetPlugins} from '../../../test/test-utils.js';
import {_testOnly_initGerritPluginApi} from './gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from './gr-gerrit.js';
@@ -52,10 +52,10 @@ suite('gr-gerrit tests', () => {
}); });
suite('proxy methods', () => { suite('proxy methods', () => {
test('Gerrit._isPluginEnabled proxy to pluginLoader', () => { test('Gerrit._isPluginEnabled proxy to getPluginLoader()', () => {
const stubFn = sinon.stub(); const stubFn = sinon.stub();
sinon.stub( sinon.stub(
pluginLoader, getPluginLoader(),
'isPluginEnabled') 'isPluginEnabled')
.callsFake((...args) => stubFn(...args) .callsFake((...args) => stubFn(...args)
); );
@@ -63,20 +63,20 @@ suite('gr-gerrit tests', () => {
assert.isTrue(stubFn.calledWith('test_plugin')); assert.isTrue(stubFn.calledWith('test_plugin'));
}); });
test('Gerrit._isPluginLoaded proxy to pluginLoader', () => { test('Gerrit._isPluginLoaded proxy to getPluginLoader()', () => {
const stubFn = sinon.stub(); const stubFn = sinon.stub();
sinon.stub( sinon.stub(
pluginLoader, getPluginLoader(),
'isPluginLoaded') 'isPluginLoaded')
.callsFake((...args) => stubFn(...args)); .callsFake((...args) => stubFn(...args));
pluginApi._isPluginLoaded('test_plugin'); pluginApi._isPluginLoaded('test_plugin');
assert.isTrue(stubFn.calledWith('test_plugin')); assert.isTrue(stubFn.calledWith('test_plugin'));
}); });
test('Gerrit._isPluginPreloaded proxy to pluginLoader', () => { test('Gerrit._isPluginPreloaded proxy to getPluginLoader()', () => {
const stubFn = sinon.stub(); const stubFn = sinon.stub();
sinon.stub( sinon.stub(
pluginLoader, getPluginLoader(),
'isPluginPreloaded') 'isPluginPreloaded')
.callsFake((...args) => stubFn(...args)); .callsFake((...args) => stubFn(...args));
pluginApi._isPluginPreloaded('test_plugin'); pluginApi._isPluginPreloaded('test_plugin');

View File

@@ -17,7 +17,7 @@
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners'; import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners';
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin'; import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin';
import {PolymerElement} from '@polymer/polymer/polymer-element'; import {PolymerElement} from '@polymer/polymer/polymer-element';
import {pluginLoader} from './gr-plugin-loader'; import {getPluginLoader} from './gr-plugin-loader';
import {patchNumEquals} from '../../../utils/patch-set-util'; import {patchNumEquals} from '../../../utils/patch-set-util';
import {customElement} from '@polymer/decorators'; import {customElement} from '@polymer/decorators';
import {ChangeInfo, RevisionInfo} from '../../../types/common'; import {ChangeInfo, RevisionInfo} from '../../../types/common';
@@ -42,31 +42,36 @@ export class GrJsApiInterface
extends GestureEventListeners(LegacyElementMixin(PolymerElement)) extends GestureEventListeners(LegacyElementMixin(PolymerElement))
implements JsApiService { implements JsApiService {
handleEvent(type: EventType, detail: any) { handleEvent(type: EventType, detail: any) {
pluginLoader.awaitPluginsLoaded().then(() => { getPluginLoader()
switch (type) { .awaitPluginsLoaded()
case EventType.HISTORY: .then(() => {
this._handleHistory(detail); switch (type) {
break; case EventType.HISTORY:
case EventType.SHOW_CHANGE: this._handleHistory(detail);
this._handleShowChange(detail); break;
break; case EventType.SHOW_CHANGE:
case EventType.COMMENT: this._handleShowChange(detail);
this._handleComment(detail); break;
break; case EventType.COMMENT:
case EventType.LABEL_CHANGE: this._handleComment(detail);
this._handleLabelChange(detail); break;
break; case EventType.LABEL_CHANGE:
case EventType.SHOW_REVISION_ACTIONS: this._handleLabelChange(detail);
this._handleShowRevisionActions(detail); break;
break; case EventType.SHOW_REVISION_ACTIONS:
case EventType.HIGHLIGHTJS_LOADED: this._handleShowRevisionActions(detail);
this._handleHighlightjsLoaded(detail); break;
break; case EventType.HIGHLIGHTJS_LOADED:
default: this._handleHighlightjsLoaded(detail);
console.warn('handleEvent called with unsupported event type:', type); break;
break; default:
} console.warn(
}); 'handleEvent called with unsupported event type:',
type
);
break;
}
});
} }
addElement(key: TargetElement, el: HTMLElement) { addElement(key: TargetElement, el: HTMLElement) {
@@ -274,13 +279,15 @@ export class GrJsApiInterface
* will resolve to null. * will resolve to null.
*/ */
getCoverageAnnotationApi(): Promise<CoverageProvider | undefined> { getCoverageAnnotationApi(): Promise<CoverageProvider | undefined> {
return pluginLoader.awaitPluginsLoaded().then( return getPluginLoader()
() => .awaitPluginsLoaded()
this._getEventCallbacks(EventType.ANNOTATE_DIFF).find(cb => { .then(
const annotationApi = (cb as unknown) as GrAnnotationActionsInterface; () =>
return annotationApi.getCoverageProvider(); this._getEventCallbacks(EventType.ANNOTATE_DIFF).find(cb => {
}) as CoverageProvider | undefined const annotationApi = (cb as unknown) as GrAnnotationActionsInterface;
); return annotationApi.getCoverageProvider();
}) as CoverageProvider | undefined
);
} }
getAdminMenuLinks() { getAdminMenuLinks() {

View File

@@ -22,7 +22,7 @@ import {GrSettingsApi} from '../../plugins/gr-settings-api/gr-settings-api.js';
import {EventType} from '../../plugins/gr-plugin-types.js'; import {EventType} from '../../plugins/gr-plugin-types.js';
import {GrPluginActionContext} from './gr-plugin-action-context.js'; import {GrPluginActionContext} from './gr-plugin-action-context.js';
import {PLUGIN_LOADING_TIMEOUT_MS} from './gr-api-utils.js'; import {PLUGIN_LOADING_TIMEOUT_MS} from './gr-api-utils.js';
import {pluginLoader} from './gr-plugin-loader.js'; import {getPluginLoader} from './gr-plugin-loader.js';
import {_testOnly_initGerritPluginApi} from './gr-gerrit.js'; import {_testOnly_initGerritPluginApi} from './gr-gerrit.js';
import {stubBaseUrl} from '../../../test/test-utils.js'; import {stubBaseUrl} from '../../../test/test-utils.js';
@@ -60,7 +60,7 @@ suite('gr-js-api-interface tests', () => {
errorStub = sinon.stub(console, 'error'); errorStub = sinon.stub(console, 'error');
pluginApi.install(p => { plugin = p; }, '0.1', pluginApi.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js'); 'http://test.com/plugins/testplugin/static/test.js');
pluginLoader.loadPlugins([]); getPluginLoader().loadPlugins([]);
}); });
teardown(() => { teardown(() => {
@@ -234,7 +234,7 @@ suite('gr-js-api-interface tests', () => {
revisions: {def: {_number: 2}, abc: {_number: 1}}, revisions: {def: {_number: 2}, abc: {_number: 1}},
}; };
const spy = sinon.spy(); const spy = sinon.spy();
pluginLoader.loadPlugins(['plugins/test.html']); getPluginLoader().loadPlugins(['plugins/test.html']);
plugin.on(EventType.SHOW_CHANGE, spy); plugin.on(EventType.SHOW_CHANGE, spy);
element.handleEvent(EventType.SHOW_CHANGE, element.handleEvent(EventType.SHOW_CHANGE,
{change: testChange, patchNum: 1}); {change: testChange, patchNum: 1});

View File

@@ -444,8 +444,12 @@ export class PluginLoader {
} }
// TODO(dmfilippov): Convert to service and add to appContext // TODO(dmfilippov): Convert to service and add to appContext
export let pluginLoader = new PluginLoader(); let pluginLoader = new PluginLoader();
export function _testOnly_resetPluginLoader() { export function _testOnly_resetPluginLoader() {
pluginLoader = new PluginLoader(); pluginLoader = new PluginLoader();
return pluginLoader; return pluginLoader;
} }
export function getPluginLoader() {
return pluginLoader;
}

View File

@@ -540,4 +540,3 @@ suite('gr-plugin-loader tests', () => {
}); });
}); });
}); });