Commit 5ef260da authored by Alex Ilin's avatar Alex Ilin Committed by Commit Bot

Add an option to cr-customize-themes to auto confirm theme changes

Some UIs using cr-customize-themes won't have a confirm button. The
theme should be applied and automatically confirmed in that case.

Bug: 1129186
Change-Id: I34d11264ddcd1977ca5d2179024016f80f10546f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418374Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Auto-Submit: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808568}
parent a4a330bd
...@@ -181,33 +181,51 @@ suite('CrComponentsCustomizeThemesTest', () => { ...@@ -181,33 +181,51 @@ suite('CrComponentsCustomizeThemesTest', () => {
tiles[3], '--cr-theme-icon-active-tab-color', 'rgba(0, 255, 0, 1)'); tiles[3], '--cr-theme-icon-active-tab-color', 'rgba(0, 255, 0, 1)');
}); });
test('clicking default theme calls applying default theme', async () => { [true, false].forEach(autoConfirm => {
// Arrange. test(
const customizeThemesElement = createCustomizeThemesElement(); `clicking default theme with autoConfirm="${
await flushTasks(); autoConfirm}" applies default theme`,
async () => {
// Act. // Arrange.
customizeThemesElement.shadowRoot.querySelector('#defaultTheme').click(); const customizeThemesElement = createCustomizeThemesElement();
customizeThemesElement.autoConfirmThemeChanges = autoConfirm;
// Assert. await flushTasks();
assertEquals(1, testProxy.testHandler.getCallCount('applyDefaultTheme'));
}); // Act.
customizeThemesElement.shadowRoot.querySelector('#defaultTheme')
test('selecting color calls applying autogenerated theme', async () => { .click();
// Arrange.
const customizeThemesElement = createCustomizeThemesElement(); // Assert.
const applyAutogeneratedThemeCalled = assertEquals(
testProxy.testHandler.whenCalled('applyAutogeneratedTheme'); 1, testProxy.testHandler.getCallCount('applyDefaultTheme'));
assertEquals(
// Act. autoConfirm ? 1 : 0,
customizeThemesElement.shadowRoot.querySelector('#colorPicker').value = testProxy.testHandler.getCallCount('confirmThemeChanges'));
'#ff0000'; });
customizeThemesElement.shadowRoot.querySelector('#colorPicker')
.dispatchEvent(new Event('change')); test(
`selecting color with autoConfirm="${
// Assert. autoConfirm}" applies autogenerated theme`,
const {value} = await applyAutogeneratedThemeCalled; async () => {
assertEquals(value, 0xffff0000); // Arrange.
const customizeThemesElement = createCustomizeThemesElement();
customizeThemesElement.autoConfirmThemeChanges = autoConfirm;
const applyAutogeneratedThemeCalled =
testProxy.testHandler.whenCalled('applyAutogeneratedTheme');
// Act.
customizeThemesElement.shadowRoot.querySelector('#colorPicker')
.value = '#ff0000';
customizeThemesElement.shadowRoot.querySelector('#colorPicker')
.dispatchEvent(new Event('change'));
// Assert.
const {value} = await applyAutogeneratedThemeCalled;
assertEquals(value, 0xffff0000);
assertEquals(
autoConfirm ? 1 : 0,
testProxy.testHandler.getCallCount('confirmThemeChanges'));
});
}); });
test('setting autogenerated theme selects and updates icon', async () => { test('setting autogenerated theme selects and updates icon', async () => {
......
...@@ -37,13 +37,27 @@ export class CustomizeThemesElement extends mixinBehaviors ...@@ -37,13 +37,27 @@ export class CustomizeThemesElement extends mixinBehaviors
static get properties() { static get properties() {
return { return {
/** @type {!customizeThemes.mojom.Theme} */ /**
* An object describing the currently selected theme.
* @type {!customizeThemes.mojom.Theme}
*/
selectedTheme: { selectedTheme: {
type: Object, type: Object,
observer: 'onThemeChange_', observer: 'onThemeChange_',
notify: true, notify: true,
}, },
/**
* If false, confirmThemeChanges() should be called after applying a theme
* to permanently apply the change. Otherwise, theme changes are confirmed
* automatically.
* @type {Boolean}
*/
autoConfirmThemeChanges: {
type: Boolean,
value: false,
},
/** @private {!Array<!customizeThemes.mojom.ChromeTheme>} */ /** @private {!Array<!customizeThemes.mojom.ChromeTheme>} */
chromeThemes_: Array, chromeThemes_: Array,
}; };
...@@ -97,6 +111,9 @@ export class CustomizeThemesElement extends mixinBehaviors ...@@ -97,6 +111,9 @@ export class CustomizeThemesElement extends mixinBehaviors
*/ */
onCustomFrameColorChange_(e) { onCustomFrameColorChange_(e) {
this.handler_.applyAutogeneratedTheme(hexColorToSkColor(e.target.value)); this.handler_.applyAutogeneratedTheme(hexColorToSkColor(e.target.value));
if (this.autoConfirmThemeChanges) {
this.handler_.confirmThemeChanges();
}
} }
/** @private */ /** @private */
...@@ -107,6 +124,9 @@ export class CustomizeThemesElement extends mixinBehaviors ...@@ -107,6 +124,9 @@ export class CustomizeThemesElement extends mixinBehaviors
/** @private */ /** @private */
onDefaultThemeClick_() { onDefaultThemeClick_() {
this.handler_.applyDefaultTheme(); this.handler_.applyDefaultTheme();
if (this.autoConfirmThemeChanges) {
this.handler_.confirmThemeChanges();
}
} }
/** /**
...@@ -115,6 +135,9 @@ export class CustomizeThemesElement extends mixinBehaviors ...@@ -115,6 +135,9 @@ export class CustomizeThemesElement extends mixinBehaviors
*/ */
onChromeThemeClick_(e) { onChromeThemeClick_(e) {
this.handler_.applyChromeTheme(this.$.themes.itemForElement(e.target).id); this.handler_.applyChromeTheme(this.$.themes.itemForElement(e.target).id);
if (this.autoConfirmThemeChanges) {
this.handler_.confirmThemeChanges();
}
} }
/** @private */ /** @private */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment