Commit 39f59fab authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Remove "ticket_items" namespace

This namespace is leftover from the old Print Preview JS code, is no
longer needed to disambiguate anything, and makes enum names
unnecessarily long. Remove it and move the enums to the general
"print_preview" namespace.

Bug: None
Change-Id: Iaf43f4f514b0a4332e8b0e7157bf75cf731ecaf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832621Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701305}
parent 63cdb148
......@@ -159,7 +159,7 @@ Polymer({
Math.round(pageLayout.marginTop), Math.round(pageLayout.marginRight),
Math.round(pageLayout.marginBottom), Math.round(pageLayout.marginLeft));
const o = print_preview.ticket_items.CustomMarginsOrientation;
const o = print_preview.CustomMarginsOrientation;
const pageSize = new print_preview.Size(
pageLayout.contentWidth + margins.get(o.LEFT) + margins.get(o.RIGHT),
pageLayout.contentHeight + margins.get(o.TOP) + margins.get(o.BOTTOM));
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('print_preview.ticket_items', function() {
cr.define('print_preview', function() {
'use strict';
/**
......@@ -61,18 +61,14 @@ cr.define('print_preview', function() {
/**
* Backing store for the margin values in points.
* @type {!Object<
* !print_preview.ticket_items.CustomMarginsOrientation, number>}
* !print_preview.CustomMarginsOrientation, number>}
* @private
*/
this.value_ = {};
this.value_[print_preview.ticket_items.CustomMarginsOrientation.TOP] =
top;
this.value_[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] =
right;
this.value_[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] =
bottom;
this.value_[print_preview.ticket_items.CustomMarginsOrientation.LEFT] =
left;
this.value_[print_preview.CustomMarginsOrientation.TOP] = top;
this.value_[print_preview.CustomMarginsOrientation.RIGHT] = right;
this.value_[print_preview.CustomMarginsOrientation.BOTTOM] = bottom;
this.value_[print_preview.CustomMarginsOrientation.LEFT] = left;
}
/**
......@@ -83,15 +79,14 @@ cr.define('print_preview', function() {
*/
static parse(state) {
return new print_preview.Margins(
state[print_preview.ticket_items.CustomMarginsOrientation.TOP] || 0,
state[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] || 0,
state[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] ||
0,
state[print_preview.ticket_items.CustomMarginsOrientation.LEFT] || 0);
state[print_preview.CustomMarginsOrientation.TOP] || 0,
state[print_preview.CustomMarginsOrientation.RIGHT] || 0,
state[print_preview.CustomMarginsOrientation.BOTTOM] || 0,
state[print_preview.CustomMarginsOrientation.LEFT] || 0);
}
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation}
* @param {!print_preview.CustomMarginsOrientation}
* orientation Specifies the margin value to get.
* @return {number} Value of the margin of the given orientation.
*/
......@@ -100,7 +95,7 @@ cr.define('print_preview', function() {
}
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation}
* @param {!print_preview.CustomMarginsOrientation}
* orientation Specifies the margin to set.
* @param {number} value Updated value of the margin in points to modify.
* @return {!print_preview.Margins} A new copy of |this| with the
......@@ -110,10 +105,10 @@ cr.define('print_preview', function() {
const newValue = this.clone_();
newValue[orientation] = value;
return new Margins(
newValue[print_preview.ticket_items.CustomMarginsOrientation.TOP],
newValue[print_preview.ticket_items.CustomMarginsOrientation.RIGHT],
newValue[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM],
newValue[print_preview.ticket_items.CustomMarginsOrientation.LEFT]);
newValue[print_preview.CustomMarginsOrientation.TOP],
newValue[print_preview.CustomMarginsOrientation.RIGHT],
newValue[print_preview.CustomMarginsOrientation.BOTTOM],
newValue[print_preview.CustomMarginsOrientation.LEFT]);
}
/**
......
......@@ -60,7 +60,7 @@ cr.define('print_preview', function() {
* width_microns: number,
* custom_display_name: (string | undefined),
* is_default: (boolean | undefined)} | undefined),
* marginsType: (print_preview.ticket_items.MarginsTypeValue | undefined),
* marginsType: (print_preview.MarginsTypeValue | undefined),
* customMargins: (print_preview.MarginsSetting | undefined),
* isColorEnabled: (boolean | undefined),
* isDuplexEnabled: (boolean | undefined),
......@@ -262,9 +262,8 @@ Polymer({
updatesPreview: true,
},
margins: {
value: print_preview.ticket_items.MarginsTypeValue.DEFAULT,
unavailableValue:
print_preview.ticket_items.MarginsTypeValue.DEFAULT,
value: print_preview.MarginsTypeValue.DEFAULT,
unavailableValue: print_preview.MarginsTypeValue.DEFAULT,
valid: true,
available: true,
setByPolicy: false,
......@@ -791,22 +790,20 @@ Polymer({
// Otherwise, availability depends on the margins.
let available = false;
const marginsType =
/** @type {!print_preview.ticket_items.MarginsTypeValue} */ (
/** @type {!print_preview.MarginsTypeValue} */ (
this.getSettingValue('margins'));
switch (marginsType) {
case print_preview.ticket_items.MarginsTypeValue.DEFAULT:
case print_preview.MarginsTypeValue.DEFAULT:
available = !this.margins ||
this.margins.get(
print_preview.ticket_items.CustomMarginsOrientation.TOP) > 0 ||
this.margins.get(
print_preview.ticket_items.CustomMarginsOrientation.BOTTOM) > 0;
this.margins.get(print_preview.CustomMarginsOrientation.TOP) > 0 ||
this.margins.get(print_preview.CustomMarginsOrientation.BOTTOM) > 0;
break;
case print_preview.ticket_items.MarginsTypeValue.NO_MARGINS:
case print_preview.MarginsTypeValue.NO_MARGINS:
break;
case print_preview.ticket_items.MarginsTypeValue.MINIMUM:
case print_preview.MarginsTypeValue.MINIMUM:
available = true;
break;
case print_preview.ticket_items.MarginsTypeValue.CUSTOM:
case print_preview.MarginsTypeValue.CUSTOM:
const margins = this.getSettingValue('customMargins');
available = margins.marginTop > 0 || margins.marginBottom > 0;
break;
......@@ -1240,7 +1237,7 @@ Polymer({
}
if (this.getSettingValue('margins') ==
print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
print_preview.MarginsTypeValue.CUSTOM) {
ticket.marginsCustom = this.getSettingValue('customMargins');
}
......
......@@ -138,7 +138,7 @@ Polymer({
*/
convertPixelsToPts: function(pixels) {
let pts;
const Orientation = print_preview.ticket_items.CustomMarginsOrientation;
const Orientation = print_preview.CustomMarginsOrientation;
if (this.side == Orientation.TOP) {
pts = pixels - this.translateTransform.y + RADIUS_PX;
pts /= this.scaleTransform;
......@@ -253,7 +253,7 @@ Polymer({
return;
}
const Orientation = print_preview.ticket_items.CustomMarginsOrientation;
const Orientation = print_preview.CustomMarginsOrientation;
let x = this.translateTransform.x;
let y = this.translateTransform.y;
let width = null;
......
......@@ -7,15 +7,13 @@ cr.define('print_preview', function() {
'use strict';
/**
* @const {!Map<!print_preview.ticket_items.CustomMarginsOrientation, string>}
* @const {!Map<!print_preview.CustomMarginsOrientation, string>}
*/
const MARGIN_KEY_MAP = new Map([
[print_preview.ticket_items.CustomMarginsOrientation.TOP, 'marginTop'],
[print_preview.ticket_items.CustomMarginsOrientation.RIGHT, 'marginRight'],
[
print_preview.ticket_items.CustomMarginsOrientation.BOTTOM, 'marginBottom'
],
[print_preview.ticket_items.CustomMarginsOrientation.LEFT, 'marginLeft']
[print_preview.CustomMarginsOrientation.TOP, 'marginTop'],
[print_preview.CustomMarginsOrientation.RIGHT, 'marginRight'],
[print_preview.CustomMarginsOrientation.BOTTOM, 'marginBottom'],
[print_preview.CustomMarginsOrientation.LEFT, 'marginLeft']
]);
/** @const {number} */
......@@ -87,16 +85,16 @@ cr.define('print_preview', function() {
},
/**
* @private {!Array<!print_preview.ticket_items.CustomMarginsOrientation>}
* @private {!Array<!print_preview.CustomMarginsOrientation>}
*/
marginSides_: {
type: Array,
notify: true,
value: [
print_preview.ticket_items.CustomMarginsOrientation.TOP,
print_preview.ticket_items.CustomMarginsOrientation.RIGHT,
print_preview.ticket_items.CustomMarginsOrientation.BOTTOM,
print_preview.ticket_items.CustomMarginsOrientation.LEFT,
print_preview.CustomMarginsOrientation.TOP,
print_preview.CustomMarginsOrientation.RIGHT,
print_preview.CustomMarginsOrientation.BOTTOM,
print_preview.CustomMarginsOrientation.LEFT,
],
},
......@@ -139,7 +137,7 @@ cr.define('print_preview', function() {
computeAvailable_: function() {
return this.previewLoaded && !!this.clipSize_ &&
this.getSettingValue('margins') ==
print_preview.ticket_items.MarginsTypeValue.CUSTOM &&
print_preview.MarginsTypeValue.CUSTOM &&
!!this.pageSize;
},
......@@ -150,7 +148,7 @@ cr.define('print_preview', function() {
// custom margins were reset.
const newMargins = {};
for (const side of Object.values(
print_preview.ticket_items.CustomMarginsOrientation)) {
print_preview.CustomMarginsOrientation)) {
const key = print_preview.MARGIN_KEY_MAP.get(side);
newMargins[key] = this.documentMargins.get(side);
}
......@@ -187,11 +185,9 @@ cr.define('print_preview', function() {
this.resetMargins_ = true;
const marginsSetting = this.getSetting('margins');
if (marginsSetting.value ==
print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
if (marginsSetting.value == print_preview.MarginsTypeValue.CUSTOM) {
// Set the margins value to default first.
this.setSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.DEFAULT);
this.setSetting('margins', print_preview.MarginsTypeValue.DEFAULT);
}
// Reset custom margins so that the sticky value is not restored for the
// new paper size.
......@@ -218,16 +214,14 @@ cr.define('print_preview', function() {
},
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation} orientation
* @param {!print_preview.CustomMarginsOrientation} orientation
* Orientation value to test.
* @return {boolean} Whether the given orientation is TOP or BOTTOM.
* @private
*/
isTopOrBottom_: function(orientation) {
return orientation ==
print_preview.ticket_items.CustomMarginsOrientation.TOP ||
orientation ==
print_preview.ticket_items.CustomMarginsOrientation.BOTTOM;
return orientation == print_preview.CustomMarginsOrientation.TOP ||
orientation == print_preview.CustomMarginsOrientation.BOTTOM;
},
/**
......@@ -241,8 +235,7 @@ cr.define('print_preview', function() {
*/
posInPixelsToPts_: function(control, posInPixels) {
const side =
/** @type {print_preview.ticket_items.CustomMarginsOrientation} */ (
control.side);
/** @type {print_preview.CustomMarginsOrientation} */ (control.side);
return this.clipAndRoundValue_(
side,
control.convertPixelsToPts(
......@@ -349,7 +342,7 @@ cr.define('print_preview', function() {
const x = control.offsetLeft;
const y = control.offsetTop;
const isTopOrBottom = this.isTopOrBottom_(
/** @type {!print_preview.ticket_items.CustomMarginsOrientation} */ (
/** @type {!print_preview.CustomMarginsOrientation} */ (
control.side));
const position = {};
// Extra padding, in px, to ensure the full textbox will be visible and
......@@ -395,8 +388,7 @@ cr.define('print_preview', function() {
*/
setMargin_: function(side, marginValue) {
const marginSide =
/** @type {!print_preview.ticket_items.CustomMarginsOrientation} */ (
side);
/** @type {!print_preview.CustomMarginsOrientation} */ (side);
const oldMargins = /** @type {print_preview.MarginsSetting} */ (
this.getSettingValue('customMargins'));
const key = print_preview.MARGIN_KEY_MAP.get(marginSide);
......@@ -416,12 +408,11 @@ cr.define('print_preview', function() {
*/
clipAndRoundValue_: function(side, value) {
const marginSide =
/** @type {!print_preview.ticket_items.CustomMarginsOrientation} */ (
side);
/** @type {!print_preview.CustomMarginsOrientation} */ (side);
if (value < 0) {
return 0;
}
const Orientation = print_preview.ticket_items.CustomMarginsOrientation;
const Orientation = print_preview.CustomMarginsOrientation;
let limit = 0;
const margins = this.getSettingValue('customMargins');
if (marginSide == Orientation.TOP) {
......@@ -482,10 +473,9 @@ cr.define('print_preview', function() {
new print_preview.Coordinate2d(e.x, e.y);
this.marginStartPositionInPixels_ =
new print_preview.Coordinate2d(control.offsetLeft, control.offsetTop);
this.dragging_ =
this.isTopOrBottom_(
/** @type {print_preview.ticket_items.CustomMarginsOrientation} */
(control.side)) ?
this.dragging_ = this.isTopOrBottom_(
/** @type {print_preview.CustomMarginsOrientation} */
(control.side)) ?
'dragging-vertical' :
'dragging-horizontal';
this.listen(control, 'pointercancel', 'onPointerUp_');
......
......@@ -19,8 +19,7 @@
settings.pagesPerSheet.value)]]"
value="{{selectedValue::change}}">
<!-- The order of these options must match the natural order of their
values, which come from
print_preview.ticket_items.MarginsTypeValue. -->
values, which come from print_preview.MarginsTypeValue. -->
<option value="[[MarginsValue.DEFAULT]]" selected>
$i18n{defaultMargins}
</option>
......
......@@ -18,7 +18,7 @@ Polymer({
/** @override */
ready: function() {
this.MarginsValue = print_preview.ticket_items.MarginsTypeValue;
this.MarginsValue = print_preview.MarginsTypeValue;
},
/**
......@@ -27,8 +27,7 @@ Polymer({
*/
onMarginsSettingChange_: function(newValue) {
this.selectedValue =
/** @type {!print_preview.ticket_items.MarginsTypeValue} */ (newValue)
.toString();
/** @type {!print_preview.MarginsTypeValue} */ (newValue).toString();
},
/** @param {string} value The new select value. */
......
......@@ -19,8 +19,7 @@ Polymer({
*/
onPagesPerSheetSettingChange_: function(newValue) {
this.selectedValue = /** @type {number} */ (newValue).toString();
this.setSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.DEFAULT);
this.setSetting('margins', print_preview.MarginsTypeValue.DEFAULT);
},
/** @param {string} value The new select value. */
......
......@@ -529,13 +529,12 @@ Polymer({
*/
marginsValid_: function() {
const type = this.getSettingValue('margins');
if (!Object.values(print_preview.ticket_items.MarginsTypeValue)
.includes(type)) {
if (!Object.values(print_preview.MarginsTypeValue).includes(type)) {
// Unrecognized margins type.
return false;
}
if (type !== print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
if (type !== print_preview.MarginsTypeValue.CUSTOM) {
return true;
}
......@@ -567,11 +566,11 @@ Polymer({
// Margins
const newMarginsType = this.getSettingValue('margins');
if (newMarginsType !== lastTicket.marginsType &&
newMarginsType !== print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
newMarginsType !== print_preview.MarginsTypeValue.CUSTOM) {
return true;
}
if (newMarginsType === print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
if (newMarginsType === print_preview.MarginsTypeValue.CUSTOM) {
const customMargins =
/** @type {!print_preview.MarginsSetting} */ (
this.getSettingValue('customMargins'));
......@@ -595,11 +594,10 @@ Polymer({
}
const customMarginsChanged =
Object.values(print_preview.ticket_items.CustomMarginsOrientation)
.some(side => {
return this.margins.get(side) !==
customMargins[print_preview.MARGIN_KEY_MAP.get(side)];
});
Object.values(print_preview.CustomMarginsOrientation).some(side => {
return this.margins.get(side) !==
customMargins[print_preview.MARGIN_KEY_MAP.get(side)];
});
if (customMarginsChanged) {
return true;
}
......@@ -629,7 +627,7 @@ Polymer({
// default margins to trigger a request.
if (this.getSettingValue('pagesPerSheet') !== lastTicket.pagesPerSheet &&
this.getSettingValue('margins') ===
print_preview.ticket_items.MarginsTypeValue.DEFAULT) {
print_preview.MarginsTypeValue.DEFAULT) {
return true;
}
......@@ -641,7 +639,7 @@ Polymer({
newValue.width_microns != lastTicket.mediaSize.width_microns ||
(this.destination.id !== lastTicket.deviceName &&
this.getSettingValue('margins') ===
print_preview.ticket_items.MarginsTypeValue.MINIMUM)) {
print_preview.MarginsTypeValue.MINIMUM)) {
return true;
}
......@@ -734,7 +732,7 @@ Polymer({
}
if (this.getSettingValue('margins') ==
print_preview.ticket_items.MarginsTypeValue.CUSTOM) {
print_preview.MarginsTypeValue.CUSTOM) {
ticket.marginsCustom = this.getSettingValue('customMargins');
}
this.lastTicket_ = ticket;
......
......@@ -28,7 +28,7 @@ cr.define('custom_margins_test', function() {
/** @type {?PrintPreviewModelElement} */
let model = null;
/** @type {!Array<!print_preview.ticket_items.CustomMarginsOrientation>} */
/** @type {!Array<!print_preview.CustomMarginsOrientation>} */
let sides = [];
/** @type {!print_preview.MeasurementSystem} */
......@@ -56,10 +56,10 @@ cr.define('custom_margins_test', function() {
model.set('settings.mediaSize.available', true);
sides = [
print_preview.ticket_items.CustomMarginsOrientation.TOP,
print_preview.ticket_items.CustomMarginsOrientation.RIGHT,
print_preview.ticket_items.CustomMarginsOrientation.BOTTOM,
print_preview.ticket_items.CustomMarginsOrientation.LEFT
print_preview.CustomMarginsOrientation.TOP,
print_preview.CustomMarginsOrientation.RIGHT,
print_preview.CustomMarginsOrientation.BOTTOM,
print_preview.CustomMarginsOrientation.LEFT
];
container =
......@@ -131,19 +131,19 @@ cr.define('custom_margins_test', function() {
let xEnd = 0;
let yEnd = 0;
switch (control.side) {
case print_preview.ticket_items.CustomMarginsOrientation.TOP:
case print_preview.CustomMarginsOrientation.TOP:
yStart = start;
yEnd = end;
break;
case print_preview.ticket_items.CustomMarginsOrientation.RIGHT:
case print_preview.CustomMarginsOrientation.RIGHT:
xStart = control.clipSize.width - start;
xEnd = control.clipSize.width - end;
break;
case print_preview.ticket_items.CustomMarginsOrientation.BOTTOM:
case print_preview.CustomMarginsOrientation.BOTTOM:
yStart = control.clipSize.height - start;
yEnd = control.clipSize.height - end;
break;
case print_preview.ticket_items.CustomMarginsOrientation.LEFT:
case print_preview.CustomMarginsOrientation.LEFT:
xStart = start;
xEnd = end;
break;
......@@ -202,12 +202,11 @@ cr.define('custom_margins_test', function() {
/*
* Initializes the settings custom margins to some test values, and returns
* a map with the values.
* @return {!Map<!print_preview.ticket_items.CustomMarginsOrientation,
* @return {!Map<!print_preview.CustomMarginsOrientation,
* number>}
*/
function setupCustomMargins() {
const orientationEnum =
print_preview.ticket_items.CustomMarginsOrientation;
const orientationEnum = print_preview.CustomMarginsOrientation;
const marginValues = new Map([
[orientationEnum.TOP, 72], [orientationEnum.RIGHT, 36],
[orientationEnum.BOTTOM, 108], [orientationEnum.LEFT, 18]
......@@ -233,8 +232,7 @@ cr.define('custom_margins_test', function() {
return finishSetup().then(() => {
// Simulate setting custom margins.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
// Validate control positions are set based on the custom values.
const controls = getControls();
......@@ -251,7 +249,7 @@ cr.define('custom_margins_test', function() {
// Margins should be reset to default and custom margins values should
// be cleared.
expectEquals(
print_preview.ticket_items.MarginsTypeValue.DEFAULT,
print_preview.MarginsTypeValue.DEFAULT,
container.getSettingValue('margins'));
expectEquals(
'{}', JSON.stringify(container.getSettingValue('customMargins')));
......@@ -282,7 +280,7 @@ cr.define('custom_margins_test', function() {
// Controls become visible when margin type CUSTOM is selected.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
print_preview.MarginsTypeValue.CUSTOM);
// Wait for the opacity transitions to finish.
return onTransitionEnd;
......@@ -339,8 +337,7 @@ cr.define('custom_margins_test', function() {
// Simulate setting custom margins from sticky settings.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
const marginValues = setupCustomMargins();
model.notifyPath('settings.customMargins.value');
Polymer.dom.flush();
......@@ -386,8 +383,7 @@ cr.define('custom_margins_test', function() {
return finishSetup().then(() => {
const controls = getControls();
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
Polymer.dom.flush();
......@@ -446,8 +442,7 @@ cr.define('custom_margins_test', function() {
c.getInput().setAttribute('data-timeout-delay', 1);
});
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
Polymer.dom.flush();
// Verify entering a new value updates the settings.
......@@ -493,8 +488,7 @@ cr.define('custom_margins_test', function() {
c.getInput().setAttribute('data-timeout-delay', 1);
});
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
Polymer.dom.flush();
// Verify entering a new value updates the settings.
......@@ -545,8 +539,7 @@ cr.define('custom_margins_test', function() {
// Simulate setting custom margins.
const controls = getControls();
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
// Validate control positions are set based on the custom values.
controls.forEach((control, index) => {
......@@ -557,8 +550,7 @@ cr.define('custom_margins_test', function() {
// Simulate setting minimum margins.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.MINIMUM);
'settings.margins.value', print_preview.MarginsTypeValue.MINIMUM);
// Validate control positions still reflect the custom values.
controls.forEach((control, index) => {
......@@ -577,7 +569,7 @@ cr.define('custom_margins_test', function() {
// Simulate setting custom margins again.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
print_preview.MarginsTypeValue.CUSTOM);
// Validate control positions are initialized based on the default
// values.
......@@ -595,8 +587,7 @@ cr.define('custom_margins_test', function() {
return validateMarginsClearedForSetting('layout', true).then(() => {
// Simulate setting custom margins again
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
// Validate control positions are initialized based on the default
// values.
......@@ -647,7 +638,7 @@ cr.define('custom_margins_test', function() {
// Controls become visible when margin type CUSTOM is selected.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
print_preview.MarginsTypeValue.CUSTOM);
container.notifyPath('settings.customMargins.value');
Polymer.dom.flush();
return onTransitionEnd;
......@@ -693,8 +684,7 @@ cr.define('custom_margins_test', function() {
return finishSetup().then(() => {
// Simulate setting custom margins.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
const controls = getControls();
controls.forEach(control => assertFalse(control.disabled));
......
......@@ -19,7 +19,7 @@ cr.define('margins_settings_test', function() {
marginsSection.settings = model.settings;
marginsSection.disabled = false;
test_util.fakeDataBind(model, marginsSection, 'settings');
marginsTypeEnum = print_preview.ticket_items.MarginsTypeValue;
marginsTypeEnum = print_preview.MarginsTypeValue;
});
// Tests that setting the setting updates the UI.
......
......@@ -376,14 +376,12 @@ cr.define('model_settings_availability_test', function() {
// Set margins to NONE
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
'settings.margins.value', print_preview.MarginsTypeValue.NO_MARGINS);
assertFalse(model.settings.headerFooter.available);
// Custom margins of 0.
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.CUSTOM);
'settings.margins.value', print_preview.MarginsTypeValue.CUSTOM);
model.set(
'settings.customMargins.value',
{marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
......@@ -429,8 +427,7 @@ cr.define('model_settings_availability_test', function() {
};
model.set('destination.capabilities', capabilities);
model.set(
'settings.margins.value',
print_preview.ticket_items.MarginsTypeValue.DEFAULT);
'settings.margins.value', print_preview.MarginsTypeValue.DEFAULT);
// Header/footer should be available for default big label with
// default margins.
......
......@@ -188,7 +188,7 @@ cr.define('model_test', function() {
layout: true,
color: false,
mediaSize: testDestination.capabilities.printer.media_size.option[1],
margins: print_preview.ticket_items.MarginsTypeValue.CUSTOM,
margins: print_preview.MarginsTypeValue.CUSTOM,
customMargins: {
marginTop: 100,
marginRight: 200,
......@@ -278,7 +278,7 @@ cr.define('model_test', function() {
landscape: false,
color: testDestination.getNativeColorModel(true),
headerFooterEnabled: false, // Only used in print preview
marginsType: print_preview.ticket_items.MarginsTypeValue.DEFAULT,
marginsType: print_preview.MarginsTypeValue.DEFAULT,
duplex: print_preview.DuplexMode.SIMPLEX,
copies: 1,
collate: true,
......@@ -319,7 +319,7 @@ cr.define('model_test', function() {
landscape: true,
color: testDestination.getNativeColorModel(false),
headerFooterEnabled: false,
marginsType: print_preview.ticket_items.MarginsTypeValue.CUSTOM,
marginsType: print_preview.MarginsTypeValue.CUSTOM,
duplex: print_preview.DuplexMode.SHORT_EDGE,
copies: 2,
collate: false,
......
......@@ -34,14 +34,14 @@ cr.define('pages_per_sheet_settings_test', function() {
// Tests that setting the pages per sheet setting resets margins to DEFAULT.
test('resets margins setting', async () => {
pagesPerSheetSection.setSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
'margins', print_preview.MarginsTypeValue.NO_MARGINS);
assertEquals(1, pagesPerSheetSection.getSettingValue('pagesPerSheet'));
pagesPerSheetSection.setSetting('pagesPerSheet', 4);
await test_util.eventToPromise(
'process-select-change', pagesPerSheetSection);
assertEquals(4, pagesPerSheetSection.getSettingValue('pagesPerSheet'));
assertEquals(
print_preview.ticket_items.MarginsTypeValue.DEFAULT,
print_preview.MarginsTypeValue.DEFAULT,
pagesPerSheetSection.getSettingValue('margins'));
});
......
......@@ -151,10 +151,10 @@ cr.define('preview_generation_test', function() {
/** Validate changing the margins updates the preview. */
test(assert(TestNames.Margins), function() {
return testSimpleSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.DEFAULT,
print_preview.ticket_items.MarginsTypeValue.MINIMUM, 'marginsType',
print_preview.ticket_items.MarginsTypeValue.DEFAULT,
print_preview.ticket_items.MarginsTypeValue.MINIMUM);
'margins', print_preview.MarginsTypeValue.DEFAULT,
print_preview.MarginsTypeValue.MINIMUM, 'marginsType',
print_preview.MarginsTypeValue.DEFAULT,
print_preview.MarginsTypeValue.MINIMUM);
});
/**
......@@ -166,15 +166,14 @@ cr.define('preview_generation_test', function() {
.then(function(args) {
const originalTicket = JSON.parse(args.printTicket);
assertEquals(
print_preview.ticket_items.MarginsTypeValue.DEFAULT,
print_preview.MarginsTypeValue.DEFAULT,
originalTicket.marginsType);
// Custom margins should not be set in the ticket.
assertEquals(undefined, originalTicket.marginsCustom);
assertEquals(0, originalTicket.requestID);
// This should do nothing.
page.setSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.CUSTOM);
page.setSetting('margins', print_preview.MarginsTypeValue.CUSTOM);
// Sets only 1 side, not valid.
page.setSetting('customMargins', {marginTop: 25});
// 2 sides, still not valid.
......@@ -192,19 +191,16 @@ cr.define('preview_generation_test', function() {
.then(function(args) {
const ticket = JSON.parse(args.printTicket);
assertEquals(
print_preview.ticket_items.MarginsTypeValue.CUSTOM,
ticket.marginsType);
print_preview.MarginsTypeValue.CUSTOM, ticket.marginsType);
assertEquals(25, ticket.marginsCustom.marginTop);
assertEquals(40, ticket.marginsCustom.marginRight);
assertEquals(20, ticket.marginsCustom.marginBottom);
assertEquals(50, ticket.marginsCustom.marginLeft);
assertEquals(1, ticket.requestID);
page.setSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.DEFAULT);
page.setSetting('margins', print_preview.MarginsTypeValue.DEFAULT);
// Set setting to something invalid and then set margins to CUSTOM.
page.setSetting('customMargins', {marginTop: 25, marginRight: 40});
page.setSetting(
'margins', print_preview.ticket_items.MarginsTypeValue.CUSTOM);
page.setSetting('margins', print_preview.MarginsTypeValue.CUSTOM);
nativeLayer.resetResolver('getPreview');
page.setSetting('customMargins', {
marginTop: 25,
......@@ -217,8 +213,7 @@ cr.define('preview_generation_test', function() {
.then(function(args) {
const ticket = JSON.parse(args.printTicket);
assertEquals(
print_preview.ticket_items.MarginsTypeValue.CUSTOM,
ticket.marginsType);
print_preview.MarginsTypeValue.CUSTOM, ticket.marginsType);
assertEquals(25, ticket.marginsCustom.marginTop);
assertEquals(40, ticket.marginsCustom.marginRight);
assertEquals(20, ticket.marginsCustom.marginBottom);
......@@ -232,10 +227,10 @@ cr.define('preview_generation_test', function() {
/**
* Validate changing the pages per sheet updates the preview, and resets
* margins to print_preview.ticket_items.MarginsTypeValue.DEFAULT.
* margins to print_preview.MarginsTypeValue.DEFAULT.
*/
test(assert(TestNames.ChangeMarginsByPagesPerSheet), function() {
const MarginsTypeEnum = print_preview.ticket_items.MarginsTypeValue;
const MarginsTypeEnum = print_preview.MarginsTypeValue;
return initialize()
.then(function(args) {
const originalTicket = JSON.parse(args.printTicket);
......@@ -471,7 +466,7 @@ cr.define('preview_generation_test', function() {
/**
* @param {Object} ticket The parsed print ticket
* @param {number} expectedId The expected ticket request ID
* @param {!print_preview.ticket_items.MarginsTypeValue} expectedMargins
* @param {!print_preview.MarginsTypeValue} expectedMargins
* The expected ticket margins type
* @param {boolean} expectedHeaderFooter The expected ticket
* header/footer value
......@@ -496,7 +491,7 @@ cr.define('preview_generation_test', function() {
printableAreaHeight: 792,
});
const MarginsTypeEnum = print_preview.ticket_items.MarginsTypeValue;
const MarginsTypeEnum = print_preview.MarginsTypeValue;
let previewArgs = await initialize();
let ticket = JSON.parse(previewArgs.printTicket);
......
......@@ -219,7 +219,7 @@ cr.define('restore_state_test', function() {
section: 'print-preview-margins-settings',
settingName: 'margins',
key: 'marginsType',
value: print_preview.ticket_items.MarginsTypeValue.MINIMUM,
value: print_preview.MarginsTypeValue.MINIMUM,
},
{
section: 'print-preview-dpi-settings',
......
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