Merge branch 'stable-3.1' into stable-3.2

* stable-3.1:
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Apply diff preferences immediately after clicking save
  Grant the InternalUser back access to changes
  Rewrite upload archive tests as real integration tests
  Add support for Elasticsearch version 7.7.*

Change-Id: I67dcf53f127b34d7aa36a3465cf27ada4a7b55c7
This commit is contained in:
David Pursehouse
2020-05-16 10:10:46 +09:00
committed by Paladox none
18 changed files with 162 additions and 22 deletions

View File

@@ -39,6 +39,17 @@ class GrDiffPreferencesDialog extends GestureEventListeners(
/** @type {?} */
diffPrefs: Object,
/**
* _editableDiffPrefs is a clone of diffPrefs.
* All changes in the dialog are applied to this object
* immediately, when a value in an editor is changed.
* The "Save" button replaces the "diffPrefs" object with
* the value of _editableDiffPrefs.
*
* @type {?}
*/
_editableDiffPrefs: Object,
_diffPrefsChanged: Boolean,
};
}
@@ -64,6 +75,10 @@ class GrDiffPreferencesDialog extends GestureEventListeners(
}
open() {
// JSON.parse(JSON.stringify(...)) makes a deep clone of diffPrefs.
// It is known, that diffPrefs is obtained from an RestAPI call and
// it is safe to clone the object this way.
this._editableDiffPrefs = JSON.parse(JSON.stringify(this.diffPrefs));
this.$.diffPrefsOverlay.open().then(() => {
const focusStops = this.getFocusStops();
this.$.diffPrefsOverlay.setFocusStops(focusStops);
@@ -72,6 +87,7 @@ class GrDiffPreferencesDialog extends GestureEventListeners(
}
_handleSaveDiffPreferences() {
this.diffPrefs = this._editableDiffPrefs;
this.$.diffPreferences.save().then(() => {
this.dispatchEvent(new CustomEvent('reload-diff-preference', {
composed: true, bubbles: false,

View File

@@ -53,7 +53,7 @@ export const htmlTemplate = html`
</div>
<gr-diff-preferences
id="diffPreferences"
diff-prefs="{{diffPrefs}}"
diff-prefs="{{_editableDiffPrefs}}"
has-unsaved-changes="{{_diffPrefsChanged}}"
></gr-diff-preferences>
<div class="diffActions">

View File

@@ -0,0 +1,69 @@
<!DOCTYPE html>
<!--
@license
Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<meta charset="utf-8">
<title>gr-diff-preferences-dialog</title>
<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/components/wct-browser-legacy/browser.js"></script>
<script src="/components/web-component-tester/data/a11ySuite.js"></script>
<test-fixture id="basic">
<template>
<gr-diff-preferences-dialog></gr-diff-preferences-dialog>
</template>
</test-fixture>
<script type="module">
import '../../../test/common-test-setup.js';
import './gr-diff-preferences-dialog.js';
import {flush} from '@polymer/polymer/lib/legacy/polymer.dom.js';
suite('gr-diff-preferences-dialog', () => {
let element;
setup(() => {
element = fixture('basic');
});
test('changes applies only on save', async () => {
const originalDiffPrefs = {
line_wrapping: true,
};
element.diffPrefs = originalDiffPrefs;
element.open();
await flush();
assert.isTrue(element.$.diffPreferences.$.lineWrappingInput.checked);
MockInteractions.tap(element.$.diffPreferences.$.lineWrappingInput);
await flush();
assert.isFalse(element.$.diffPreferences.$.lineWrappingInput.checked);
assert.isTrue(element._diffPrefsChanged);
assert.isTrue(element.diffPrefs.line_wrapping);
assert.isTrue(originalDiffPrefs.line_wrapping);
MockInteractions.tap(element.$.saveButton);
await flush();
// Original prefs must remains unchanged, dialog must expose a new object
assert.isTrue(originalDiffPrefs.line_wrapping);
assert.isFalse(element.diffPrefs.line_wrapping);
});
});
</script>

View File

@@ -690,21 +690,26 @@ class GrDiff extends mixinBehaviors( [
}
_prefsObserver(newPrefs, oldPrefs) {
// Scan the preference objects one level deep to see if they differ.
let differ = !oldPrefs;
if (newPrefs && oldPrefs) {
for (const key in newPrefs) {
if (newPrefs[key] !== oldPrefs[key]) {
differ = true;
}
}
}
if (differ) {
if (!this._prefsEqual(newPrefs, oldPrefs)) {
this._prefsChanged(newPrefs);
}
}
_prefsEqual(prefs1, prefs2) {
if (prefs1 === prefs2) {
return true;
}
if (!prefs1 || !prefs2) {
return false;
}
// Scan the preference objects one level deep to see if they differ.
const keys1 = Object.keys(prefs1);
const keys2 = Object.keys(prefs2);
return keys1.length === keys2.length &&
keys1.every(key => prefs1[key] === prefs2[key]) &&
keys2.every(key => prefs1[key] === prefs2[key]);
}
_pathObserver() {
// Call _prefsChanged(), because line-limit style value depends on path.
this._prefsChanged(this.prefs);

View File

@@ -710,6 +710,22 @@ suite('gr-diff tests', () => {
assert.isTrue(element._renderDiffTable.called);
});
test('adding/removing property in preferences re-renders diff', () => {
const stub = sandbox.stub(element, '_renderDiffTable');
const newPrefs1 = Object.assign({}, MINIMAL_PREFS,
{line_wrapping: true});
element.prefs = newPrefs1;
element.flushDebouncer('renderDiffTable');
assert.isTrue(element._renderDiffTable.called);
stub.reset();
const newPrefs2 = Object.assign({}, newPrefs1);
delete newPrefs2.line_wrapping;
element.prefs = newPrefs2;
element.flushDebouncer('renderDiffTable');
assert.isTrue(element._renderDiffTable.called);
});
test('change in preferences does not re-renders diff with ' +
'noRenderOnPrefsChange', () => {
sandbox.stub(element, '_renderDiffTable');
@@ -902,6 +918,24 @@ suite('gr-diff tests', () => {
assert.equal(element._computeNewlineWarningClass(null, false), hidden);
assert.equal(element._computeNewlineWarningClass('foo', false), shown);
});
test('_prefsEqual', () => {
element = fixture('basic');
assert.isTrue(element._prefsEqual(null, null));
assert.isTrue(element._prefsEqual({}, {}));
assert.isTrue(element._prefsEqual({x: 1}, {x: 1}));
assert.isTrue(
element._prefsEqual({x: 1, abc: 'def'}, {x: 1, abc: 'def'}));
const somePref = {abc: 'def', p: true};
assert.isTrue(element._prefsEqual(somePref, somePref));
assert.isFalse(element._prefsEqual({}, null));
assert.isFalse(element._prefsEqual(null, {}));
assert.isFalse(element._prefsEqual({x: 1}, {x: 2}));
assert.isFalse(element._prefsEqual({x: 1, y: 'abc'}, {x: 1, y: 'abcd'}));
assert.isFalse(element._prefsEqual({x: 1, y: 'abc'}, {x: 1}));
assert.isFalse(element._prefsEqual({x: 1}, {x: 1, y: 'abc'}));
});
});
suite('key locations', () => {

View File

@@ -107,6 +107,7 @@ const elements = [
'diff/gr-diff-highlight/gr-diff-highlight_test.html',
'diff/gr-diff-host/gr-diff-host_test.html',
'diff/gr-diff-mode-selector/gr-diff-mode-selector_test.html',
'diff/gr-diff-preferences-dialog/gr-diff-preferences-dialog_test.html',
'diff/gr-diff-processor/gr-diff-processor_test.html',
'diff/gr-diff-selection/gr-diff-selection_test.html',
'diff/gr-diff-view/gr-diff-view_test.html',