Commit 9f695d72 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview Refresh: Enable change button while destination loads

In some cases (e.g. kiosk apps with no default printer configured), the
print destination may never load. Enable the "Change" button while
destination capabilities are loading so that the user can switch
destinations in this case.

Bug: 901115
Change-Id: I53eec9332e0d7f075e461226290d408ae6d6ef49
Reviewed-on: https://chromium-review.googlesource.com/c/1332703
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607896}
parent 1580ece8
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<link rel="import" href="print_preview_shared_css.html"> <link rel="import" href="print_preview_shared_css.html">
<link rel="import" href="throbber_css.html"> <link rel="import" href="throbber_css.html">
<link rel="import" href="settings_section.html"> <link rel="import" href="settings_section.html">
<link rel="import" href="state.html">
<link rel="import" href="strings.html"> <link rel="import" href="strings.html">
<dom-module id="print-preview-destination-settings"> <dom-module id="print-preview-destination-settings">
......
...@@ -59,7 +59,7 @@ Polymer({ ...@@ -59,7 +59,7 @@ Polymer({
*/ */
shouldDisableButton_: function() { shouldDisableButton_: function() {
return !this.destinationStore || return !this.destinationStore ||
(this.disabled && (this.disabled && this.state != print_preview_new.State.NOT_READY &&
this.state != print_preview_new.State.INVALID_PRINTER); this.state != print_preview_new.State.INVALID_PRINTER);
}, },
......
// 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('destination_settings_test', function() {
/** @enum {string} */
const TestNames = {
ChangeButtonState: 'change button state',
};
const suiteName = 'DestinationSettingsTest';
suite(suiteName, function() {
/** @type {?PrintPreviewDestinationSettingsElement} */
let destinationSettings = null;
/** @override */
setup(function() {
PolymerTest.clearBody();
destinationSettings =
document.createElement('print-preview-destination-settings');
destinationSettings.disabled = false;
destinationSettings.destinationStore = null;
destinationSettings.state = print_preview_new.State.NOT_READY;
document.body.appendChild(destinationSettings);
});
// Tests that the change button is enabled or disabled correctly based on
// the state.
test(assert(TestNames.ChangeButtonState), function() {
const button = destinationSettings.$$('paper-button');
// Initial state: No destination store, button should be disabled.
assertTrue(button.disabled);
// Set up the destination store, but no destination yet. Button is now
// enabled.
const userInfo = new print_preview.UserInfo();
const destinationStore = new print_preview.DestinationStore(
userInfo, new WebUIListenerTracker());
destinationStore.init(
false /* isInAppKioskMode */, 'FooDevice' /* printerName */,
'' /* serializedDefaultDestinationSelectionRulesStr */,
[] /* recentDestinations */);
destinationSettings.destinationStore = destinationStore;
destinationSettings.state = print_preview_new.State.NOT_READY;
assertFalse(button.disabled);
// Simulate loading a destination and setting state to ready. The button
// is still enabled.
destinationSettings.destination = new print_preview.Destination(
'FooDevice', print_preview.DestinationType.LOCAL,
print_preview.DestinationOrigin.LOCAL, 'FooName', true /* isRecent */,
print_preview.DestinationConnectionStatus.ONLINE);
destinationSettings.state = print_preview_new.State.READY;
assertFalse(button.disabled);
// Simulate setting a setting to an invalid value. Button is disabled due
// to validation error on another control.
destinationSettings.state = print_preview_new.State.INVALID_TICKET;
destinationSettings.disabled = true;
assertTrue(button.disabled);
// Simulate the user fixing the validation error, and then selecting an
// invalid printer. Button is enabled, so that the user can fix the error.
destinationSettings.state = print_preview_new.State.READY;
destinationSettings.disabled = false;
destinationSettings.state = print_preview_new.State.INVALID_PRINTER;
destinationSettings.disabled = true;
assertFalse(button.disabled);
});
});
return {
suiteName: suiteName,
TestNames: TestNames,
};
});
...@@ -1119,3 +1119,27 @@ TEST_F( ...@@ -1119,3 +1119,27 @@ TEST_F(
TEST_F('PrintPreviewKeyEventTest', 'CtrlShiftPOpensSystemDialog', function() { TEST_F('PrintPreviewKeyEventTest', 'CtrlShiftPOpensSystemDialog', function() {
this.runMochaTest(key_event_test.TestNames.CtrlShiftPOpensSystemDialog); this.runMochaTest(key_event_test.TestNames.CtrlShiftPOpensSystemDialog);
}); });
PrintPreviewDestinationSettingsTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/destination_settings.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
ROOT_PATH + 'ui/webui/resources/js/webui_listener_tracker.js',
'destination_settings_test.js',
]);
}
/** @override */
get suiteName() {
return destination_settings_test.suiteName;
}
};
TEST_F('PrintPreviewDestinationSettingsTest', 'ChangeButtonState', function() {
this.runMochaTest(destination_settings_test.TestNames.ChangeButtonState);
});
...@@ -254,6 +254,7 @@ PrintPreviewDestinationDialogTest.* ...@@ -254,6 +254,7 @@ PrintPreviewDestinationDialogTest.*
PrintPreviewDestinationItemTest.* PrintPreviewDestinationItemTest.*
PrintPreviewDestinationListTest.* PrintPreviewDestinationListTest.*
PrintPreviewDestinationSearchTest.* PrintPreviewDestinationSearchTest.*
PrintPreviewDestinationSettingsTest.*
PrintPreviewHeaderTest.* PrintPreviewHeaderTest.*
PrintPreviewKeyEventTest.* PrintPreviewKeyEventTest.*
PrintPreviewLinkContainerTest.* PrintPreviewLinkContainerTest.*
......
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