Print Preview: Migrate more settings sections to class-based syntax
- other_options_settings.js
- pages_settings.js
- pages_per_sheet_settings.js
Bug: 1206112
Change-Id: Ifc194f8122825a4b167262737342ca3bb078d0ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3131351
Reviewed-by: John Lee <johntlee@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#917472}
diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js
index 012a890..dc0129c 100644
--- a/chrome/browser/resources/print_preview/print_preview.js
+++ b/chrome/browser/resources/print_preview/print_preview.js
@@ -65,6 +65,9 @@
export {PrintPreviewMarginsSettingsElement} from './ui/margins_settings.js';
export {PrintPreviewMediaSizeSettingsElement} from './ui/media_size_settings.js';
export {PrintPreviewNumberSettingsSectionElement} from './ui/number_settings_section.js';
+export {PrintPreviewOtherOptionsSettingsElement} from './ui/other_options_settings.js';
+export {PrintPreviewPagesPerSheetSettingsElement} from './ui/pages_per_sheet_settings.js';
+export {PrintPreviewPagesSettingsElement} from './ui/pages_settings.js';
export {PDFPlugin, PluginProxy, PluginProxyImpl} from './ui/plugin_proxy.js';
export {PreviewAreaState} from './ui/preview_area.js';
export {SelectBehavior} from './ui/select_behavior.js';
diff --git a/chrome/browser/resources/print_preview/ui/other_options_settings.js b/chrome/browser/resources/print_preview/ui/other_options_settings.js
index 153c763..da6b155 100644
--- a/chrome/browser/resources/print_preview/ui/other_options_settings.js
+++ b/chrome/browser/resources/print_preview/ui/other_options_settings.js
@@ -8,62 +8,85 @@
import './settings_section.js';
import '../strings.m.js';
-import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
-import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
+import {I18nBehavior, I18nBehaviorInterface} from 'chrome://resources/js/i18n_behavior.m.js';
+import {html, mixinBehaviors, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
-import {SettingsBehavior} from './settings_behavior.js';
+import {SettingsBehavior, SettingsBehaviorInterface} from './settings_behavior.js';
-Polymer({
- is: 'print-preview-other-options-settings',
+/**
+ * @constructor
+ * @extends {PolymerElement}
+ * @implements {I18nBehaviorInterface}
+ * @implements {SettingsBehaviorInterface}
+ */
+const PrintPreviewOtherOptionsSettingsElementBase =
+ mixinBehaviors([SettingsBehavior, I18nBehavior], PolymerElement);
- _template: html`{__html_template__}`,
+/** @polymer */
+export class PrintPreviewOtherOptionsSettingsElement extends
+ PrintPreviewOtherOptionsSettingsElementBase {
+ static get is() {
+ return 'print-preview-other-options-settings';
+ }
- behaviors: [SettingsBehavior, I18nBehavior],
+ static get template() {
+ return html`{__html_template__}`;
+ }
- properties: {
- disabled: Boolean,
+ static get properties() {
+ return {
+ disabled: Boolean,
- /**
- * @private {!Array<!{name: string,
- * label: string,
- * value: (boolean | undefined),
- * managed: (boolean | undefined),
- * available: (boolean | undefined)}>}
- */
- options_: {
- type: Array,
- value() {
- return [
- {name: 'headerFooter', label: 'optionHeaderFooter'},
- {name: 'cssBackground', label: 'optionBackgroundColorsAndImages'},
- {name: 'rasterize', label: 'optionRasterize'},
- {name: 'selectionOnly', label: 'optionSelectionOnly'},
- ];
+ /**
+ * @private {!Array<!{name: string,
+ * label: string,
+ * value: (boolean | undefined),
+ * managed: (boolean | undefined),
+ * available: (boolean | undefined)}>}
+ */
+ options_: {
+ type: Array,
+ value() {
+ return [
+ {name: 'headerFooter', label: 'optionHeaderFooter'},
+ {name: 'cssBackground', label: 'optionBackgroundColorsAndImages'},
+ {name: 'rasterize', label: 'optionRasterize'},
+ {name: 'selectionOnly', label: 'optionSelectionOnly'},
+ ];
+ },
},
- },
- /**
- * The index of the checkbox that should display the "Options" title.
- * @private {number}
- */
- firstIndex_: {
- type: Number,
- value: 0,
- },
- },
+ /**
+ * The index of the checkbox that should display the "Options" title.
+ * @private {number}
+ */
+ firstIndex_: {
+ type: Number,
+ value: 0,
+ },
- observers: [
- 'onHeaderFooterSettingChange_(settings.headerFooter.*)',
- 'onCssBackgroundSettingChange_(settings.cssBackground.*)',
- 'onRasterizeSettingChange_(settings.rasterize.*)',
- 'onSelectionOnlySettingChange_(settings.selectionOnly.*)',
- ],
+ };
+ }
- /** @private {!Map<string, ?number>} */
- timeouts_: new Map(),
+ static get observers() {
+ return [
+ 'onHeaderFooterSettingChange_(settings.headerFooter.*)',
+ 'onCssBackgroundSettingChange_(settings.cssBackground.*)',
+ 'onRasterizeSettingChange_(settings.rasterize.*)',
+ 'onSelectionOnlySettingChange_(settings.selectionOnly.*)',
- /** @private {!Map<string, boolean>} */
- previousValues_: new Map(),
+ ];
+ }
+
+ constructor() {
+ super();
+
+ /** @private {!Map<string, ?number>} */
+ this.timeouts_ = new Map();
+
+ /** @private {!Map<string, boolean>} */
+ this.previousValues_ = new Map();
+ }
/**
* @param {string} settingName The name of the setting to updated.
@@ -85,9 +108,11 @@
this.setSetting(settingName, newValue);
// For tests only
- this.fire('update-checkbox-setting', settingName);
+ this.dispatchEvent(new CustomEvent(
+ 'update-checkbox-setting',
+ {bubbles: true, composed: true, detail: settingName}));
}, 200));
- },
+ }
/**
* @param {number} index The index of the option to update.
@@ -104,7 +129,7 @@
if (availableOptions.length > 0) {
this.firstIndex_ = this.options_.indexOf(availableOptions[0]);
}
- },
+ }
/**
* @param {boolean} managed Whether the setting is managed by policy.
@@ -114,27 +139,27 @@
*/
getDisabled_(managed, disabled) {
return managed || disabled;
- },
+ }
/** @private */
onHeaderFooterSettingChange_() {
this.updateOptionFromSetting_(0);
- },
+ }
/** @private */
onCssBackgroundSettingChange_() {
this.updateOptionFromSetting_(1);
- },
+ }
/** @private */
onRasterizeSettingChange_() {
this.updateOptionFromSetting_(2);
- },
+ }
/** @private */
onSelectionOnlySettingChange_() {
this.updateOptionFromSetting_(3);
- },
+ }
/**
* @param {!Event} e Contains the checkbox item that was checked.
@@ -142,8 +167,9 @@
*/
onChange_(e) {
const name = e.model.item.name;
- this.updateSettingWithTimeout_(name, this.$$(`#${name}`).checked);
- },
+ this.updateSettingWithTimeout_(
+ name, this.shadowRoot.querySelector(`#${name}`).checked);
+ }
/**
* @param {number} index The index of the settings section.
@@ -153,5 +179,9 @@
*/
getClass_(index) {
return index === this.firstIndex_ ? 'first-visible' : '';
- },
-});
+ }
+}
+
+customElements.define(
+ PrintPreviewOtherOptionsSettingsElement.is,
+ PrintPreviewOtherOptionsSettingsElement);
diff --git a/chrome/browser/resources/print_preview/ui/pages_per_sheet_settings.js b/chrome/browser/resources/print_preview/ui/pages_per_sheet_settings.js
index 9c5d692..8e9c538 100644
--- a/chrome/browser/resources/print_preview/ui/pages_per_sheet_settings.js
+++ b/chrome/browser/resources/print_preview/ui/pages_per_sheet_settings.js
@@ -6,25 +6,45 @@
import './print_preview_shared_css.js';
import './settings_section.js';
-import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
+import {html, mixinBehaviors, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {MarginsType} from '../data/margins.js';
-import {SelectBehavior} from './select_behavior.js';
-import {SettingsBehavior} from './settings_behavior.js';
+import {SelectBehavior, SelectBehaviorInterface} from './select_behavior.js';
+import {SettingsBehavior, SettingsBehaviorInterface} from './settings_behavior.js';
-Polymer({
- is: 'print-preview-pages-per-sheet-settings',
+/**
+ * @constructor
+ * @extends {PolymerElement}
+ * @implements {SelectBehaviorInterface}
+ * @implements {SettingsBehaviorInterface}
+ */
+const PrintPreviewPagesPerSheetSettingsElementBase =
+ mixinBehaviors([SettingsBehavior, SelectBehavior], PolymerElement);
- _template: html`{__html_template__}`,
+/** @polymer */
+export class PrintPreviewPagesPerSheetSettingsElement extends
+ PrintPreviewPagesPerSheetSettingsElementBase {
+ static get is() {
+ return 'print-preview-pages-per-sheet-settings';
+ }
- behaviors: [SettingsBehavior, SelectBehavior],
+ static get template() {
+ return html`{__html_template__}`;
+ }
- properties: {
- disabled: Boolean,
- },
+ static get properties() {
+ return {
+ disabled: Boolean,
- observers: ['onPagesPerSheetSettingChange_(settings.pagesPerSheet.value)'],
+ };
+ }
+
+ static get observers() {
+ return [
+ 'onPagesPerSheetSettingChange_(settings.pagesPerSheet.value)',
+ ];
+ }
/**
* @param {*} newValue The new value of the pages per sheet setting.
@@ -32,10 +52,14 @@
*/
onPagesPerSheetSettingChange_(newValue) {
this.selectedValue = /** @type {number} */ (newValue).toString();
- },
+ }
/** @param {string} value The new select value. */
onProcessSelectChange(value) {
this.setSetting('pagesPerSheet', parseInt(value, 10));
- },
-});
+ }
+}
+
+customElements.define(
+ PrintPreviewPagesPerSheetSettingsElement.is,
+ PrintPreviewPagesPerSheetSettingsElement);
diff --git a/chrome/browser/resources/print_preview/ui/pages_settings.js b/chrome/browser/resources/print_preview/ui/pages_settings.js
index e14001fb..9956eae 100644
--- a/chrome/browser/resources/print_preview/ui/pages_settings.js
+++ b/chrome/browser/resources/print_preview/ui/pages_settings.js
@@ -11,13 +11,14 @@
import {assert} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
-import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
+import {WebUIListenerBehavior, WebUIListenerBehaviorInterface} from 'chrome://resources/js/web_ui_listener_behavior.m.js';
+import {html, mixinBehaviors, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {areRangesEqual} from '../print_preview_utils.js';
-import {InputBehavior} from './input_behavior.js';
-import {SelectBehavior} from './select_behavior.js';
-import {SettingsBehavior} from './settings_behavior.js';
+import {InputBehavior, InputBehaviorInterface} from './input_behavior.js';
+import {SelectBehavior, SelectBehaviorInterface} from './select_behavior.js';
+import {SettingsBehavior, SettingsBehaviorInterface} from './settings_behavior.js';
/** @enum {number} */
const PagesInputErrorState = {
@@ -50,110 +51,149 @@
return NaN;
}
-Polymer({
- is: 'print-preview-pages-settings',
- _template: html`{__html_template__}`,
+/**
+ * @constructor
+ * @extends {PolymerElement}
+ * @implements {InputBehaviorInterface}
+ * @implements {SelectBehaviorInterface}
+ * @implements {SettingsBehaviorInterface}
+ * @implements {WebUIListenerBehaviorInterface}
+ */
+const PrintPreviewPagesSettingsElementBase = mixinBehaviors(
+ [SettingsBehavior, InputBehavior, SelectBehavior, WebUIListenerBehavior],
+ PolymerElement);
- behaviors: [SettingsBehavior, InputBehavior, SelectBehavior],
+/** @polymer */
+export class PrintPreviewPagesSettingsElement extends
+ PrintPreviewPagesSettingsElementBase {
+ static get is() {
+ return 'print-preview-pages-settings';
+ }
- properties: {
- disabled: Boolean,
+ static get template() {
+ return html`{__html_template__}`;
+ }
- pageCount: {
- type: Number,
- observer: 'onPageCountChange_',
- },
+ static get properties() {
+ return {
+ disabled: Boolean,
- /** @private {boolean} */
- controlsDisabled_: {
- type: Boolean,
- computed: 'computeControlsDisabled_(disabled, hasError_)',
- },
-
- /** @private {number} */
- errorState_: {
- type: Number,
- reflectToAttribute: true,
- value: PagesInputErrorState.NO_ERROR,
- },
-
- /** @private {string} */
- inputString_: {
- type: String,
- value: '',
- },
-
- /** @private {!Array<number>} */
- pagesToPrint_: {
- type: Array,
- value() {
- return [];
+ pageCount: {
+ type: Number,
+ observer: 'onPageCountChange_',
},
- },
- /** @private {!Array<{to: number, from: number}>} */
- rangesToPrint_: {
- type: Array,
- computed: 'computeRangesToPrint_(pagesToPrint_)',
- },
+ /** @private {boolean} */
+ controlsDisabled_: {
+ type: Boolean,
+ computed: 'computeControlsDisabled_(disabled, hasError_)',
+ },
- /** @private {number} */
- selection_: {
- type: Number,
- value: PagesValue.ALL,
- observer: 'onSelectionChange_',
- },
+ /** @private {number} */
+ errorState_: {
+ type: Number,
+ reflectToAttribute: true,
+ value: PagesInputErrorState.NO_ERROR,
+ },
+
+ /** @private {boolean} */
+ hasError_: {
+ type: Boolean,
+ value: false,
+ },
+
+ /** @private {string} */
+ inputString_: {
+ type: String,
+ value: '',
+ },
+
+ /** @private {!Array<number>} */
+ pagesToPrint_: {
+ type: Array,
+ value() {
+ return [];
+ },
+ },
+
+ /** @private {!Array<{to: number, from: number}>} */
+ rangesToPrint_: {
+ type: Array,
+ computed: 'computeRangesToPrint_(pagesToPrint_)',
+ },
+
+ /** @private {number} */
+ selection_: {
+ type: Number,
+ value: PagesValue.ALL,
+ observer: 'onSelectionChange_',
+ },
+
+ /**
+ * Mirroring the enum so that it can be used from HTML bindings.
+ * @private
+ */
+ pagesValueEnum_: {
+ type: Object,
+ value: PagesValue,
+ },
+
+ };
+ }
+
+ static get observers() {
+ return [
+ 'updatePagesToPrint_(inputString_)',
+ 'onRangeChange_(errorState_, rangesToPrint_, settings.pages, ' +
+ 'settings.pagesPerSheet.value)',
+ ];
+ }
+
+ constructor() {
+ super();
/**
- * Mirroring the enum so that it can be used from HTML bindings.
- * @private
+ * True if the user's last valid input should be restored to the custom
+ * input field. Cleared when the input is set automatically, or the user
+ * manually clears the field.
+ * @private {boolean}
*/
- pagesValueEnum_: {
- type: Object,
- value: PagesValue,
- },
- },
+ this.restoreLastInput_ = true;
- observers: [
- 'updatePagesToPrint_(inputString_)',
- 'onRangeChange_(errorState_, rangesToPrint_, settings.pages, ' +
- 'settings.pagesPerSheet.value)',
- ],
+ /**
+ * Memorizes the user's last non-custom pages setting. Used when
+ * `PagesValue.ODDS` and `PagesValue.EVEN` become invalid due to a changed
+ * page count.
+ * @private {number}
+ */
+ this.resorationValue_ = PagesValue.ALL;
+ }
- listeners: {
- 'input-change': 'onInputChange_',
- },
+ /** @override */
+ ready() {
+ super.ready();
+
+ this.addEventListener(
+ 'input-change',
+ e => this.onInputChange_(/** @type {!CustomEvent<string>} */ (e)));
+ }
/**
- * True if the user's last valid input should be restored to the custom input
- * field. Cleared when the input is set automatically, or the user manually
- * clears the field.
- * @private {boolean}
- */
- restoreLastInput_: true,
-
- /**
- * Memorizes the user's last non-custom pages setting. Used when
- * `PagesValue.ODDS` and `PagesValue.EVEN` become invalid due to a changed
- * page count.
- * @private {number}
- */
- resorationValue_: PagesValue.ALL,
-
- /**
- * Initialize |selectedValue| in attached() since this doesn't observe
- * settings.pages, because settings.pages is not sticky.
+ * Initialize |selectedValue| in connectedCallback() since this doesn't
+ * observe settings.pages, because settings.pages is not sticky.
* @override
*/
- attached() {
+ connectedCallback() {
+ super.connectedCallback();
+
this.selectedValue = PagesValue.ALL.toString();
- },
+ }
/** @return {!CrInputElement} The cr-input field element for InputBehavior. */
getInput() {
return /** @type {!CrInputElement} */ (this.$.pageSettingsCustomInput);
- },
+ }
/**
* @param {number} value
@@ -161,8 +201,9 @@
*/
setSelectedValue_(value) {
this.selectedValue = value.toString();
- this.$$('select').dispatchEvent(new CustomEvent('change'));
- },
+ this.shadowRoot.querySelector('select').dispatchEvent(
+ new CustomEvent('change'));
+ }
/**
* @param {!CustomEvent<string>} e Contains the new input value.
@@ -173,11 +214,11 @@
this.restoreLastInput_ = true;
}
this.inputString_ = e.detail;
- },
+ }
onProcessSelectChange(value) {
this.selection_ = parseInt(value, 10);
- },
+ }
/** @private */
onCollapseChanged_() {
@@ -185,7 +226,7 @@
/** @type {!CrInputElement} */ (this.$.pageSettingsCustomInput)
.inputElement.focus();
}
- },
+ }
/**
* @return {boolean} Whether the controls should be disabled.
@@ -194,7 +235,7 @@
computeControlsDisabled_() {
// Disable the input if other settings are responsible for the error state.
return !this.hasError_ && this.disabled;
- },
+ }
/**
* Updates pages to print and error state based on the validity and
@@ -295,7 +336,7 @@
this.errorState_ = PagesInputErrorState.NO_ERROR;
this.pagesToPrint_ = pages;
- },
+ }
/**
* @return {!Array<{to: number, from: number}>}
@@ -322,7 +363,7 @@
}
ranges.push({from: from, to: to});
return ranges;
- },
+ }
/**
* @return {!Array<number>} The final page numbers, reflecting N-up setting.
@@ -343,7 +384,7 @@
nupPages[i] = i + 1;
}
return nupPages;
- },
+ }
/**
* Updates the model with pages and validity, and adds error styling if
@@ -380,7 +421,7 @@
}
this.setSettingValid('pages', true);
this.hasError_ = false;
- },
+ }
/** @private */
onSelectBlur_(event) {
@@ -390,19 +431,20 @@
}
this.onCustomInputBlur_();
- },
+ }
/** @private */
onCustomInputBlur_() {
this.resetAndUpdate();
if (this.errorState_ === PagesInputErrorState.EMPTY) {
// Update with all pages.
- this.$$('cr-input').value = this.getAllPagesString_();
+ this.shadowRoot.querySelector('cr-input').value =
+ this.getAllPagesString_();
this.inputString_ = this.getAllPagesString_();
this.resetString();
this.restoreLastInput_ = false;
}
- },
+ }
/**
* @return {string} Gets message to show as hint.
@@ -424,7 +466,7 @@
'pageRangeLimitInstructionWithValue', this.pageCount);
}
return formattedMessage.replace(/<\/b>|<b>/g, '');
- },
+ }
/**
* @return {boolean} Whether the document being printed has only one page.
@@ -432,7 +474,7 @@
*/
isSinglePage_() {
return this.pageCount === 1;
- },
+ }
/**
* @return {boolean} Whether to hide the hint.
@@ -441,7 +483,7 @@
hintHidden_() {
return this.errorState_ === PagesInputErrorState.NO_ERROR ||
this.errorState_ === PagesInputErrorState.EMPTY;
- },
+ }
/**
* @return {boolean} Whether to disable the custom input.
@@ -449,7 +491,7 @@
*/
inputDisabled_() {
return this.selection_ !== PagesValue.CUSTOM || this.controlsDisabled_;
- },
+ }
/**
* @return {boolean} Whether to display the custom input.
@@ -457,7 +499,7 @@
*/
shouldShowInput_() {
return this.selection_ === PagesValue.CUSTOM;
- },
+ }
/**
* @return {string} A string representing the full page range.
@@ -469,7 +511,7 @@
}
return this.pageCount === 1 ? '1' : `1-${this.pageCount}`;
- },
+ }
/** @private */
onSelectionChange_() {
@@ -478,11 +520,11 @@
this.errorState_ !== PagesInputErrorState.NO_ERROR) {
this.restoreLastInput_ = true;
this.inputString_ = '';
- this.$$('cr-input').value = '';
+ this.shadowRoot.querySelector('cr-input').value = '';
this.resetString();
}
this.updatePagesToPrint_();
- },
+ }
/**
* @param {number} current
@@ -510,11 +552,15 @@
(current < previous || !this.restoreLastInput_);
if (resetCustom) {
- this.$$('cr-input').value = this.getAllPagesString_();
+ this.shadowRoot.querySelector('cr-input').value =
+ this.getAllPagesString_();
this.inputString_ = this.getAllPagesString_();
this.resetString();
} else {
this.updatePagesToPrint_();
}
- },
-});
+ }
+}
+
+customElements.define(
+ PrintPreviewPagesSettingsElement.is, PrintPreviewPagesSettingsElement);
diff --git a/chrome/test/data/webui/print_preview/other_options_settings_test.js b/chrome/test/data/webui/print_preview/other_options_settings_test.js
index c3219b1..44f3fd2 100644
--- a/chrome/test/data/webui/print_preview/other_options_settings_test.js
+++ b/chrome/test/data/webui/print_preview/other_options_settings_test.js
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import {PrintPreviewModelElement} from 'chrome://print/print_preview.js';
+import {PrintPreviewModelElement, PrintPreviewOtherOptionsSettingsElement} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
@@ -51,7 +51,8 @@
test('checkbox visibility', function() {
['headerFooter', 'cssBackground', 'rasterize', 'selectionOnly'].forEach(
setting => {
- const checkbox = otherOptionsSection.$$(`#${setting}`);
+ const checkbox =
+ otherOptionsSection.shadowRoot.querySelector(`#${setting}`);
// Show, hide and reset.
[true, false, true].forEach(value => {
model.set(`settings.${setting}.available`, value);
@@ -63,7 +64,8 @@
test('set with checkbox', async () => {
const testOptionCheckbox = (settingName) => {
- const element = otherOptionsSection.$$('#' + settingName);
+ const element =
+ otherOptionsSection.shadowRoot.querySelector(`#${settingName}`);
const optionSetting = otherOptionsSection.getSetting(settingName);
assertFalse(isSectionHidden(element));
assertTrue(element.checked);
@@ -88,7 +90,8 @@
test('update from setting', function() {
['headerFooter', 'cssBackground', 'rasterize', 'selectionOnly'].forEach(
setting => {
- const checkbox = otherOptionsSection.$$(`#${setting}`);
+ const checkbox =
+ otherOptionsSection.shadowRoot.querySelector(`#${setting}`);
// Set true and then false.
[true, false].forEach(value => {
otherOptionsSection.setSetting(setting, value);
@@ -101,7 +104,8 @@
// Tests that if settings are enforced by enterprise policy the checkbox
// is disabled.
test('header footer disabled by policy', function() {
- const checkbox = otherOptionsSection.$$('#headerFooter');
+ const checkbox =
+ otherOptionsSection.shadowRoot.querySelector('#headerFooter');
// Set true and then false.
[true, false].forEach(value => {
model.set('settings.headerFooter.setByPolicy', value);
diff --git a/chrome/test/data/webui/print_preview/pages_per_sheet_settings_test.js b/chrome/test/data/webui/print_preview/pages_per_sheet_settings_test.js
index 04a176a..60b061b 100644
--- a/chrome/test/data/webui/print_preview/pages_per_sheet_settings_test.js
+++ b/chrome/test/data/webui/print_preview/pages_per_sheet_settings_test.js
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import {MarginsType} from 'chrome://print/print_preview.js';
+import {MarginsType, PrintPreviewPagesPerSheetSettingsElement} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {selectOption} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {eventToPromise, fakeDataBind} from 'chrome://test/test_util.js';
suite('PagesPerSheetSettingsTest', function() {
+ /** @type {?PrintPreviewPagesPerSheetSettingsElement} */
let pagesPerSheetSection = null;
/** @override */
@@ -26,7 +27,7 @@
// Tests that setting the setting updates the UI.
test('set setting', async () => {
- const select = pagesPerSheetSection.$$('select');
+ const select = pagesPerSheetSection.shadowRoot.querySelector('select');
assertEquals('1', select.value);
pagesPerSheetSection.setSetting('pagesPerSheet', 4);
@@ -37,7 +38,7 @@
// Tests that selecting a new option in the dropdown updates the setting.
test('select option', async () => {
// Verify that the selected option and names are as expected.
- const select = pagesPerSheetSection.$$('select');
+ const select = pagesPerSheetSection.shadowRoot.querySelector('select');
assertEquals('1', select.value);
assertEquals(1, pagesPerSheetSection.getSettingValue('pagesPerSheet'));
assertFalse(pagesPerSheetSection.getSetting('pagesPerSheet').setFromUi);
diff --git a/chrome/test/data/webui/print_preview/pages_settings_test.js b/chrome/test/data/webui/print_preview/pages_settings_test.js
index 4ba7ebe5..f91b0c7 100644
--- a/chrome/test/data/webui/print_preview/pages_settings_test.js
+++ b/chrome/test/data/webui/print_preview/pages_settings_test.js
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import {PrintPreviewPagesSettingsElement} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {keyEventOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
@@ -77,8 +78,12 @@
assertEquals(range.from, rangesValue[index].from);
});
assertEquals(!invalid, pagesSection.getSetting('pages').valid);
- assertEquals(expectedError !== '', pagesSection.$$('cr-input').invalid);
- assertEquals(expectedError, pagesSection.$$('cr-input').errorMessage);
+ assertEquals(
+ expectedError !== '',
+ pagesSection.shadowRoot.querySelector('cr-input').invalid);
+ assertEquals(
+ expectedError,
+ pagesSection.shadowRoot.querySelector('cr-input').errorMessage);
}
// Verifies that the pages setting updates correctly when the dropdown
@@ -87,8 +92,9 @@
pagesSection.pageCount = 5;
// Default value is all pages.
- const pagesSelect = pagesSection.$$('select');
- const customInputCollapse = pagesSection.$$('iron-collapse');
+ const pagesSelect = pagesSection.shadowRoot.querySelector('select');
+ const customInputCollapse =
+ pagesSection.shadowRoot.querySelector('iron-collapse');
const pagesCrInput = pagesSection.$.pageSettingsCustomInput;
const pagesInput = pagesCrInput.inputElement;
@@ -143,12 +149,12 @@
test(assert(pages_settings_test.TestNames.NoParityOptions), async () => {
pagesSection.pageCount = 1;
- const oddOption =
- pagesSection.$$(`[value="${pagesSection.pagesValueEnum_.ODDS}"]`);
+ const oddOption = pagesSection.shadowRoot.querySelector(
+ `[value="${pagesSection.pagesValueEnum_.ODDS}"]`);
assertTrue(oddOption.hidden);
- const evenOption =
- pagesSection.$$(`[value="${pagesSection.pagesValueEnum_.EVENS}"]`);
+ const evenOption = pagesSection.shadowRoot.querySelector(
+ `[value="${pagesSection.pagesValueEnum_.EVENS}"]`);
assertTrue(evenOption.hidden);
});
@@ -157,7 +163,7 @@
test(
assert(pages_settings_test.TestNames.ParitySelectionMemorized),
async () => {
- const select = pagesSection.$$('select');
+ const select = pagesSection.shadowRoot.querySelector('select');
pagesSection.pageCount = 2;
assertEquals(pagesSection.pagesValueEnum_.ALL.toString(), select.value);
@@ -303,7 +309,7 @@
test(assert(pages_settings_test.TestNames.ClearInput), async () => {
pagesSection.pageCount = 3;
const input = pagesSection.$.pageSettingsCustomInput.inputElement;
- const select = pagesSection.$$('select');
+ const select = pagesSection.shadowRoot.querySelector('select');
const allValue = pagesSection.pagesValueEnum_.ALL.toString();
const customValue = pagesSection.pagesValueEnum_.CUSTOM.toString();
assertEquals(allValue, select.value);
@@ -437,7 +443,7 @@
// Setup an empty input by selecting custom..
const customValue = pagesSection.pagesValueEnum_.CUSTOM.toString();
- const pagesSelect = pagesSection.$$('select');
+ const pagesSelect = pagesSection.shadowRoot.querySelector('select');
await Promise.all([
selectOption(pagesSection, customValue),
eventToPromise('focus', input)