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

Reland tests for Print Preview: Enable change button during load

Flakes appear to be due to destination store communicating with the
real native layer/print preview handler. Stub out native layer like in
other tests.

Bug: 901115, 905205
Change-Id: I938b6fbecfc5da26a5495e6f9ecbb8fa35b64d4e
Reviewed-on: https://chromium-review.googlesource.com/c/1335998
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608548}
parent a908129a
// 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();
const nativeLayer = new print_preview.NativeLayerStub();
print_preview.NativeLayer.setInstance(nativeLayer);
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,
};
});
......@@ -143,7 +143,8 @@ cr.define('print_preview', function() {
{destinationId: printerId, printerType: type});
if (type != print_preview.PrinterType.LOCAL_PRINTER)
return Promise.reject();
return this.localDestinationCapabilities_.get(printerId);
return this.localDestinationCapabilities_.get(printerId) ||
Promise.reject();
}
/** @override */
......
......@@ -1119,3 +1119,29 @@ TEST_F(
TEST_F('PrintPreviewKeyEventTest', 'CtrlShiftPOpensSystemDialog', function() {
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',
'../test_browser_proxy.js',
'native_layer_stub.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.*
PrintPreviewDestinationItemTest.*
PrintPreviewDestinationListTest.*
PrintPreviewDestinationSearchTest.*
PrintPreviewDestinationSettingsTest.*
PrintPreviewHeaderTest.*
PrintPreviewKeyEventTest.*
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