Commit 27b08932 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview Componentization: Add unit tests for print-preview-header

Bug: 844513
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ic00f1af465b742a23701a85aad2f0d68d22f8808
Reviewed-on: https://chromium-review.googlesource.com/1071071Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561655}
parent 5223da53
...@@ -49,7 +49,8 @@ Polymer({ ...@@ -49,7 +49,8 @@ Polymer({
observers: observers:
['update_(settings.copies.value, settings.duplex.value, ' + ['update_(settings.copies.value, settings.duplex.value, ' +
'settings.pages.value, settings.pagesPerSheet.value, state)'], 'settings.pages.value, settings.pagesPerSheet.value, state, ' +
'destination.id)'],
/** @private */ /** @private */
onPrintClick_: function() { onPrintClick_: function() {
......
// Copyright 2018 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('header_test', function() {
/** @enum {string} */
const TestNames = {
HeaderPrinterTypes: 'header printer types',
HeaderWithDuplex: 'header with duplex',
HeaderWithCopies: 'header with copies',
HeaderWithNup: 'header with nup',
HeaderChangesForState: 'header changes for state',
};
const suiteName = 'HeaderTest';
suite(suiteName, function() {
/** @type {?PrintPreviewHeaderElement} */
let header = null;
/** @override */
setup(function() {
// Only care about copies, duplex, pages, and pages per sheet.
const settings = {
copies: {
value: '1',
unavailableValue: '1',
valid: true,
available: true,
key: '',
},
duplex: {
value: false,
unavailableValue: false,
valid: true,
available: true,
key: 'isDuplexEnabled',
},
pages: {
value: [1],
unavailableValue: [],
valid: true,
available: true,
key: '',
},
pagesPerSheet: {
value: 1,
unavailableValue: 1,
valid: true,
available: true,
key: '',
},
};
PolymerTest.clearBody();
header = document.createElement('print-preview-header');
header.settings = settings;
header.destination = new print_preview.Destination(
'FooDevice', print_preview.DestinationType.GOOGLE,
print_preview.DestinationOrigin.COOKIES, 'FooName',
true /* isRecent */,
print_preview.DestinationConnectionStatus.ONLINE);
header.errorMessage = '';
header.state = print_preview_new.State.READY;
document.body.appendChild(header);
});
function setPdfDestination() {
header.set(
'destination',
new print_preview.Destination(
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
print_preview.DestinationType.LOCAL,
print_preview.DestinationOrigin.LOCAL,
loadTimeData.getString('printToPDF'), false,
print_preview.DestinationConnectionStatus.ONLINE));
}
// Tests that the 4 different messages (non-virtual printer singular and
// plural, virtual printer singular and plural) all show up as expected.
test(assert(TestNames.HeaderPrinterTypes), function() {
const summary = header.$$('.summary');
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('pages', [1, 2, 3]);
assertEquals('Total: 3 sheets of paper', summary.textContent);
setPdfDestination();
assertEquals('Total: 3 pages', summary.textContent);
header.setSetting('pages', [1]);
assertEquals('Total: 1 page', summary.textContent);
});
// Tests that the message is correctly adjusted with a duplex printer.
test(assert(TestNames.HeaderWithDuplex), function() {
const summary = header.$$('.summary');
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('pages', [1, 2, 3]);
assertEquals('Total: 3 sheets of paper', summary.textContent);
header.setSetting('duplex', true);
assertEquals('Total: 2 sheets of paper', summary.textContent);
header.setSetting('pages', [1, 2]);
assertEquals('Total: 1 sheet of paper', summary.textContent);
});
// Tests that the message is correctly adjusted with multiple copies.
test(assert(TestNames.HeaderWithCopies), function() {
const summary = header.$$('.summary');
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('copies', 4);
assertEquals('Total: 4 sheets of paper', summary.textContent);
header.setSetting('duplex', true);
assertEquals('Total: 4 sheets of paper', summary.textContent);
header.setSetting('pages', [1, 2]);
assertEquals('Total: 4 sheets of paper', summary.textContent);
header.setSetting('duplex', false);
assertEquals('Total: 8 sheets of paper', summary.textContent);
});
// Tests that the message is correctly adjusted for N-up.
test(assert(TestNames.HeaderWithNup), function() {
const summary = header.$$('.summary');
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('pagesPerSheet', 4);
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('pages', [1, 2, 3, 4, 5, 6]);
assertEquals('Total: 2 sheets of paper', summary.textContent);
header.setSetting('duplex', true);
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('pagesPerSheet', 2);
assertEquals('Total: 2 sheets of paper', summary.textContent);
header.setSetting('pagesPerSheet', 3);
assertEquals('Total: 1 sheet of paper', summary.textContent);
header.setSetting('copies', 2);
assertEquals('Total: 2 sheets of paper', summary.textContent);
// Check PDF destination
header.setSetting('copies', 1);
header.setSetting('duplex', false);
setPdfDestination();
assertEquals('Total: 2 pages', summary.textContent);
});
// Tests that the correct message is shown for non-READY states, and that
// the print button is disabled appropriately.
test(assert(TestNames.HeaderChangesForState), function() {
const summary = header.$$('.summary');
const printButton = header.$$('.print');
assertEquals('Total: 1 sheet of paper', summary.textContent);
assertFalse(printButton.disabled);
header.set('state', print_preview_new.State.NOT_READY);
assertEquals('', summary.textContent);
assertTrue(printButton.disabled);
header.set('state', print_preview_new.State.PRINTING);
assertEquals(loadTimeData.getString('printing'), summary.textContent);
assertTrue(printButton.disabled);
setPdfDestination();
assertEquals(loadTimeData.getString('saving'), summary.textContent);
header.set('state', print_preview_new.State.INVALID_TICKET);
assertEquals('', summary.textContent);
assertTrue(printButton.disabled);
header.set('state', print_preview_new.State.INVALID_PRINTER);
assertEquals('', summary.textContent);
assertTrue(printButton.disabled);
const testError = 'Error printing to cloud print';
header.set('errorMessage', testError);
header.set('state', print_preview_new.State.FATAL_ERROR);
assertEquals(testError, summary.textContent);
assertTrue(printButton.disabled);
});
});
return {
suiteName: suiteName,
TestNames: TestNames,
};
});
...@@ -671,3 +671,43 @@ GEN('#endif'); // defined(OS_CHROMEOS) ...@@ -671,3 +671,43 @@ GEN('#endif'); // defined(OS_CHROMEOS)
TEST_F('PrintPreviewNewDestinationSearchTest', 'CloudKioskPrinter', function() { TEST_F('PrintPreviewNewDestinationSearchTest', 'CloudKioskPrinter', function() {
this.runMochaTest(destination_search_test.TestNames.CloudKioskPrinter); this.runMochaTest(destination_search_test.TestNames.CloudKioskPrinter);
}); });
PrintPreviewHeaderTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/header.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'header_test.js',
]);
}
/** @override */
get suiteName() {
return header_test.suiteName;
}
};
TEST_F('PrintPreviewHeaderTest', 'HeaderPrinterTypes', function() {
this.runMochaTest(header_test.TestNames.HeaderPrinterTypes);
});
TEST_F('PrintPreviewHeaderTest', 'HeaderWithDuplex', function() {
this.runMochaTest(header_test.TestNames.HeaderWithDuplex);
});
TEST_F('PrintPreviewHeaderTest', 'HeaderWithCopies', function() {
this.runMochaTest(header_test.TestNames.HeaderWithCopies);
});
TEST_F('PrintPreviewHeaderTest', 'HeaderWithNup', function() {
loadTimeData.overrideValues({pagesPerSheetEnabled: true});
this.runMochaTest(header_test.TestNames.HeaderWithNup);
});
TEST_F('PrintPreviewHeaderTest', 'HeaderChangesForState', function() {
this.runMochaTest(header_test.TestNames.HeaderChangesForState);
});
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