Commit 5a87d3d9 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Closure compile more tests, part 2

Closure compiling:
- copies_settings_test
- color_settings_test
- custom_margins_test

Bug: 1000989
Change-Id: I4e9d9068d1f5d63d5a618bcc9980f52358fd1ce5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223265
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774015}
parent 697e49e5
...@@ -44,6 +44,7 @@ export let Setting; ...@@ -44,6 +44,7 @@ export let Setting;
* collate: !Setting, * collate: !Setting,
* layout: !Setting, * layout: !Setting,
* color: !Setting, * color: !Setting,
* customMargins: !Setting,
* mediaSize: !Setting, * mediaSize: !Setting,
* margins: !Setting, * margins: !Setting,
* dpi: !Setting, * dpi: !Setting,
......
...@@ -14,7 +14,7 @@ export {ColorModeRestriction, DuplexModeRestriction, PinModeRestriction} from '. ...@@ -14,7 +14,7 @@ export {ColorModeRestriction, DuplexModeRestriction, PinModeRestriction} from '.
export {DestinationErrorType, DestinationStore} from './data/destination_store.js'; export {DestinationErrorType, DestinationStore} from './data/destination_store.js';
export {PageLayoutInfo} from './data/document_info.js'; export {PageLayoutInfo} from './data/document_info.js';
export {InvitationStore} from './data/invitation_store.js'; export {InvitationStore} from './data/invitation_store.js';
export {CustomMarginsOrientation, Margins, MarginsType} from './data/margins.js'; export {CustomMarginsOrientation, Margins, MarginsSetting, MarginsType} from './data/margins.js';
export {MeasurementSystem, MeasurementSystemUnitType} from './data/measurement_system.js'; export {MeasurementSystem, MeasurementSystemUnitType} from './data/measurement_system.js';
export {DuplexMode, DuplexType, getInstance, whenReady} from './data/model.js'; export {DuplexMode, DuplexType, getInstance, whenReady} from './data/model.js';
export {ScalingType} from './data/scaling.js'; export {ScalingType} from './data/scaling.js';
......
...@@ -19,10 +19,10 @@ js_type_check("closure_compile") { ...@@ -19,10 +19,10 @@ js_type_check("closure_compile") {
":button_strip_interactive_test", ":button_strip_interactive_test",
":button_strip_test", ":button_strip_test",
":cloud_print_interface_stub", ":cloud_print_interface_stub",
":color_settings_test",
":copies_settings_test",
":custom_margins_test",
#":color_settings_test",
#":copies_settings_test",
#":custom_margins_test",
#":destination_dialog_interactive_test", #":destination_dialog_interactive_test",
#":destination_dialog_test", #":destination_dialog_test",
#":destination_item_test", #":destination_item_test",
...@@ -120,6 +120,38 @@ js_library("button_strip_interactive_test") { ...@@ -120,6 +120,38 @@ js_library("button_strip_interactive_test") {
externs_list = [ "$externs_path/mocha-2.5.js" ] externs_list = [ "$externs_path/mocha-2.5.js" ]
} }
js_library("color_settings_test") {
deps = [
":print_preview_test_utils",
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("copies_settings_test") {
deps = [
":print_preview_test_utils",
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("custom_margins_test") {
deps = [
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("print_preview_test_utils") { js_library("print_preview_test_utils") {
deps = [ deps = [
"..:test_util.m", "..:test_util.m",
......
...@@ -6,23 +6,28 @@ import 'chrome://print/print_preview.js'; ...@@ -6,23 +6,28 @@ import 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {isChromeOS} from 'chrome://resources/js/cr.m.js'; import {isChromeOS} from 'chrome://resources/js/cr.m.js';
import {selectOption} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {eventToPromise, fakeDataBind} from 'chrome://test/test_util.m.js'; import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {eventToPromise, fakeDataBind} from '../test_util.m.js';
import {selectOption} from './print_preview_test_utils.js';
suite('ColorSettingsTest', function() { suite('ColorSettingsTest', function() {
/** @type {?PrintPreviewColorSettingsElement} */ /** @type {!PrintPreviewColorSettingsElement} */
let colorSection = null; let colorSection;
/** @type {?PrintPreviewModelElement} */ /** @type {!PrintPreviewModelElement} */
let model = null; let model;
/** @override */ /** @override */
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
model = document.createElement('print-preview-model'); model = /** @type {!PrintPreviewModelElement} */ (
document.createElement('print-preview-model'));
document.body.appendChild(model); document.body.appendChild(model);
colorSection = document.createElement('print-preview-color-settings'); colorSection = /** @type {!PrintPreviewColorSettingsElement} */ (
document.createElement('print-preview-color-settings'));
colorSection.settings = model.settings; colorSection.settings = model.settings;
colorSection.disabled = false; colorSection.disabled = false;
fakeDataBind(model, colorSection, 'settings'); fakeDataBind(model, colorSection, 'settings');
...@@ -45,13 +50,13 @@ suite('ColorSettingsTest', function() { ...@@ -45,13 +50,13 @@ suite('ColorSettingsTest', function() {
// Verify that the selected option and names are as expected. // Verify that the selected option and names are as expected.
const select = colorSection.$$('select'); const select = colorSection.$$('select');
assertEquals('color', select.value); assertEquals('color', select.value);
assertTrue(colorSection.getSettingValue('color')); assertTrue(/** @type {boolean} */ (colorSection.getSettingValue('color')));
assertFalse(colorSection.getSetting('color').setFromUi); assertFalse(colorSection.getSetting('color').setFromUi);
assertEquals(2, select.options.length); assertEquals(2, select.options.length);
// Verify that selecting an new option in the dropdown sets the setting. // Verify that selecting an new option in the dropdown sets the setting.
await selectOption(colorSection, 'bw'); await selectOption(colorSection, 'bw');
assertFalse(colorSection.getSettingValue('color')); assertFalse(/** @type {boolean} */ (colorSection.getSettingValue('color')));
assertTrue(colorSection.getSetting('color').setFromUi); assertTrue(colorSection.getSetting('color').setFromUi);
}); });
......
...@@ -3,26 +3,30 @@ ...@@ -3,26 +3,30 @@
// found in the LICENSE file. // found in the LICENSE file.
import {DEFAULT_MAX_COPIES} from 'chrome://print/print_preview.js'; import {DEFAULT_MAX_COPIES} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {triggerInputEvent} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {fakeDataBind} from 'chrome://test/test_util.m.js'; import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {fakeDataBind} from '../test_util.m.js';
import {triggerInputEvent} from './print_preview_test_utils.js';
suite('CopiesSettingsTest', function() { suite('CopiesSettingsTest', function() {
/** @type {?PrintPreviewCopiesSettingsElement} */ /** @type {!PrintPreviewCopiesSettingsElement} */
let copiesSection = null; let copiesSection;
/** @type {?PrintPreviewModelElement} */ /** @type {!PrintPreviewModelElement} */
let model = null; let model;
/** @override */ /** @override */
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
model = document.createElement('print-preview-model'); model = /** @type {!PrintPreviewModelElement} */ (
document.createElement('print-preview-model'));
document.body.appendChild(model); document.body.appendChild(model);
model.set('settings.collate.available', true); model.set('settings.collate.available', true);
copiesSection = document.createElement('print-preview-copies-settings'); copiesSection = /** @type {!PrintPreviewCopiesSettingsElement} */ (
document.createElement('print-preview-copies-settings'));
copiesSection.settings = model.settings; copiesSection.settings = model.settings;
copiesSection.disabled = false; copiesSection.disabled = false;
fakeDataBind(model, copiesSection, 'settings'); fakeDataBind(model, copiesSection, 'settings');
...@@ -31,7 +35,7 @@ suite('CopiesSettingsTest', function() { ...@@ -31,7 +35,7 @@ suite('CopiesSettingsTest', function() {
/** /**
* Confirms that |max| is currently set as copiesSection's maxCopies. * Confirms that |max| is currently set as copiesSection's maxCopies.
* @param {number} Expected maximum copies value to check. * @param {number} max Expected maximum copies value to check.
*/ */
async function checkCopiesMax(max) { async function checkCopiesMax(max) {
const input = const input =
...@@ -58,9 +62,6 @@ suite('CopiesSettingsTest', function() { ...@@ -58,9 +62,6 @@ suite('CopiesSettingsTest', function() {
await checkCopiesMax(1234); await checkCopiesMax(1234);
// Missing and empty capabilities should choose default max copies. // Missing and empty capabilities should choose default max copies.
copiesSection.capability = null;
await checkCopiesMax(DEFAULT_MAX_COPIES);
copiesSection.capability = {}; copiesSection.capability = {};
await checkCopiesMax(DEFAULT_MAX_COPIES); await checkCopiesMax(DEFAULT_MAX_COPIES);
}); });
...@@ -127,7 +128,8 @@ suite('CopiesSettingsTest', function() { ...@@ -127,7 +128,8 @@ suite('CopiesSettingsTest', function() {
collateCheckbox.click(); collateCheckbox.click();
assertFalse(collateCheckbox.checked); assertFalse(collateCheckbox.checked);
collateCheckbox.dispatchEvent(new CustomEvent('change')); collateCheckbox.dispatchEvent(new CustomEvent('change'));
assertFalse(copiesSection.getSettingValue('collate')); assertFalse(
/** @type {boolean} */ (copiesSection.getSettingValue('collate')));
assertTrue(copiesSection.getSetting('collate').setFromUi); assertTrue(copiesSection.getSetting('collate').setFromUi);
}); });
......
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {CustomMarginsOrientation, Margins, MarginsType, MeasurementSystem, MeasurementSystemUnitType, Size, State} from 'chrome://print/print_preview.js'; import {CustomMarginsOrientation, Margins, MarginsSetting, MarginsType, MeasurementSystem, MeasurementSystemUnitType, Size, State} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {eventToPromise, fakeDataBind} from 'chrome://test/test_util.m.js';
import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {eventToPromise, fakeDataBind} from '../test_util.m.js';
window.custom_margins_test = {}; window.custom_margins_test = {};
const custom_margins_test = window.custom_margins_test;
custom_margins_test.suiteName = 'CustomMarginsTest'; custom_margins_test.suiteName = 'CustomMarginsTest';
/** @enum {string} */ /** @enum {string} */
custom_margins_test.TestNames = { custom_margins_test.TestNames = {
...@@ -26,17 +29,17 @@ custom_margins_test.TestNames = { ...@@ -26,17 +29,17 @@ custom_margins_test.TestNames = {
}; };
suite(custom_margins_test.suiteName, function() { suite(custom_margins_test.suiteName, function() {
/** @type {?PrintPreviewMarginControlContainerElement} */ /** @type {!PrintPreviewMarginControlContainerElement} */
let container = null; let container;
/** @type {?PrintPreviewModelElement} */ /** @type {PrintPreviewModelElement} */
let model = null; let model;
/** @type {!Array<!CustomMarginsOrientation>} */ /** @type {!Array<!CustomMarginsOrientation>} */
let sides = []; let sides = [];
/** @type {!MeasurementSystem} */ /** @type {!MeasurementSystem} */
let measurementSystem = null; let measurementSystem;
/** @type {number} */ /** @type {number} */
const pixelsPerInch = 100; const pixelsPerInch = 100;
...@@ -52,10 +55,11 @@ suite(custom_margins_test.suiteName, function() { ...@@ -52,10 +55,11 @@ suite(custom_margins_test.suiteName, function() {
/** @override */ /** @override */
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
measurementSystem = measurementSystem =
new MeasurementSystem(',', '.', MeasurementSystemUnitType.IMPERIAL); new MeasurementSystem(',', '.', MeasurementSystemUnitType.IMPERIAL);
model = document.createElement('print-preview-model'); model = /** @type {!PrintPreviewModelElement} */ (
document.createElement('print-preview-model'));
document.body.appendChild(model); document.body.appendChild(model);
model.set('settings.mediaSize.available', true); model.set('settings.mediaSize.available', true);
...@@ -64,8 +68,8 @@ suite(custom_margins_test.suiteName, function() { ...@@ -64,8 +68,8 @@ suite(custom_margins_test.suiteName, function() {
CustomMarginsOrientation.BOTTOM, CustomMarginsOrientation.LEFT CustomMarginsOrientation.BOTTOM, CustomMarginsOrientation.LEFT
]; ];
container = container = /** @type {!PrintPreviewMarginControlContainerElement} */ (
document.createElement('print-preview-margin-control-container'); document.createElement('print-preview-margin-control-container'));
container.previewLoaded = false; container.previewLoaded = false;
// 8.5 x 11, in points // 8.5 x 11, in points
container.pageSize = new Size(612, 794); container.pageSize = new Size(612, 794);
...@@ -74,10 +78,10 @@ suite(custom_margins_test.suiteName, function() { ...@@ -74,10 +78,10 @@ suite(custom_margins_test.suiteName, function() {
container.state = State.NOT_READY; container.state = State.NOT_READY;
}); });
/** @return {!Array<!PrintPreviewMarginControlElement>} */ /** @return {!NodeList<!PrintPreviewMarginControlElement>} */
function getControls() { function getControls() {
return container.shadowRoot.querySelectorAll( return /** @type {!NodeList<!PrintPreviewMarginControlElement>} */ (
'print-preview-margin-control'); container.shadowRoot.querySelectorAll('print-preview-margin-control'));
} }
/* /*
...@@ -166,7 +170,7 @@ suite(custom_margins_test.suiteName, function() { ...@@ -166,7 +170,7 @@ suite(custom_margins_test.suiteName, function() {
* Tests setting the margin control with its textbox. * Tests setting the margin control with its textbox.
* @param {!PrintPreviewMarginControlElement} control The control. * @param {!PrintPreviewMarginControlElement} control The control.
* @param {string} key The control's key in the custom margin setting. * @param {string} key The control's key in the custom margin setting.
* @param {number} currentValue The current margin value in points. * @param {number} currentValuePts The current margin value in points.
* @param {string} input The new textbox input for the margin. * @param {string} input The new textbox input for the margin.
* @param {boolean} invalid Whether the new value is invalid. * @param {boolean} invalid Whether the new value is invalid.
* @param {number=} newValuePts the new margin value in pts. If not * @param {number=} newValuePts the new margin value in pts. If not
...@@ -247,7 +251,7 @@ suite(custom_margins_test.suiteName, function() { ...@@ -247,7 +251,7 @@ suite(custom_margins_test.suiteName, function() {
container.previewLoaded = false; container.previewLoaded = false;
// Custom margins values should be cleared. // Custom margins values should be cleared.
expectEquals( assertEquals(
'{}', JSON.stringify(container.getSettingValue('customMargins'))); '{}', JSON.stringify(container.getSettingValue('customMargins')));
// The margins-settings element will also set the margins type to DEFAULT. // The margins-settings element will also set the margins type to DEFAULT.
model.set('settings.margins.value', MarginsType.DEFAULT); model.set('settings.margins.value', MarginsType.DEFAULT);
...@@ -256,7 +260,7 @@ suite(custom_margins_test.suiteName, function() { ...@@ -256,7 +260,7 @@ suite(custom_margins_test.suiteName, function() {
// custom margins are not selected. We do not want to set the sticky // custom margins are not selected. We do not want to set the sticky
// values until the user has selected custom margins. // values until the user has selected custom margins.
container.previewLoaded = true; container.previewLoaded = true;
expectEquals( assertEquals(
'{}', JSON.stringify(container.getSettingValue('customMargins'))); '{}', JSON.stringify(container.getSettingValue('customMargins')));
}); });
} }
...@@ -264,6 +268,11 @@ suite(custom_margins_test.suiteName, function() { ...@@ -264,6 +268,11 @@ suite(custom_margins_test.suiteName, function() {
// Test that controls correctly appear when custom margins are selected and // Test that controls correctly appear when custom margins are selected and
// disappear when the preview is loading. // disappear when the preview is loading.
test(assert(custom_margins_test.TestNames.ControlsCheck), function() { test(assert(custom_margins_test.TestNames.ControlsCheck), function() {
/** @return {!MarginsSetting} */
const getCustomMarginsValue = function() {
return /** @type {!MarginsSetting} */ (
container.getSettingValue('customMargins'));
};
return finishSetup() return finishSetup()
.then(() => { .then(() => {
const controls = getControls(); const controls = getControls();
...@@ -283,18 +292,10 @@ suite(custom_margins_test.suiteName, function() { ...@@ -283,18 +292,10 @@ suite(custom_margins_test.suiteName, function() {
}) })
.then(function() { .then(function() {
// Verify margins are correctly set based on previous value. // Verify margins are correctly set based on previous value.
assertEquals( assertEquals(defaultMarginPts, getCustomMarginsValue().marginTop);
defaultMarginPts, assertEquals(defaultMarginPts, getCustomMarginsValue().marginLeft);
container.settings.customMargins.value.marginTop); assertEquals(defaultMarginPts, getCustomMarginsValue().marginRight);
assertEquals( assertEquals(defaultMarginPts, getCustomMarginsValue().marginBottom);
defaultMarginPts,
container.settings.customMargins.value.marginLeft);
assertEquals(
defaultMarginPts,
container.settings.customMargins.value.marginRight);
assertEquals(
defaultMarginPts,
container.settings.customMargins.value.marginBottom);
// Verify there is one control for each side and that controls are // Verify there is one control for each side and that controls are
// visible and positioned correctly. // visible and positioned correctly.
...@@ -395,7 +396,7 @@ suite(custom_margins_test.suiteName, function() { ...@@ -395,7 +396,7 @@ suite(custom_margins_test.suiteName, function() {
}); });
/** /**
* @param {!Array<!MarginControlElement>} controls * @param {!NodeList<!PrintPreviewMarginControlElement>} controls
* @param {number} currentValue Current margin value in pts * @param {number} currentValue Current margin value in pts
* @param {string} input String to set in margin textboxes * @param {string} input String to set in margin textboxes
* @param {boolean} invalid Whether the string is invalid * @param {boolean} invalid Whether the string is invalid
......
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