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