Commit 03af9daa authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Remove settings section tests

These tests have now been moved and/or broken up into tests for the
elements actually responsible for the behaviors tested, with the
exception of presets and visiblity tests, which are validating the
behavior of print-preview-app itself. Move these tests into the
print_preview_app_test.js. Trim down PresetCopies and PresetDuplex
to test only behavior not already tested in other places, and combine
these two tests into one since they are both testing the same event
handler.

Change-Id: I1167776f437f60f7bd82c3407206331db84de86d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1501999
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarEsmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637878}
parent e95ed3f0
......@@ -64,43 +64,13 @@ TEST_F('PrintPreviewAppTest', 'PrintToGoogleDrive', function() {
this.runMochaTest(print_preview_app_test.TestNames.PrintToGoogleDrive);
});
PrintPreviewSettingsSectionsTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/app.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'../settings/test_util.js',
'../test_browser_proxy.js',
'native_layer_stub.js',
'plugin_stub.js',
'print_preview_test_utils.js',
'settings_section_test.js',
]);
}
/** @override */
get suiteName() {
return settings_sections_tests.suiteName;
}
};
TEST_F(
'PrintPreviewSettingsSectionsTest', 'SettingsSectionsVisibilityChange',
function() {
this.runMochaTest(
settings_sections_tests.TestNames.SettingsSectionsVisibilityChange);
});
TEST_F('PrintPreviewSettingsSectionsTest', 'PresetCopies', function() {
this.runMochaTest(settings_sections_tests.TestNames.PresetCopies);
TEST_F('PrintPreviewAppTest', 'SettingsSectionsVisibilityChange', function() {
this.runMochaTest(
print_preview_app_test.TestNames.SettingsSectionsVisibilityChange);
});
TEST_F('PrintPreviewSettingsSectionsTest', 'PresetDuplex', function() {
this.runMochaTest(settings_sections_tests.TestNames.PresetDuplex);
TEST_F('PrintPreviewAppTest', 'PrintPresets', function() {
this.runMochaTest(print_preview_app_test.TestNames.PrintPresets);
});
PrintPreviewPagesSettingsTest = class extends NewPrintPreviewTest {
......
......@@ -6,6 +6,8 @@ cr.define('print_preview_app_test', function() {
/** @enum {string} */
const TestNames = {
PrintToGoogleDrive: 'print to google drive',
SettingsSectionsVisibilityChange: 'settings sections visibility change',
PrintPresets: 'print presets',
};
const suiteName = 'PrintPreviewAppTest';
......@@ -116,6 +118,40 @@ cr.define('print_preview_app_test', function() {
print_preview.Destination.GooglePromotedId.DOCS, args.destination.id);
assertEquals('1.0', JSON.parse(args.printTicket).version);
});
test(assert(TestNames.SettingsSectionsVisibilityChange), async () => {
await finishSetup();
const moreSettingsElement = page.$$('print-preview-more-settings');
moreSettingsElement.$.label.click();
const camelToKebab = s => s.replace(/([A-Z])/g, '-$1').toLowerCase();
['copies', 'layout', 'color', 'mediaSize', 'margins', 'dpi', 'scaling',
'otherOptions']
.forEach(setting => {
const element =
page.$$(`print-preview-${camelToKebab(setting)}-settings`);
// Show, hide and reset.
[true, false, true].forEach(value => {
page.set(`settings.${setting}.available`, value);
// Element expected to be visible when available.
assertEquals(!value, element.hidden);
});
});
});
test(assert(TestNames.PrintPresets), async () => {
await finishSetup();
assertEquals(1, page.settings.copies.value);
page.setSetting('duplex', false);
assertFalse(page.settings.duplex.value);
// Send preset values of duplex LONG_EDGE and 2 copies.
const copies = 2;
const duplex = print_preview_new.DuplexMode.LONG_EDGE;
cr.webUIListenerCallback('print-preset-options', true, copies, duplex);
assertEquals(copies, page.getSettingValue('copies'));
assertTrue(page.getSettingValue('duplex'));
});
});
return {
......
// Copyright 2017 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('settings_sections_tests', function() {
/** @enum {string} */
const TestNames = {
SettingsSectionsVisibilityChange: 'settings sections visibility change',
PresetCopies: 'preset copies',
PresetDuplex: 'preset duplex',
};
const suiteName = 'SettingsSectionsTests';
suite(suiteName, function() {
/** @type {?PrintPreviewAppElement} */
let page = null;
/** @override */
setup(function() {
const initialSettings =
print_preview_test_utils.getDefaultInitialSettings();
const nativeLayer = new print_preview.NativeLayerStub();
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate(initialSettings.printerName));
nativeLayer.setPageCount(3);
print_preview.NativeLayer.setInstance(nativeLayer);
const pluginProxy = new print_preview.PDFPluginStub();
print_preview_new.PluginProxy.setInstance(pluginProxy);
PolymerTest.clearBody();
page = document.createElement('print-preview-app');
document.body.appendChild(page);
const previewArea = page.$.previewArea;
pluginProxy.setLoadCallback(previewArea.onPluginLoad_.bind(previewArea));
// Wait for initialization to complete.
return Promise
.all([
nativeLayer.whenCalled('getInitialSettings'),
nativeLayer.whenCalled('getPrinterCapabilities')
])
.then(function() {
Polymer.dom.flush();
});
});
function toggleMoreSettings() {
const moreSettingsElement = page.$$('print-preview-more-settings');
moreSettingsElement.$.label.click();
}
test(assert(TestNames.SettingsSectionsVisibilityChange), function() {
toggleMoreSettings();
const camelToKebab = s => s.replace(/([A-Z])/g, '-$1').toLowerCase();
['copies', 'layout', 'color', 'mediaSize', 'margins', 'dpi', 'scaling',
'otherOptions']
.forEach(setting => {
const element =
page.$$(`print-preview-${camelToKebab(setting)}-settings`);
// Show, hide and reset.
[true, false, true].forEach(value => {
page.set(`settings.${setting}.available`, value);
// Element expected to be visible when available.
assertEquals(!value, element.hidden);
});
});
});
test(assert(TestNames.PresetCopies), function() {
const copiesElement = page.$$('print-preview-copies-settings');
assertFalse(copiesElement.hidden);
// Default value is 1
const copiesInput =
copiesElement.$$('print-preview-number-settings-section')
.$.userValue.inputElement;
assertEquals('1', copiesInput.value);
assertEquals(1, page.settings.copies.value);
// Send a preset value of 2
const copies = 2;
cr.webUIListenerCallback('print-preset-options', true, copies);
assertEquals(copies, page.settings.copies.value);
assertEquals(copies.toString(), copiesInput.value);
});
test(assert(TestNames.PresetDuplex), function() {
toggleMoreSettings();
const optionsElement = page.$$('print-preview-other-options-settings');
assertFalse(optionsElement.hidden);
// Default value is on, so turn it off
page.setSetting('duplex', false);
const checkbox = optionsElement.$$('#duplex');
assertFalse(checkbox.checked);
assertFalse(page.settings.duplex.value);
// Send a preset value of LONG_EDGE
const duplex = print_preview_new.DuplexMode.LONG_EDGE;
cr.webUIListenerCallback('print-preset-options', false, 1, duplex);
assertTrue(page.settings.duplex.value);
assertTrue(checkbox.checked);
});
});
return {
suiteName: suiteName,
TestNames: TestNames,
};
});
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