Commit 1f4e9a46 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Add the new Drive destination to the CrOS destination dropdown

This destination replaces the existing Save To Drive destination when
the printSaveToDrive flag is enabled.

Bug: 1112416
Change-Id: I860a026ede69161beb169cae01d5b91388be5374
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343972
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797157}
parent 23ff897d
......@@ -8,11 +8,12 @@ export {PluralStringProxyImpl as PrintPreviewPluralStringProxyImpl} from 'chrome
export {CloudPrintInterface, CloudPrintInterfaceEventType} from './cloud_print_interface.js';
export {CloudPrintInterfaceImpl} from './cloud_print_interface_impl.js';
export {Cdd, ColorMode, createDestinationKey, Destination, DestinationCertificateStatus, DestinationConnectionStatus, DestinationOrigin, DestinationType, makeRecentDestination, RecentDestination} from './data/destination.js';
// <if expr="chromeos">
export {SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from './data/destination.js';
// </if>
export {PrinterType} from './data/destination_match.js';
// <if expr="chromeos">
export {ColorModeRestriction, DuplexModeRestriction, PinModeRestriction} from './data/destination_policies.js';
export {PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from './data/printer_status_cros.js';
export {PrinterState} from './ui/printer_status_icon_cros.js';
// </if>
export {DestinationErrorType, DestinationStore} from './data/destination_store.js';
export {PageLayoutInfo} from './data/document_info.js';
......@@ -20,6 +21,9 @@ export {InvitationStore} from './data/invitation_store.js';
export {CustomMarginsOrientation, Margins, MarginsSetting, MarginsType} from './data/margins.js';
export {MeasurementSystem, MeasurementSystemUnitType} from './data/measurement_system.js';
export {DuplexMode, DuplexType, getInstance, whenReady} from './data/model.js';
// <if expr="chromeos">
export {PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from './data/printer_status_cros.js';
// </if>
export {ScalingType} from './data/scaling.js';
export {Size} from './data/size.js';
export {Error, State} from './data/state.js';
......@@ -29,5 +33,8 @@ export {DEFAULT_MAX_COPIES} from './ui/copies_settings.js';
export {DestinationState} from './ui/destination_settings.js';
export {PDFPlugin, PluginProxy, PluginProxyImpl} from './ui/plugin_proxy.js';
export {PreviewAreaState} from './ui/preview_area.js';
// <if expr="chromeos">
export {PrinterState} from './ui/printer_status_icon_cros.js';
// </if>
export {SelectBehavior} from './ui/select_behavior.js';
export {SelectOption} from './ui/settings_select.js';
......@@ -25,8 +25,8 @@
<option value="[[pdfDestinationKey_]]" hidden$="[[pdfPrinterDisabled]]">
$i18n{printToPDF}
</option>
<option value="[[driveDestinationKey]]"
hidden$="[[!driveDestinationKey]]">
<option value="[[driveDestinationKeyCros_]]"
hidden$="[[!driveDestinationKeyCros_]]">
$i18n{printToGoogleDrive}
</option>
<option value="noDestinations"
......@@ -44,7 +44,7 @@
value="[[destination]]" hidden$="[[!loaded]]"
item-list="[[recentDestinationList]]"
pdf-destination-key="[[pdfDestinationKey_]]"
drive-destination-key="[[driveDestinationKey]]"
drive-destination-key="[[driveDestinationKeyCros_]]"
no-destinations="[[noDestinations]]"
pdf-printer-disabled="[[pdfPrinterDisabled]]"
destination-icon="[[destinationIcon_]]" disabled="[[disabled]]"
......
......@@ -21,7 +21,7 @@ import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {Base, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {CloudOrigins, Destination, DestinationOrigin, PDF_DESTINATION_KEY, RecentDestination} from '../data/destination.js';
import {CloudOrigins, Destination, DestinationOrigin, PDF_DESTINATION_KEY, RecentDestination, SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from '../data/destination.js';
import {ERROR_STRING_KEY_MAP, PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from '../data/printer_status_cros.js';
import {NativeLayer, NativeLayerImpl} from '../native_layer.js';
import {getSelectDropdownBackground} from '../print_preview_utils.js';
......@@ -109,6 +109,22 @@ Polymer({
computed: 'computeIsCurrentDestinationCrosLocal_(destination)',
reflectToAttribute: true,
},
/** @private */
saveToDriveFlagEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('printSaveToDrive');
},
readOnly: true,
},
/** @private */
driveDestinationKeyCros_: {
type: String,
computed:
'computeDriveDestinationKeyCros_(driveDestinationKey, saveToDriveFlagEnabled_)',
},
},
/** @private {!IronMetaElement} */
......@@ -403,5 +419,14 @@ Polymer({
this.$$('#dropdown')
.shadowRoot.querySelectorAll('.list-item:not([hidden])') :
this.shadowRoot.querySelectorAll('option:not([hidden])');
},
/**
* @return {string}
* @private
*/
computeDriveDestinationKeyCros_: function() {
return this.saveToDriveFlagEnabled_ ? SAVE_TO_DRIVE_CROS_DESTINATION_KEY :
this.driveDestinationKey;
}
});
......@@ -22,6 +22,7 @@ import '../strings.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {EventTracker} from 'chrome://resources/js/event_tracker.m.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {WebUIListenerBehavior} from 'chrome://resources/js/web_ui_listener_behavior.m.js';
import {beforeNextRender, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......@@ -152,6 +153,17 @@ Polymer({
/** @private {!Array<string>} */
users_: Array,
// <if expr="chromeos">
/** @private */
saveToDriveFlagEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('printSaveToDrive');
},
readOnly: true,
},
// </if>
},
/** @private {string} */
......@@ -371,6 +383,13 @@ Polymer({
* Drive.
*/
destinationIsDriveOrPdf_(destination) {
// <if expr="chromeos">
if (this.saveToDriveFlagEnabled_ &&
destination.id === Destination.GooglePromotedId.SAVE_TO_DRIVE_CROS) {
return true;
}
// </if>
return destination.id === Destination.GooglePromotedId.SAVE_AS_PDF ||
destination.id === Destination.GooglePromotedId.DOCS;
},
......
......@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground, NativeLayer, NativeLayerImpl, PrinterState, PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from 'chrome://print/print_preview.js';
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground, NativeLayer, NativeLayerImpl, PrinterState, PrinterStatus, PrinterStatusReason, PrinterStatusSeverity, SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {Base, flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
......@@ -325,7 +326,8 @@ destination_select_test_cros.suiteName = 'DestinationSelectTestCros';
destination_select_test_cros.TestNames = {
UpdateStatus: 'update status',
ChangeIcon: 'change icon',
EulaIsDisplayed: 'eula is displayed'
EulaIsDisplayed: 'eula is displayed',
SelectDriveDestination: 'select drive destination',
};
suite(destination_select_test_cros.suiteName, function() {
......@@ -460,4 +462,39 @@ suite(destination_select_test_cros.suiteName, function() {
'destination.eulaUrl', 'chrome://os-credits/eula');
assertFalse(destinationEulaWrapper.hidden);
});
// Tests that the correct drive destination is in the select based on value of
// printSaveToDrive flag.
test(
assert(destination_select_test_cros.TestNames.SelectDriveDestination),
function() {
const driveDestinationKey = `${Destination.GooglePromotedId.DOCS}/${
DestinationOrigin.COOKIES}/${account}`;
const printSaveToDriveEnabled =
loadTimeData.getBoolean('printSaveToDrive');
const expectedKey = printSaveToDriveEnabled ?
SAVE_TO_DRIVE_CROS_DESTINATION_KEY :
driveDestinationKey;
const wrongKey = !printSaveToDriveEnabled ?
SAVE_TO_DRIVE_CROS_DESTINATION_KEY :
driveDestinationKey;
return waitBeforeNextRender(destinationSelect)
.then(() => {
destinationSelect.driveDestinationKey = driveDestinationKey;
destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination();
assertTrue(
!!Array.from(destinationSelect.$$('.md-select').options)
.find(option => option.value === expectedKey));
assertTrue(!Array.from(destinationSelect.$$('.md-select').options)
.find(option => option.value === wrongKey));
return selectOption(destinationSelect, expectedKey);
})
.then(() => {
assertEquals(
expectedKey, destinationSelect.$$('.md-select').value);
});
});
});
......@@ -1123,6 +1123,48 @@ TEST_F('PrintPreviewDestinationSelectTestCrOS', 'EulaIsDisplayed', function() {
this.runMochaTest(destination_select_test_cros.TestNames.EulaIsDisplayed);
});
TEST_F(
'PrintPreviewDestinationSelectTestCrOS', 'SelectDriveDestination',
function() {
this.runMochaTest(
destination_select_test_cros.TestNames.SelectDriveDestination);
});
// eslint-disable-next-line no-var
var PrintPreviewDestinationSelectTestCrOSSaveToDriveEnabled =
class extends PrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/test_loader.html?module=print_preview/destination_select_test_cros.js';
}
/** @override */
get suiteName() {
return destination_select_test_cros.suiteName;
}
/** @override */
get featureList() {
const kPrinterStatus = ['chromeos::features::kPrinterStatus'];
const kPrintSaveToDrive = ['chromeos::features::kPrintSaveToDrive'];
const featureList = super.featureList;
featureList.disabled = featureList.disabled ?
featureList.disabled.concat(kPrinterStatus) :
kPrinterStatus;
featureList.enabled = featureList.enabled ?
featureList.enabled.concat(kPrintSaveToDrive) :
kPrintSaveToDrive;
return featureList;
}
};
TEST_F(
'PrintPreviewDestinationSelectTestCrOSSaveToDriveEnabled',
'SelectDriveDestination', function() {
this.runMochaTest(
destination_select_test_cros.TestNames.SelectDriveDestination);
});
// eslint-disable-next-line no-var
var PrintPreviewPrinterStatusTestCros = class extends PrintPreviewTest {
/** @override */
......
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