Commit ca7a8666 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Refactor Print Preview tests: MediaSize, Dpi

SetMediaSize and SetDpi are moved with small modifications to
DpiSettingsSectionTest.UpdateFromSetting and
MediaSizeSettingsSectionTest.UpdateFromSetting

Since setting the setting based on the dropdown is actually the
responsibility of the settings-select element, this aspect of the test
is covered by a new SettingsSelect.SetSetting test.

CustomMediaSize test is moved to:
MediaSizeSettingsSectionTest.SettingsSelect

Adding new
DpiSettingsSectionTest.SettingsSelect
(similar to media size test above).

Change-Id: I7d6fe6b382b0fb5ac7ddb90c52bc3272425cf380
Reviewed-on: https://chromium-review.googlesource.com/c/1493373
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarEsmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636700}
parent 25781e9c
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('dpi_settings_test', function() {
suite('DpiSettingsTest', function() {
/** @type {?PrintPreviewDpiSettingsElement} */
let dpiSection = null;
const dpiCapability = print_preview_test_utils.getCddTemplate('FooPrinter')
.capabilities.printer.dpi;
const expectedCapabilityWithLabels =
print_preview_test_utils.getCddTemplate('FooPrinter')
.capabilities.printer.dpi;
expectedCapabilityWithLabels.option.forEach(option => {
option.name = option.horizontal_dpi.toString() + ' dpi';
});
/** @override */
setup(function() {
PolymerTest.clearBody();
dpiSection = document.createElement('print-preview-dpi-settings');
dpiSection.settings = {
dpi: {
value: {},
unavailableValue: {},
valid: true,
available: true,
setByPolicy: false,
key: 'dpi',
},
};
dpiSection.capability = dpiCapability;
dpiSection.disabled = false;
document.body.appendChild(dpiSection);
});
test('settings select', function() {
const settingsSelect = dpiSection.$$('print-preview-settings-select');
assertFalse(settingsSelect.disabled);
assertDeepEquals(expectedCapabilityWithLabels, settingsSelect.capability);
assertEquals('dpi', settingsSelect.settingName);
});
test('update from setting', function() {
const highQualityOption = dpiCapability.option[0];
const lowQualityOption = dpiCapability.option[1];
const highQualityWithLabel = expectedCapabilityWithLabels.option[0];
const lowQualityWithLabel = expectedCapabilityWithLabels.option[1];
// Set the setting to the printer default.
dpiSection.set('settings.dpi.value', highQualityOption);
// Default is 200 dpi.
const settingsSelect = dpiSection.$$('print-preview-settings-select');
assertDeepEquals(
highQualityWithLabel, JSON.parse(settingsSelect.selectedValue));
assertDeepEquals(highQualityOption, dpiSection.getSettingValue('dpi'));
// Change to 100
dpiSection.setSetting('dpi', lowQualityOption);
assertDeepEquals(
lowQualityWithLabel, JSON.parse(settingsSelect.selectedValue));
// Set the setting to an option that is not supported by the
// printer. This can occur if sticky settings are for a different
// printer at startup.
const unavailableOption = {
horizontal_dpi: 400,
vertical_dpi: 400,
};
dpiSection.setSetting('dpi', unavailableOption);
// The section should reset the setting to the printer's default
// value with label, since the printer does not support 400 DPI.
assertDeepEquals(highQualityWithLabel, dpiSection.getSettingValue('dpi'));
assertDeepEquals(
highQualityWithLabel, JSON.parse(settingsSelect.selectedValue));
});
});
});
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('media_size_settings_test', function() {
suite('MediaSizeSettingsTest', function() {
/** @type {?PrintPreviewMediaSizeSettingsElement} */
let mediaSizeSection = null;
const mediaSizeCapability =
print_preview_test_utils.getCddTemplate('FooPrinter')
.capabilities.printer.media_size;
/** @override */
setup(function() {
PolymerTest.clearBody();
mediaSizeSection =
document.createElement('print-preview-media-size-settings');
mediaSizeSection.settings = {
mediaSize: {
value: {
width_microns: 215900,
height_microns: 279400,
},
unavailableValue: {},
valid: true,
available: true,
setByPolicy: false,
key: 'mediaSize',
},
};
mediaSizeSection.capability = mediaSizeCapability;
mediaSizeSection.disabled = false;
document.body.appendChild(mediaSizeSection);
});
test('settings select', function() {
const settingsSelect =
mediaSizeSection.$$('print-preview-settings-select');
assertFalse(settingsSelect.disabled);
assertEquals(mediaSizeCapability, settingsSelect.capability);
assertEquals('mediaSize', settingsSelect.settingName);
});
test('update from setting', function() {
const letterOption = mediaSizeCapability.option[0];
const squareOption = mediaSizeCapability.option[1];
// Default is letter
const settingsSelect =
mediaSizeSection.$$('print-preview-settings-select');
assertDeepEquals(letterOption, JSON.parse(settingsSelect.selectedValue));
assertDeepEquals(
letterOption, mediaSizeSection.getSettingValue('mediaSize'));
// Change to square
mediaSizeSection.setSetting('mediaSize', mediaSizeCapability.option[1]);
assertDeepEquals(squareOption, JSON.parse(settingsSelect.selectedValue));
// Set the setting to an option that is not supported by the
// printer. This can occur if sticky settings are for a different
// printer at startup.
const unavailableOption = {
name: 'ISO_A4',
width_microns: 210000,
height_microns: 297000,
custom_display_name: 'A4',
};
mediaSizeSection.setSetting('mediaSize', unavailableOption);
// The section should reset the setting to the printer's default
// value, since the printer does not support A4.
assertDeepEquals(
letterOption, mediaSizeSection.getSettingValue('mediaSize'));
assertDeepEquals(letterOption, JSON.parse(settingsSelect.selectedValue));
});
});
});
...@@ -95,10 +95,6 @@ TEST_F( ...@@ -95,10 +95,6 @@ TEST_F(
settings_sections_tests.TestNames.SettingsSectionsVisibilityChange); settings_sections_tests.TestNames.SettingsSectionsVisibilityChange);
}); });
TEST_F('PrintPreviewSettingsSectionsTest', 'MediaSizeCustomNames', function() {
this.runMochaTest(settings_sections_tests.TestNames.MediaSizeCustomNames);
});
TEST_F('PrintPreviewSettingsSectionsTest', 'Other', function() { TEST_F('PrintPreviewSettingsSectionsTest', 'Other', function() {
this.runMochaTest(settings_sections_tests.TestNames.Other); this.runMochaTest(settings_sections_tests.TestNames.Other);
}); });
...@@ -115,14 +111,6 @@ TEST_F('PrintPreviewSettingsSectionsTest', 'SetColor', function() { ...@@ -115,14 +111,6 @@ TEST_F('PrintPreviewSettingsSectionsTest', 'SetColor', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetColor); this.runMochaTest(settings_sections_tests.TestNames.SetColor);
}); });
TEST_F('PrintPreviewSettingsSectionsTest', 'SetMediaSize', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetMediaSize);
});
TEST_F('PrintPreviewSettingsSectionsTest', 'SetDpi', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetDpi);
});
TEST_F('PrintPreviewSettingsSectionsTest', 'SetMargins', function() { TEST_F('PrintPreviewSettingsSectionsTest', 'SetMargins', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetMargins); this.runMochaTest(settings_sections_tests.TestNames.SetMargins);
}); });
...@@ -246,19 +234,15 @@ PrintPreviewSettingsSelectTest = class extends NewPrintPreviewTest { ...@@ -246,19 +234,15 @@ PrintPreviewSettingsSelectTest = class extends NewPrintPreviewTest {
/** @override */ /** @override */
get extraLibraries() { get extraLibraries() {
return super.extraLibraries.concat([ return super.extraLibraries.concat([
'../settings/test_util.js',
'print_preview_test_utils.js', 'print_preview_test_utils.js',
'settings_select_test.js', 'settings_select_test.js',
]); ]);
} }
/** @override */
get suiteName() {
return settings_select_test.suiteName;
}
}; };
TEST_F('PrintPreviewSettingsSelectTest', 'CustomMediaNames', function() { TEST_F('PrintPreviewSettingsSelectTest', 'All', function() {
this.runMochaTest(settings_select_test.TestNames.CustomMediaNames); mocha.run();
}); });
PrintPreviewSelectBehaviorTest = class extends NewPrintPreviewTest { PrintPreviewSelectBehaviorTest = class extends NewPrintPreviewTest {
...@@ -1309,3 +1293,43 @@ TEST_F( ...@@ -1309,3 +1293,43 @@ TEST_F(
this.runMochaTest( this.runMochaTest(
scaling_settings_test.TestNames.InputNotDisabledOnValidityChange); scaling_settings_test.TestNames.InputNotDisabledOnValidityChange);
}); });
PrintPreviewMediaSizeSettingsTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/media_size_settings.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'../settings/test_util.js',
'print_preview_test_utils.js',
'media_size_settings_test.js',
]);
}
};
TEST_F('PrintPreviewMediaSizeSettingsTest', 'All', function() {
mocha.run();
});
PrintPreviewDpiSettingsTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/dpi_settings.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'../settings/test_util.js',
'print_preview_test_utils.js',
'dpi_settings_test.js',
]);
}
};
TEST_F('PrintPreviewDpiSettingsTest', 'All', function() {
mocha.run();
});
...@@ -6,13 +6,10 @@ cr.define('settings_sections_tests', function() { ...@@ -6,13 +6,10 @@ cr.define('settings_sections_tests', function() {
/** @enum {string} */ /** @enum {string} */
const TestNames = { const TestNames = {
SettingsSectionsVisibilityChange: 'settings sections visibility change', SettingsSectionsVisibilityChange: 'settings sections visibility change',
MediaSizeCustomNames: 'media size custom names',
Other: 'other', Other: 'other',
SetCopies: 'set copies', SetCopies: 'set copies',
SetLayout: 'set layout', SetLayout: 'set layout',
SetColor: 'set color', SetColor: 'set color',
SetMediaSize: 'set media size',
SetDpi: 'set dpi',
SetMargins: 'set margins', SetMargins: 'set margins',
SetPagesPerSheet: 'set pages per sheet', SetPagesPerSheet: 'set pages per sheet',
SetOther: 'set other', SetOther: 'set other',
...@@ -111,31 +108,6 @@ cr.define('settings_sections_tests', function() { ...@@ -111,31 +108,6 @@ cr.define('settings_sections_tests', function() {
}); });
}); });
test(assert(TestNames.MediaSizeCustomNames), function() {
const customLocalizedMediaName = 'Vendor defined localized media name';
const customMediaName = 'Vendor defined media name';
const mediaSizeElement = page.$$('print-preview-media-size-settings');
// Expand more settings to reveal the element.
toggleMoreSettings();
assertFalse(mediaSizeElement.hidden);
// Change capability to have custom paper sizes.
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
capabilities.printer.media_size =
print_preview_test_utils.getMediaSizeCapabilityWithCustomNames();
page.set('destination_.capabilities', capabilities);
Polymer.dom.flush();
const settingsSelect =
mediaSizeElement.$$('print-preview-settings-select');
assertEquals(capabilities.printer.media_size, settingsSelect.capability);
assertFalse(settingsSelect.disabled);
assertEquals('mediaSize', settingsSelect.settingName);
});
/** /**
* @param {!CrCheckboxElement} checkbox The checkbox to check * @param {!CrCheckboxElement} checkbox The checkbox to check
* @return {boolean} Whether the checkbox's parent section is hidden. * @return {boolean} Whether the checkbox's parent section is hidden.
...@@ -249,98 +221,6 @@ cr.define('settings_sections_tests', function() { ...@@ -249,98 +221,6 @@ cr.define('settings_sections_tests', function() {
}); });
}); });
test(assert(TestNames.SetMediaSize), function() {
toggleMoreSettings();
const mediaSizeElement = page.$$('print-preview-media-size-settings');
assertFalse(mediaSizeElement.hidden);
const mediaSizeCapabilities =
page.destination_.capabilities.printer.media_size;
const letterOption = JSON.stringify(mediaSizeCapabilities.option[0]);
const squareOption = JSON.stringify(mediaSizeCapabilities.option[1]);
// Default is letter
const settingsSelect =
mediaSizeElement.$$('print-preview-settings-select');
assertEquals(letterOption, settingsSelect.$$('select').value);
assertEquals(letterOption, JSON.stringify(page.settings.mediaSize.value));
// Change to square
return print_preview_test_utils.selectOption(settingsSelect, squareOption)
.then(function() {
assertEquals(
squareOption, JSON.stringify(page.settings.mediaSize.value));
// Set the setting to an option that is not supported by the
// printer. This can occur if sticky settings are for a different
// printer at startup.
const unavailableOption = {
name: 'ISO_A4',
width_microns: 210000,
height_microns: 297000,
custom_display_name: 'A4',
};
page.setSetting('mediaSize', unavailableOption);
return test_util.eventToPromise(
'process-select-change', mediaSizeElement);
})
.then(function() {
// The section should reset the setting to the printer's default
// value, since the printer does not support A4.
assertEquals(
letterOption, JSON.stringify(page.settings.mediaSize.value));
});
});
test(assert(TestNames.SetDpi), function() {
toggleMoreSettings();
const dpiElement = page.$$('print-preview-dpi-settings');
assertFalse(dpiElement.hidden);
const dpiCapabilities = page.destination_.capabilities.printer.dpi;
const highQualityOption = dpiCapabilities.option[0];
const lowQualityOption = dpiCapabilities.option[1];
// Default is 200
const settingsSelect = dpiElement.$$('print-preview-settings-select');
const isDpiEqual = function(value1, value2) {
return value1.horizontal_dpi == value2.horizontal_dpi &&
value1.vertical_dpi == value2.vertical_dpi &&
value1.vendor_id == value2.vendor_id;
};
expectTrue(isDpiEqual(
highQualityOption, JSON.parse(settingsSelect.$$('select').value)));
expectTrue(isDpiEqual(highQualityOption, page.settings.dpi.value));
// Change to 100
return print_preview_test_utils
.selectOption(
settingsSelect,
JSON.stringify(dpiElement.capabilityWithLabels_.option[1]))
.then(function() {
expectTrue(isDpiEqual(
lowQualityOption,
JSON.parse(settingsSelect.$$('select').value)));
expectTrue(isDpiEqual(lowQualityOption, page.settings.dpi.value));
// Set to the setting to an option that is not supported by the
// printer. This can occur if sticky settings are for a different
// printer at startup.
const unavailableOption = {
horizontal_dpi: 400,
vertical_dpi: 400,
};
page.setSetting('dpi', unavailableOption);
return test_util.eventToPromise(
'process-select-change', dpiElement);
})
.then(function() {
// The section should reset the setting to the printer's default
// value, since the printer does not support 400 DPI.
expectTrue(isDpiEqual(highQualityOption, page.settings.dpi.value));
});
});
test(assert(TestNames.SetMargins), function() { test(assert(TestNames.SetMargins), function() {
toggleMoreSettings(); toggleMoreSettings();
const marginsElement = page.$$('print-preview-margins-settings'); const marginsElement = page.$$('print-preview-margins-settings');
......
...@@ -3,13 +3,7 @@ ...@@ -3,13 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
cr.define('settings_select_test', function() { cr.define('settings_select_test', function() {
/** @enum {string} */ suite('SettingsSelectTest', function() {
const TestNames = {
CustomMediaNames: 'custom media names',
};
const suiteName = 'SettingsSelectTest';
suite(suiteName, function() {
let settingsSelect = null; let settingsSelect = null;
/** @override */ /** @override */
...@@ -21,7 +15,7 @@ cr.define('settings_select_test', function() { ...@@ -21,7 +15,7 @@ cr.define('settings_select_test', function() {
}); });
// Test that destinations are correctly displayed in the lists. // Test that destinations are correctly displayed in the lists.
test(assert(TestNames.CustomMediaNames), function() { test('custom media names', function() {
// Set a capability with custom paper sizes. // Set a capability with custom paper sizes.
settingsSelect.settingName = 'mediaSize'; settingsSelect.settingName = 'mediaSize';
settingsSelect.capability = settingsSelect.capability =
...@@ -41,10 +35,56 @@ cr.define('settings_select_test', function() { ...@@ -41,10 +35,56 @@ cr.define('settings_select_test', function() {
customLocalizedMediaName, select.options[0].textContent.trim()); customLocalizedMediaName, select.options[0].textContent.trim());
assertEquals(customMediaName, select.options[1].textContent.trim()); assertEquals(customMediaName, select.options[1].textContent.trim());
}); });
});
return { test('set setting', async () => {
suiteName: suiteName, // Fake setting.
TestNames: TestNames, settingsSelect.settings = {
}; fruit: {
value: {},
unavailableValue: {},
valid: true,
available: true,
setByPolicy: false,
key: 'fruit',
},
};
settingsSelect.settingName = 'fruit';
settingsSelect.capability = {
option: [
{name: 'lime', color: 'green', size: 3},
{name: 'orange', color: 'orange', size: 5, is_default: true},
],
};
Polymer.dom.flush();
const option0 = JSON.stringify(settingsSelect.capability.option[0]);
const option1 = JSON.stringify(settingsSelect.capability.option[1]);
const select = settingsSelect.$$('select');
// Normally done for initialization by the model and parent section.
settingsSelect.set(
'settings.fruit.value', settingsSelect.capability.option[0]);
settingsSelect.selectValue(option1);
// Verify that the selected option and names are as expected.
assertEquals(2, select.options.length);
assertEquals(1, select.selectedIndex);
assertEquals('lime', select.options[0].textContent.trim());
assertEquals('orange', select.options[1].textContent.trim());
assertEquals(option0, select.options[0].value);
assertEquals(option1, select.options[1].value);
// Verify that selecting an new option in the dropdown sets the setting.
await print_preview_test_utils.selectOption(settingsSelect, option0);
assertEquals(
option0, JSON.stringify(settingsSelect.getSettingValue('fruit')));
assertEquals(0, select.selectedIndex);
// Verify that selecting from outside works.
settingsSelect.selectValue(option1);
await test_util.eventToPromise('process-select-change', settingsSelect);
assertEquals(
option1, JSON.stringify(settingsSelect.getSettingValue('fruit')));
assertEquals(1, select.selectedIndex);
});
});
}); });
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