Get rid of global Gerrit Api methods
Change-Id: I240680b46956e5d50eaf3857b14e331596c44e01
This commit is contained in:
@@ -43,6 +43,7 @@ import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-beh
|
||||
import {AdminNavBehavior} from '../../../behaviors/gr-admin-nav-behavior/gr-admin-nav-behavior.js';
|
||||
import {URLEncodingBehavior} from '../../../behaviors/gr-url-encoding-behavior/gr-url-encoding-behavior.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
|
||||
|
||||
@@ -118,7 +119,7 @@ class GrAdminView extends mixinBehaviors( [
|
||||
reload() {
|
||||
const promises = [
|
||||
this.$.restAPI.getAccount(),
|
||||
Gerrit.awaitPluginsLoaded(),
|
||||
pluginLoader.awaitPluginsLoaded(),
|
||||
];
|
||||
return Promise.all(promises).then(result => {
|
||||
this._account = result[0];
|
||||
|
||||
@@ -39,6 +39,7 @@ import {URLEncodingBehavior} from '../../../behaviors/gr-url-encoding-behavior/g
|
||||
import {RESTClientBehavior} from '../../../behaviors/rest-client-behavior/rest-client-behavior.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
const CHANGE_SIZE = {
|
||||
XS: 10,
|
||||
@@ -99,7 +100,7 @@ class GrChangeListItem extends mixinBehaviors( [
|
||||
/** @override */
|
||||
attached() {
|
||||
super.attached();
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
this._dynamicCellEndpoints = pluginEndpoints.getDynamicEndpoints(
|
||||
'change-list-item-cell');
|
||||
});
|
||||
|
||||
@@ -37,6 +37,7 @@ import {KeyboardShortcutBehavior} from '../../../behaviors/keyboard-shortcut-beh
|
||||
import {RESTClientBehavior} from '../../../behaviors/rest-client-behavior/rest-client-behavior.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
const NUMBER_FIXED_COLUMNS = 3;
|
||||
const CLOSED_STATUS = ['MERGED', 'ABANDONED'];
|
||||
@@ -177,7 +178,7 @@ class GrChangeList extends mixinBehaviors( [
|
||||
/** @override */
|
||||
attached() {
|
||||
super.attached();
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
this._dynamicHeaderEndpoints = pluginEndpoints.getDynamicEndpoints(
|
||||
'change-list-header');
|
||||
});
|
||||
|
||||
@@ -43,6 +43,7 @@ import {htmlTemplate} from './gr-change-actions_html.js';
|
||||
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
|
||||
import {RESTClientBehavior} from '../../../behaviors/rest-client-behavior/rest-client-behavior.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
const ERR_BRANCH_EMPTY = 'The destination branch can’t be empty.';
|
||||
const ERR_COMMIT_EMPTY = 'The commit message can’t be empty.';
|
||||
@@ -533,7 +534,7 @@ class GrChangeActions extends mixinBehaviors( [
|
||||
}
|
||||
|
||||
_handleLoadingComplete() {
|
||||
Gerrit.awaitPluginsLoaded().then(() => this._loading = false);
|
||||
pluginLoader.awaitPluginsLoaded().then(() => this._loading = false);
|
||||
}
|
||||
|
||||
_sendShowRevisionActions(detail) {
|
||||
|
||||
@@ -43,6 +43,9 @@ import './gr-change-metadata.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {resetPlugins} from '../../../test/test-utils.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-change-metadata integration tests', () => {
|
||||
let sandbox;
|
||||
|
||||
@@ -35,6 +35,10 @@ import '../../../test/common-test-setup.js';
|
||||
import '../../core/gr-router/gr-router.js';
|
||||
import './gr-change-metadata.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-change-metadata tests', () => {
|
||||
let element;
|
||||
@@ -758,7 +762,7 @@ suite('gr-change-metadata tests', () => {
|
||||
},
|
||||
'0.1',
|
||||
'http://some/plugins/url.html');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
flush(() => {
|
||||
assert.strictEqual(hookEl.plugin, plugin);
|
||||
assert.strictEqual(hookEl.change, element.change);
|
||||
|
||||
@@ -483,7 +483,7 @@ class GrChangeView extends mixinBehaviors( [
|
||||
this._setDiffViewMode();
|
||||
});
|
||||
|
||||
Gerrit.awaitPluginsLoaded()
|
||||
pluginLoader.awaitPluginsLoaded()
|
||||
.then(() => {
|
||||
this._dynamicTabHeaderEndpoints =
|
||||
pluginEndpoints.getDynamicEndpoints('change-view-tab-header');
|
||||
@@ -1164,7 +1164,7 @@ class GrChangeView extends mixinBehaviors( [
|
||||
}
|
||||
|
||||
_maybeShowRevertDialog() {
|
||||
Gerrit.awaitPluginsLoaded()
|
||||
pluginLoader.awaitPluginsLoaded()
|
||||
.then(this._getLoggedIn.bind(this))
|
||||
.then(loggedIn => {
|
||||
if (!loggedIn || !this._change ||
|
||||
|
||||
@@ -50,6 +50,9 @@ import {_testOnly_resetEndpoints} from '../../shared/gr-js-api-interface/gr-plug
|
||||
import {util} from '../../../scripts/util.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-change-view tests', () => {
|
||||
const kb = KeyboardShortcutBinder;
|
||||
@@ -311,7 +314,7 @@ suite('gr-change-view tests', () => {
|
||||
});
|
||||
element = fixture('basic');
|
||||
sandbox.stub(element.$.actions, 'reload').returns(Promise.resolve());
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
Gerrit.install(
|
||||
plugin => {
|
||||
plugin.registerDynamicCustomComponent(
|
||||
|
||||
@@ -45,6 +45,7 @@ import {GrFileListConstants} from '../gr-file-list-constants.js';
|
||||
import {GrCountStringFormatter} from '../../shared/gr-count-string-formatter/gr-count-string-formatter.js';
|
||||
import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
|
||||
import {pluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
// Maximum length for patch set descriptions.
|
||||
const PATCH_DESC_MAX_LENGTH = 500;
|
||||
@@ -299,7 +300,7 @@ class GrFileList extends mixinBehaviors( [
|
||||
/** @override */
|
||||
attached() {
|
||||
super.attached();
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
this._dynamicHeaderEndpoints = pluginEndpoints.getDynamicEndpoints(
|
||||
'change-view-file-list-header');
|
||||
this._dynamicContentEndpoints = pluginEndpoints.getDynamicEndpoints(
|
||||
|
||||
@@ -42,6 +42,10 @@ import '../../plugins/gr-plugin-host/gr-plugin-host.js';
|
||||
import './gr-reply-dialog.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {resetPlugins} from '../../../test/test-utils.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-reply-dialog tests', () => {
|
||||
let element;
|
||||
@@ -149,7 +153,7 @@ suite('gr-reply-dialog tests', () => {
|
||||
const importSpy =
|
||||
sandbox.spy(element.shadowRoot
|
||||
.querySelector('gr-endpoint-decorator'), '_import');
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
Promise.all(importSpy.returnValues).then(() => {
|
||||
flush(() => {
|
||||
const textarea = element.$.textarea.getNativeTextarea();
|
||||
|
||||
@@ -39,6 +39,10 @@ void (0);
|
||||
import '../../../test/common-test-setup.js';
|
||||
import './gr-error-manager.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-error-manager tests', () => {
|
||||
let element;
|
||||
let sandbox;
|
||||
|
||||
@@ -31,6 +31,7 @@ import {htmlTemplate} from './gr-main-header_html.js';
|
||||
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
|
||||
import {DocsUrlBehavior} from '../../../behaviors/docs-url-behavior/docs-url-behavior.js';
|
||||
import {AdminNavBehavior} from '../../../behaviors/gr-admin-nav-behavior/gr-admin-nav-behavior.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
const DEFAULT_LINKS = [{
|
||||
title: 'Changes',
|
||||
@@ -266,7 +267,7 @@ class GrMainHeader extends mixinBehaviors( [
|
||||
const promises = [
|
||||
this.$.restAPI.getAccount(),
|
||||
this.$.restAPI.getTopMenus(),
|
||||
Gerrit.awaitPluginsLoaded(),
|
||||
pluginLoader.awaitPluginsLoaded(),
|
||||
];
|
||||
|
||||
return Promise.all(promises).then(result => {
|
||||
|
||||
@@ -34,6 +34,7 @@ limitations under the License.
|
||||
import '../test/common-test-setup.js';
|
||||
import './gr-app.js';
|
||||
import {util} from '../scripts/util.js';
|
||||
import {pluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
suite('gr-app custom dark theme tests', () => {
|
||||
let sandbox;
|
||||
@@ -74,7 +75,7 @@ suite('gr-app custom dark theme tests', () => {
|
||||
const importForThemeSpy = sandbox.spy(
|
||||
element.$['app-element'].$.externalStyleForTheme,
|
||||
'_import');
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
Promise.all(importSpy.returnValues.concat(importForThemeSpy.returnValues))
|
||||
.then(() => {
|
||||
flush(done);
|
||||
|
||||
@@ -34,6 +34,7 @@ limitations under the License.
|
||||
import '../test/common-test-setup.js';
|
||||
import './gr-app.js';
|
||||
import {util} from '../scripts/util.js';
|
||||
import {pluginLoader} from './shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
suite('gr-app custom light theme tests', () => {
|
||||
let sandbox;
|
||||
@@ -74,7 +75,7 @@ suite('gr-app custom light theme tests', () => {
|
||||
const importForThemeSpy = sandbox.spy(
|
||||
element.$['app-element'].$.externalStyleForTheme,
|
||||
'_import');
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
Promise.all(importSpy.returnValues.concat(importForThemeSpy.returnValues))
|
||||
.then(() => {
|
||||
flush(done);
|
||||
|
||||
@@ -35,11 +35,6 @@ setCancelSyntheticClickEvents(false);
|
||||
|
||||
import 'polymer-resin/standalone/polymer-resin.js';
|
||||
import {initGlobalVariables} from './gr-app-global-var-init.js';
|
||||
// Initialize global variables before any other imports
|
||||
// If a plugin is loaded in one of the subsequent import (with async/await, for
|
||||
// example), then all global variables must be initialized at this time
|
||||
initGlobalVariables();
|
||||
|
||||
import './gr-app-element.js';
|
||||
import './change-list/gr-embed-dashboard/gr-embed-dashboard.js';
|
||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
||||
@@ -47,6 +42,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-app_html.js';
|
||||
import {SafeTypes} from '../behaviors/safe-types-behavior/safe-types-behavior.js';
|
||||
import {initGerritPluginApi} from './shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
security.polymer_resin.install({
|
||||
allowedIdentifierPrefixes: [''],
|
||||
@@ -64,3 +60,6 @@ class GrApp extends GestureEventListeners(
|
||||
}
|
||||
|
||||
customElements.define(GrApp.is, GrApp);
|
||||
|
||||
initGlobalVariables();
|
||||
initGerritPluginApi();
|
||||
|
||||
@@ -27,6 +27,11 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.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 {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-admin-api tests', () => {
|
||||
let sandbox;
|
||||
let adminApi;
|
||||
@@ -36,7 +41,7 @@ suite('gr-admin-api tests', () => {
|
||||
let plugin;
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
adminApi = plugin.admin();
|
||||
});
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ limitations under the License.
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
|
||||
import {GrDomHook, GrDomHooksManager} from './gr-dom-hooks.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-dom-hooks tests', () => {
|
||||
const PUBLIC_METHODS =[
|
||||
|
||||
@@ -24,6 +24,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-endpoint-decorator_html.js';
|
||||
import {pluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
const INIT_PROPERTIES_TIMEOUT_MS = 10000;
|
||||
|
||||
@@ -163,7 +164,7 @@ class GrEndpointDecorator extends GestureEventListeners(
|
||||
super.ready();
|
||||
this._endpointCallBack = this._initModule.bind(this);
|
||||
pluginEndpoints.onNewEndpoint(this.name, this._endpointCallBack);
|
||||
Gerrit.awaitPluginsLoaded()
|
||||
pluginLoader.awaitPluginsLoaded()
|
||||
.then(() => Promise.all(
|
||||
pluginEndpoints.getPlugins(this.name).map(
|
||||
pluginUrl => this._import(pluginUrl)))
|
||||
|
||||
@@ -46,6 +46,10 @@ import './gr-endpoint-decorator.js';
|
||||
import '../gr-endpoint-param/gr-endpoint-param.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {resetPlugins} from '../../../test/test-utils.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-endpoint-decorator', () => {
|
||||
let container;
|
||||
@@ -61,14 +65,15 @@ suite('gr-endpoint-decorator', () => {
|
||||
});
|
||||
resetPlugins();
|
||||
container = fixture('basic');
|
||||
Gerrit.install(p => plugin = p, '0.1', 'http://some/plugin/url.html');
|
||||
Gerrit.install(p => plugin = p, '0.1',
|
||||
'http://some/plugin/url.html');
|
||||
// Decoration
|
||||
decorationHook = plugin.registerCustomComponent('first', 'some-module');
|
||||
// Replacement
|
||||
replacementHook = plugin.registerCustomComponent(
|
||||
'second', 'other-module', {replace: true});
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
flush(done);
|
||||
});
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-external-style_html.js';
|
||||
import {pluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
/** @extends Polymer.Element */
|
||||
class GrExternalStyle extends GestureEventListeners(
|
||||
@@ -99,7 +100,7 @@ class GrExternalStyle extends GestureEventListeners(
|
||||
/** @override */
|
||||
ready() {
|
||||
super.ready();
|
||||
Gerrit.awaitPluginsLoaded().then(() => this._importAndApply());
|
||||
pluginLoader.awaitPluginsLoaded().then(() => this._importAndApply());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@ limitations under the License.
|
||||
import '../../../test/common-test-setup.js';
|
||||
import './gr-external-style.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-external-style integration tests', () => {
|
||||
const TEST_URL = 'http://some/plugin/url.html';
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
|
||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
/** @extends Polymer.Element */
|
||||
class GrPluginHost extends GestureEventListeners(
|
||||
@@ -42,7 +43,7 @@ class GrPluginHost extends GestureEventListeners(
|
||||
const jsPlugins =
|
||||
this._handleMigrations(plugins.js_resource_paths || [], htmlPlugins);
|
||||
const shouldLoadTheme = config.default_theme &&
|
||||
!Gerrit._isPluginPreloaded('preloaded:gerrit-theme');
|
||||
!pluginLoader.isPluginPreloaded('preloaded:gerrit-theme');
|
||||
const themeToLoad =
|
||||
shouldLoadTheme ? [config.default_theme] : [];
|
||||
|
||||
@@ -57,7 +58,7 @@ class GrPluginHost extends GestureEventListeners(
|
||||
pluginOpts[config.default_theme] = {sync: true};
|
||||
}
|
||||
|
||||
Gerrit._loadPlugins(pluginsPending, pluginOpts);
|
||||
pluginLoader.loadPlugins(pluginsPending, pluginOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,9 @@ import '../../../test/common-test-setup.js';
|
||||
import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {GrPopupInterface} from './gr-popup-interface.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
suite('gr-popup-interface tests', () => {
|
||||
let container;
|
||||
let instance;
|
||||
|
||||
@@ -34,6 +34,10 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../gr-endpoint-decorator/gr-endpoint-decorator.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-repo-api tests', () => {
|
||||
let sandbox;
|
||||
@@ -44,7 +48,7 @@ suite('gr-repo-api tests', () => {
|
||||
let plugin;
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
repoApi = plugin.project();
|
||||
});
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../gr-endpoint-decorator/gr-endpoint-decorator.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-settings-api tests', () => {
|
||||
let sandbox;
|
||||
@@ -46,7 +50,7 @@ suite('gr-settings-api tests', () => {
|
||||
let plugin;
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
settingsApi = plugin.settings();
|
||||
});
|
||||
|
||||
|
||||
@@ -40,6 +40,11 @@ Polymer({is: 'gr-style-test-element'});
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-styles-api tests', () => {
|
||||
let sandbox;
|
||||
let stylesApi;
|
||||
@@ -49,7 +54,7 @@ suite('gr-styles-api tests', () => {
|
||||
let plugin;
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
stylesApi = plugin.styles();
|
||||
});
|
||||
|
||||
@@ -78,7 +83,7 @@ suite('gr-styles-api tests', () => {
|
||||
let plugin;
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
stylesApi = plugin.styles();
|
||||
displayInlineStyle = stylesApi.css('display: inline');
|
||||
displayNoneStyle = stylesApi.css('display: none');
|
||||
|
||||
@@ -35,6 +35,10 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../gr-endpoint-decorator/gr-endpoint-decorator.js';
|
||||
import {pluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-theme-api tests', () => {
|
||||
let sandbox;
|
||||
@@ -66,7 +70,7 @@ suite('gr-theme-api tests', () => {
|
||||
/** @override */
|
||||
ready() { customHeader = this; },
|
||||
});
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
});
|
||||
|
||||
test('sets logo and title', done => {
|
||||
|
||||
@@ -25,6 +25,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {htmlTemplate} from './gr-avatar_html.js';
|
||||
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
|
||||
import {pluginLoader} from '../gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
/**
|
||||
* @extends Polymer.Element
|
||||
@@ -60,7 +61,7 @@ class GrAvatar extends mixinBehaviors( [
|
||||
super.attached();
|
||||
Promise.all([
|
||||
this._getConfig(),
|
||||
Gerrit.awaitPluginsLoaded(),
|
||||
pluginLoader.awaitPluginsLoaded(),
|
||||
]).then(([cfg]) => {
|
||||
this._hasAvatars = !!(cfg && cfg.plugin && cfg.plugin.has_avatars);
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.js';
|
||||
import './gr-avatar.js';
|
||||
import {pluginLoader} from '../gr-js-api-interface/gr-plugin-loader.js';
|
||||
|
||||
suite('gr-avatar tests', () => {
|
||||
let element;
|
||||
let sandbox;
|
||||
@@ -116,11 +118,11 @@ suite('gr-avatar tests', () => {
|
||||
assert.strictEqual(element.style.backgroundImage, '');
|
||||
|
||||
// Emulate plugins loaded.
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
|
||||
Promise.all([
|
||||
element.$.restAPI.getConfig(),
|
||||
Gerrit.awaitPluginsLoaded(),
|
||||
pluginLoader.awaitPluginsLoaded(),
|
||||
]).then(() => {
|
||||
assert.isFalse(element.hasAttribute('hidden'));
|
||||
|
||||
@@ -151,11 +153,11 @@ suite('gr-avatar tests', () => {
|
||||
assert.isFalse(element.hasAttribute('hidden'));
|
||||
|
||||
// Emulate plugins loaded.
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
|
||||
return Promise.all([
|
||||
element.$.restAPI.getConfig(),
|
||||
Gerrit.awaitPluginsLoaded(),
|
||||
pluginLoader.awaitPluginsLoaded(),
|
||||
]).then(() => {
|
||||
assert.isTrue(element.hasAttribute('hidden'));
|
||||
|
||||
@@ -191,11 +193,11 @@ suite('gr-avatar tests', () => {
|
||||
_account_id: 123,
|
||||
};
|
||||
// Emulate plugins loaded.
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
|
||||
return Promise.all([
|
||||
element.$.restAPI.getConfig(),
|
||||
Gerrit.awaitPluginsLoaded(),
|
||||
pluginLoader.awaitPluginsLoaded(),
|
||||
]).then(() => {
|
||||
assert.isTrue(element.hasAttribute('hidden'));
|
||||
});
|
||||
|
||||
@@ -32,6 +32,10 @@ limitations under the License.
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../gr-js-api-interface/gr-js-api-interface.js';
|
||||
import {EventEmitter} from './gr-event-interface.js';
|
||||
import {initGerritPluginApi} from '../gr-js-api-interface/gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-event-interface tests', () => {
|
||||
let sandbox;
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ import '../../../test/common-test-setup.js';
|
||||
import './gr-js-api-interface.js';
|
||||
import {GrAnnotation} from '../../diff/gr-diff-highlight/gr-annotation.js';
|
||||
import {GrAnnotationActionsContext} from './gr-annotation-actions-context.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-annotation-actions-context tests', () => {
|
||||
let instance;
|
||||
|
||||
@@ -37,6 +37,10 @@ limitations under the License.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../../change/gr-change-actions/gr-change-actions.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-annotation-actions-js-api tests', () => {
|
||||
let annotationActions;
|
||||
let sandbox;
|
||||
|
||||
@@ -39,6 +39,9 @@ import '../../../test/common-test-setup.js';
|
||||
import '../../change/gr-change-actions/gr-change-actions.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {resetPlugins} from '../../../test/test-utils.js';
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-js-api-interface tests', () => {
|
||||
let element;
|
||||
@@ -59,7 +62,7 @@ suite('gr-js-api-interface tests', () => {
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
changeActions = plugin.changeActions();
|
||||
element = fixture('basic');
|
||||
});
|
||||
@@ -87,7 +90,7 @@ suite('gr-js-api-interface tests', () => {
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
changeActions = plugin.changeActions();
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
|
||||
@@ -37,6 +37,10 @@ breaking changes to gr-reply-dialog won’t be noticed.
|
||||
<script type="module">
|
||||
import '../../../test/common-test-setup.js';
|
||||
import '../../change/gr-reply-dialog/gr-reply-dialog.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-change-reply-js-api tests', () => {
|
||||
let element;
|
||||
let sandbox;
|
||||
|
||||
@@ -33,57 +33,19 @@ function flushPreinstalls() {
|
||||
window.Gerrit.flushPreinstalls();
|
||||
}
|
||||
}
|
||||
flushPreinstalls();
|
||||
export const _testOnly_flushPreinstalls = flushPreinstalls;
|
||||
|
||||
window.Gerrit = window.Gerrit || {};
|
||||
const Gerrit = window.Gerrit;
|
||||
export function initGerritPluginApi() {
|
||||
window.Gerrit = window.Gerrit || {};
|
||||
flushPreinstalls();
|
||||
initGerritPluginsMethods(window.Gerrit);
|
||||
// Preloaded plugins should be installed after Gerrit.install() is set,
|
||||
// since plugin preloader substitutes Gerrit.install() temporarily.
|
||||
// (Gerrit.install() is set in initGerritPluginsMethods)
|
||||
pluginLoader.installPreloadedPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use plugin.styles().css(rulesStr) instead. Please, consult
|
||||
* the documentation how to replace it accordingly.
|
||||
*/
|
||||
Gerrit.css = function(rulesStr) {
|
||||
console.warn('Gerrit.css(rulesStr) is deprecated!',
|
||||
'Use plugin.styles().css(rulesStr)');
|
||||
if (!Gerrit._customStyleSheet) {
|
||||
const styleEl = document.createElement('style');
|
||||
document.head.appendChild(styleEl);
|
||||
Gerrit._customStyleSheet = styleEl.sheet;
|
||||
}
|
||||
|
||||
const name = '__pg_js_api_class_' +
|
||||
Gerrit._customStyleSheet.cssRules.length;
|
||||
Gerrit._customStyleSheet.insertRule('.' + name + '{' + rulesStr + '}', 0);
|
||||
return name;
|
||||
};
|
||||
|
||||
Gerrit.install = function(callback, opt_version, opt_src) {
|
||||
pluginLoader.install(callback, opt_version, opt_src);
|
||||
};
|
||||
|
||||
Gerrit.getLoggedIn = function() {
|
||||
console.warn('Gerrit.getLoggedIn() is deprecated! ' +
|
||||
'Use plugin.restApi().getLoggedIn()');
|
||||
return document.createElement('gr-rest-api-interface').getLoggedIn();
|
||||
};
|
||||
|
||||
Gerrit.get = function(url, callback) {
|
||||
console.warn('.get() is deprecated! Use plugin.restApi().get()');
|
||||
send('GET', url, callback);
|
||||
};
|
||||
|
||||
Gerrit.post = function(url, payload, callback) {
|
||||
console.warn('.post() is deprecated! Use plugin.restApi().post()');
|
||||
send('POST', url, callback, payload);
|
||||
};
|
||||
|
||||
Gerrit.put = function(url, payload, callback) {
|
||||
console.warn('.put() is deprecated! Use plugin.restApi().put()');
|
||||
send('PUT', url, callback, payload);
|
||||
};
|
||||
|
||||
Gerrit.delete = function(url, opt_callback) {
|
||||
export function deprecatedDelete(url, opt_callback) {
|
||||
console.warn('.delete() is deprecated! Use plugin.restApi().delete()');
|
||||
return getRestAPI().send('DELETE', url)
|
||||
.then(response => {
|
||||
@@ -101,43 +63,88 @@ Gerrit.delete = function(url, opt_callback) {
|
||||
}
|
||||
return response;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Gerrit.awaitPluginsLoaded = function() {
|
||||
function initGerritPluginsMethods(globalGerritObj) {
|
||||
/**
|
||||
* @deprecated Use plugin.styles().css(rulesStr) instead. Please, consult
|
||||
* the documentation how to replace it accordingly.
|
||||
*/
|
||||
globalGerritObj.css = function(rulesStr) {
|
||||
console.warn('Gerrit.css(rulesStr) is deprecated!',
|
||||
'Use plugin.styles().css(rulesStr)');
|
||||
if (!globalGerritObj._customStyleSheet) {
|
||||
const styleEl = document.createElement('style');
|
||||
document.head.appendChild(styleEl);
|
||||
globalGerritObj._customStyleSheet = styleEl.sheet;
|
||||
}
|
||||
|
||||
const name = '__pg_js_api_class_' +
|
||||
globalGerritObj._customStyleSheet.cssRules.length;
|
||||
globalGerritObj._customStyleSheet
|
||||
.insertRule('.' + name + '{' + rulesStr + '}', 0);
|
||||
return name;
|
||||
};
|
||||
|
||||
globalGerritObj.install = function(callback, opt_version, opt_src) {
|
||||
pluginLoader.install(callback, opt_version, opt_src);
|
||||
};
|
||||
|
||||
globalGerritObj.getLoggedIn = function() {
|
||||
console.warn('Gerrit.getLoggedIn() is deprecated! ' +
|
||||
'Use plugin.restApi().getLoggedIn()');
|
||||
return document.createElement('gr-rest-api-interface').getLoggedIn();
|
||||
};
|
||||
|
||||
globalGerritObj.get = function(url, callback) {
|
||||
console.warn('.get() is deprecated! Use plugin.restApi().get()');
|
||||
send('GET', url, callback);
|
||||
};
|
||||
|
||||
globalGerritObj.post = function(url, payload, callback) {
|
||||
console.warn('.post() is deprecated! Use plugin.restApi().post()');
|
||||
send('POST', url, callback, payload);
|
||||
};
|
||||
|
||||
globalGerritObj.put = function(url, payload, callback) {
|
||||
console.warn('.put() is deprecated! Use plugin.restApi().put()');
|
||||
send('PUT', url, callback, payload);
|
||||
};
|
||||
|
||||
globalGerritObj.delete = function(url, opt_callback) {
|
||||
deprecatedDelete(url, opt_callback);
|
||||
};
|
||||
|
||||
globalGerritObj.awaitPluginsLoaded = function() {
|
||||
return pluginLoader.awaitPluginsLoaded();
|
||||
};
|
||||
};
|
||||
|
||||
// TODO(taoalpha): consider removing these proxy methods
|
||||
// and using _pluginLoader directly
|
||||
|
||||
Gerrit._loadPlugins = function(plugins, opt_option) {
|
||||
// TODO(taoalpha): consider removing these proxy methods
|
||||
// and using pluginLoader directly
|
||||
globalGerritObj._loadPlugins = function(plugins, opt_option) {
|
||||
pluginLoader.loadPlugins(plugins, opt_option);
|
||||
};
|
||||
};
|
||||
|
||||
Gerrit._arePluginsLoaded = function() {
|
||||
globalGerritObj._arePluginsLoaded = function() {
|
||||
return pluginLoader.arePluginsLoaded();
|
||||
};
|
||||
};
|
||||
|
||||
Gerrit._isPluginPreloaded = function(url) {
|
||||
globalGerritObj._isPluginPreloaded = function(url) {
|
||||
return pluginLoader.isPluginPreloaded(url);
|
||||
};
|
||||
};
|
||||
|
||||
Gerrit._isPluginEnabled = function(pathOrUrl) {
|
||||
globalGerritObj._isPluginEnabled = function(pathOrUrl) {
|
||||
return pluginLoader.isPluginEnabled(pathOrUrl);
|
||||
};
|
||||
};
|
||||
|
||||
Gerrit._isPluginLoaded = function(pathOrUrl) {
|
||||
globalGerritObj._isPluginLoaded = function(pathOrUrl) {
|
||||
return pluginLoader.isPluginLoaded(pathOrUrl);
|
||||
};
|
||||
};
|
||||
|
||||
// Preloaded plugins should be installed after Gerrit.install() is set,
|
||||
// since plugin preloader substitutes Gerrit.install() temporarily.
|
||||
pluginLoader.installPreloadedPlugins();
|
||||
|
||||
// TODO(taoalpha): List all internal supported event names.
|
||||
// Also convert this to inherited class once we move Gerrit to class.
|
||||
Gerrit._eventEmitter = new EventEmitter();
|
||||
['addListener',
|
||||
// TODO(taoalpha): List all internal supported event names.
|
||||
// Also convert this to inherited class once we move Gerrit to class.
|
||||
globalGerritObj._eventEmitter = new EventEmitter();
|
||||
['addListener',
|
||||
'dispatch',
|
||||
'emit',
|
||||
'off',
|
||||
@@ -145,7 +152,7 @@ Gerrit._eventEmitter = new EventEmitter();
|
||||
'once',
|
||||
'removeAllListeners',
|
||||
'removeListener',
|
||||
].forEach(method => {
|
||||
].forEach(method => {
|
||||
/**
|
||||
* Enabling EventEmitter interface on Gerrit.
|
||||
*
|
||||
@@ -168,5 +175,7 @@ Gerrit._eventEmitter = new EventEmitter();
|
||||
* });
|
||||
* });
|
||||
*/
|
||||
Gerrit[method] = Gerrit._eventEmitter[method].bind(Gerrit._eventEmitter);
|
||||
});
|
||||
globalGerritObj[method] = globalGerritObj._eventEmitter[method]
|
||||
.bind(globalGerritObj._eventEmitter);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ import '../../../test/common-test-setup.js';
|
||||
import './gr-js-api-interface.js';
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
import {resetPlugins} from '../../../test/test-utils.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-gerrit tests', () => {
|
||||
let element;
|
||||
|
||||
@@ -21,6 +21,7 @@ import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-l
|
||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
|
||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
||||
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
|
||||
// Note: for new events, naming convention should be: `a-b`
|
||||
const EventType = {
|
||||
@@ -74,7 +75,7 @@ class GrJsApiInterface extends mixinBehaviors( [
|
||||
}
|
||||
|
||||
handleEvent(type, detail) {
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
switch (type) {
|
||||
case EventType.HISTORY:
|
||||
this._handleHistory(detail);
|
||||
@@ -288,7 +289,7 @@ class GrJsApiInterface extends mixinBehaviors( [
|
||||
* @return {!Promise<?GrAnnotationActionsInterface>}
|
||||
*/
|
||||
getCoverageAnnotationApi() {
|
||||
return Gerrit.awaitPluginsLoaded()
|
||||
return pluginLoader.awaitPluginsLoaded()
|
||||
.then(() => this._getEventCallbacks(EventType.ANNOTATE_DIFF)
|
||||
.find(api => api.getCoverageProvider()));
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ import {GrPopupInterface} from '../../plugins/gr-popup-interface/gr-popup-interf
|
||||
import {GrSettingsApi} from '../../plugins/gr-settings-api/gr-settings-api.js';
|
||||
import {GrPluginActionContext} from './gr-plugin-action-context.js';
|
||||
import {PLUGIN_LOADING_TIMEOUT_MS} from './gr-api-utils.js';
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-js-api-interface tests', () => {
|
||||
let element;
|
||||
@@ -69,7 +73,7 @@ suite('gr-js-api-interface tests', () => {
|
||||
errorStub = sandbox.stub(console, 'error');
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
@@ -238,7 +242,7 @@ suite('gr-js-api-interface tests', () => {
|
||||
revisions: {def: {_number: 2}, abc: {_number: 1}},
|
||||
};
|
||||
const spy = sandbox.spy();
|
||||
Gerrit._loadPlugins(['plugins/test.html']);
|
||||
pluginLoader.loadPlugins(['plugins/test.html']);
|
||||
plugin.on(element.EventType.SHOW_CHANGE, spy);
|
||||
element.handleEvent(element.EventType.SHOW_CHANGE,
|
||||
{change: testChange, patchNum: 1});
|
||||
|
||||
@@ -35,6 +35,9 @@ import '../../../test/common-test-setup.js';
|
||||
import './gr-js-api-interface.js';
|
||||
import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
|
||||
import {GrPluginActionContext} from './gr-plugin-action-context.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-plugin-action-context tests', () => {
|
||||
let instance;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
|
||||
/** @constructor */
|
||||
export function GrPluginEndpoints() {
|
||||
this._endpoints = {};
|
||||
@@ -79,7 +81,7 @@ GrPluginEndpoints.prototype.registerModule = function(plugin, endpoint, type,
|
||||
}
|
||||
const moduleInfo = this._getOrCreateModuleInfo(plugin, endpoint, type,
|
||||
moduleName, domHook);
|
||||
if (Gerrit._arePluginsLoaded() && this._callbacks[endpoint]) {
|
||||
if (pluginLoader.arePluginsLoaded() && this._callbacks[endpoint]) {
|
||||
this._callbacks[endpoint].forEach(callback => callback(moduleInfo));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,6 +29,9 @@ import '../../../test/common-test-setup.js';
|
||||
import './gr-js-api-interface.js';
|
||||
import {GrPluginEndpoints} from './gr-plugin-endpoints.js';
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-plugin-endpoints tests', () => {
|
||||
let sandbox;
|
||||
|
||||
@@ -38,6 +38,9 @@ import {PRELOADED_PROTOCOL, PLUGIN_LOADING_TIMEOUT_MS} from './gr-api-utils.js';
|
||||
import {pluginLoader} from './gr-plugin-loader.js';
|
||||
import {resetPlugins} from '../../../test/test-utils.js';
|
||||
import {_testOnly_flushPreinstalls} from './gr-gerrit.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-plugin-loader tests', () => {
|
||||
let plugin;
|
||||
@@ -100,23 +103,23 @@ suite('gr-plugin-loader tests', () => {
|
||||
done();
|
||||
},
|
||||
});
|
||||
Gerrit._loadPlugins([]);
|
||||
pluginLoader.loadPlugins([]);
|
||||
});
|
||||
|
||||
test('arePluginsLoaded', done => {
|
||||
assert.isFalse(Gerrit._arePluginsLoaded());
|
||||
assert.isFalse(pluginLoader.arePluginsLoaded());
|
||||
const plugins = [
|
||||
'http://test.com/plugins/foo/static/test.js',
|
||||
'http://test.com/plugins/bar/static/test.js',
|
||||
];
|
||||
|
||||
Gerrit._loadPlugins(plugins);
|
||||
assert.isFalse(Gerrit._arePluginsLoaded());
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
assert.isFalse(pluginLoader.arePluginsLoaded());
|
||||
// Timeout on loading plugins
|
||||
window.clock.tick(PLUGIN_LOADING_TIMEOUT_MS * 2);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -134,11 +137,11 @@ suite('gr-plugin-loader tests', () => {
|
||||
'http://test.com/plugins/foo/static/test.js',
|
||||
'http://test.com/plugins/bar/static/test.js',
|
||||
];
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['foo', 'bar']));
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -157,13 +160,13 @@ suite('gr-plugin-loader tests', () => {
|
||||
'http://test.com/plugins/bar/static/test.js',
|
||||
'bar/static/test.js',
|
||||
];
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
assert.isTrue(
|
||||
plugins.every(plugin => pluginLoader.isPluginEnabled(plugin))
|
||||
);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
assert.isTrue(
|
||||
plugins.every(plugin => pluginLoader.isPluginLoaded(plugin))
|
||||
);
|
||||
@@ -194,11 +197,11 @@ suite('gr-plugin-loader tests', () => {
|
||||
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
||||
});
|
||||
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['bar']));
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
assert.isTrue(alertStub.calledOnce);
|
||||
done();
|
||||
});
|
||||
@@ -226,14 +229,14 @@ suite('gr-plugin-loader tests', () => {
|
||||
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
||||
});
|
||||
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
assert.isTrue(
|
||||
plugins.every(plugin => pluginLoader.isPluginEnabled(plugin))
|
||||
);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['bar']));
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
assert.isTrue(alertStub.calledOnce);
|
||||
assert.isTrue(pluginLoader.isPluginLoaded(plugins[1]));
|
||||
assert.isFalse(pluginLoader.isPluginLoaded(plugins[0]));
|
||||
@@ -261,11 +264,11 @@ suite('gr-plugin-loader tests', () => {
|
||||
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
||||
});
|
||||
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly([]));
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
assert.isTrue(alertStub.calledTwice);
|
||||
done();
|
||||
});
|
||||
@@ -290,11 +293,11 @@ suite('gr-plugin-loader tests', () => {
|
||||
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
||||
});
|
||||
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['foo']));
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
assert.isTrue(alertStub.calledOnce);
|
||||
done();
|
||||
});
|
||||
@@ -314,11 +317,11 @@ suite('gr-plugin-loader tests', () => {
|
||||
'http://test.com/plugins/foo/static/test2.js',
|
||||
'http://test.com/plugins/bar/static/test.js',
|
||||
];
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
|
||||
flush(() => {
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['foo', 'bar']));
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
assert.isTrue(pluginLoader.arePluginsLoaded());
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -343,7 +346,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
failToLoadStub(...args);
|
||||
});
|
||||
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'foo/bar',
|
||||
]);
|
||||
|
||||
@@ -355,7 +358,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
});
|
||||
|
||||
test('relative path for plugins', () => {
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'foo/bar.js',
|
||||
'foo/bar.html',
|
||||
]);
|
||||
@@ -374,7 +377,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
const testUrl = '/test';
|
||||
sandbox.stub(BaseUrlBehavior, 'getBaseUrl', () => testUrl);
|
||||
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'foo/bar.js',
|
||||
'foo/bar.html',
|
||||
]);
|
||||
@@ -392,7 +395,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
});
|
||||
|
||||
test('absolute path for plugins', () => {
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'http://e.com/foo/bar.js',
|
||||
'http://e.com/foo/bar.html',
|
||||
]);
|
||||
@@ -428,7 +431,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
});
|
||||
|
||||
test('Should try load plugins from assets path instead', () => {
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'foo/bar.js',
|
||||
'foo/bar.html',
|
||||
]);
|
||||
@@ -443,7 +446,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
});
|
||||
|
||||
test('Should honor original path if exists', () => {
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'http://e.com/foo/bar.html',
|
||||
'http://e.com/foo/bar.js',
|
||||
]);
|
||||
@@ -459,7 +462,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
|
||||
test('Should try replace current host with assetsPath', () => {
|
||||
const host = window.location.origin;
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
`${host}/foo/bar.html`,
|
||||
`${host}/foo/bar.js`,
|
||||
]);
|
||||
@@ -475,7 +478,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
});
|
||||
|
||||
test('adds js plugins will call the body', () => {
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'http://e.com/foo/bar.js',
|
||||
'http://e.com/bar/foo.js',
|
||||
]);
|
||||
@@ -498,12 +501,12 @@ suite('gr-plugin-loader tests', () => {
|
||||
Gerrit.install(() => pluginCallback(url), undefined, url);
|
||||
});
|
||||
|
||||
Gerrit._loadPlugins(plugins);
|
||||
pluginLoader.loadPlugins(plugins);
|
||||
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
assert.isTrue(installed);
|
||||
|
||||
Gerrit.awaitPluginsLoaded().then(() => {
|
||||
pluginLoader.awaitPluginsLoaded().then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -525,7 +528,7 @@ suite('gr-plugin-loader tests', () => {
|
||||
bar: () => void 0,
|
||||
};
|
||||
|
||||
Gerrit._loadPlugins([
|
||||
pluginLoader.loadPlugins([
|
||||
'http://e.com/plugins/foo.js',
|
||||
'plugins/bar.html',
|
||||
'http://e.com/plugins/test/foo.js',
|
||||
|
||||
@@ -27,6 +27,9 @@ limitations under the License.
|
||||
import '../../../test/common-test-setup.js';
|
||||
import './gr-js-api-interface.js';
|
||||
import {GrPluginRestApi} from './gr-plugin-rest-api.js';
|
||||
import {initGerritPluginApi} from './gr-gerrit.js';
|
||||
|
||||
initGerritPluginApi();
|
||||
|
||||
suite('gr-plugin-rest-api tests', () => {
|
||||
let instance;
|
||||
|
||||
@@ -33,11 +33,8 @@ import {GrStylesApi} from '../../plugins/gr-styles-api/gr-styles-api.js';
|
||||
import {GrPluginActionContext} from './gr-plugin-action-context.js';
|
||||
import {pluginEndpoints} from './gr-plugin-endpoints.js';
|
||||
|
||||
import {
|
||||
PRELOADED_PROTOCOL,
|
||||
getPluginNameFromUrl,
|
||||
send,
|
||||
} from './gr-api-utils.js';
|
||||
import {PRELOADED_PROTOCOL, getPluginNameFromUrl, send} from './gr-api-utils.js';
|
||||
import {deprecatedDelete} from './gr-gerrit.js';
|
||||
|
||||
(function(window) {
|
||||
'use strict';
|
||||
@@ -195,7 +192,7 @@ import {
|
||||
};
|
||||
|
||||
Plugin.prototype.delete = function(url, opt_callback) {
|
||||
return Gerrit.delete(this.url(url), opt_callback);
|
||||
return deprecatedDelete(this.url(url), opt_callback);
|
||||
};
|
||||
|
||||
Plugin.prototype.annotationApi = function() {
|
||||
|
||||
Reference in New Issue
Block a user