Commit 432b8c12 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Add drive mounted check to print preview initialization

Adding |isDriveMounted| to the init functions allows us to prevent the
creation of the Save to Drive destination on Chrome OS when necessary.

Bug: 1112416
Change-Id: I509c5354bf07134b6cce5a9298f9624059a3c37e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441729Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814868}
parent 60b0f43d
...@@ -340,6 +340,8 @@ export class DestinationStore extends EventTarget { ...@@ -340,6 +340,8 @@ export class DestinationStore extends EventTarget {
* will be automatically selected. * will be automatically selected.
* @param {boolean} pdfPrinterDisabled Whether the PDF print destination is * @param {boolean} pdfPrinterDisabled Whether the PDF print destination is
* disabled in print preview. * disabled in print preview.
* @param {boolean} isDriveMounted Whether Google Drive is mounted. Only used
on Chrome OS.
* @param {string} systemDefaultDestinationId ID of the system default * @param {string} systemDefaultDestinationId ID of the system default
* destination. * destination.
* @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
...@@ -348,13 +350,13 @@ export class DestinationStore extends EventTarget { ...@@ -348,13 +350,13 @@ export class DestinationStore extends EventTarget {
* recentDestinations The recent print destinations. * recentDestinations The recent print destinations.
*/ */
init( init(
pdfPrinterDisabled, systemDefaultDestinationId, pdfPrinterDisabled, isDriveMounted, systemDefaultDestinationId,
serializedDefaultDestinationSelectionRulesStr, recentDestinations) { serializedDefaultDestinationSelectionRulesStr, recentDestinations) {
this.pdfPrinterEnabled_ = !pdfPrinterDisabled; this.pdfPrinterEnabled_ = !pdfPrinterDisabled;
this.systemDefaultDestinationId_ = systemDefaultDestinationId; this.systemDefaultDestinationId_ = systemDefaultDestinationId;
this.createLocalPdfPrintDestination_(); this.createLocalPdfPrintDestination_();
// <if expr="chromeos"> // <if expr="chromeos">
if (this.saveToDriveFlagEnabled_) { if (this.saveToDriveFlagEnabled_ && isDriveMounted) {
this.createLocalDrivePrintDestination_(); this.createLocalDrivePrintDestination_();
} }
// </if> // </if>
......
...@@ -340,7 +340,7 @@ Polymer({ ...@@ -340,7 +340,7 @@ Polymer({
settings.isInAppKioskMode, settings.printerName, settings.isInAppKioskMode, settings.printerName,
settings.serializedDefaultDestinationSelectionRulesStr, settings.serializedDefaultDestinationSelectionRulesStr,
settings.userAccounts || null, settings.syncAvailable, settings.userAccounts || null, settings.syncAvailable,
settings.pdfPrinterDisabled); settings.pdfPrinterDisabled, settings.isDriveMounted || false);
// <if expr="chromeos"> // <if expr="chromeos">
if (this.saveToDriveFlagEnabled_) { if (this.saveToDriveFlagEnabled_) {
this.$.sidebar.setIsDriveMounted(settings.isDriveMounted); this.$.sidebar.setIsDriveMounted(settings.isDriveMounted);
......
...@@ -302,6 +302,8 @@ Polymer({ ...@@ -302,6 +302,8 @@ Polymer({
/** /**
* @param {string} defaultPrinter The system default printer ID. * @param {string} defaultPrinter The system default printer ID.
* @param {boolean} pdfPrinterDisabled Whether the PDF printer is disabled. * @param {boolean} pdfPrinterDisabled Whether the PDF printer is disabled.
* @param {boolean} isDriveMounted Whether Google Drive is mounted. Only used
on Chrome OS.
* @param {string} serializedDefaultDestinationRulesStr String with rules * @param {string} serializedDefaultDestinationRulesStr String with rules
* for selecting a default destination. * for selecting a default destination.
* @param {?Array<string>} userAccounts The signed in user accounts. * @param {?Array<string>} userAccounts The signed in user accounts.
...@@ -310,8 +312,8 @@ Polymer({ ...@@ -310,8 +312,8 @@ Polymer({
* to always send requests to the Google Cloud Print server. * to always send requests to the Google Cloud Print server.
*/ */
init( init(
defaultPrinter, pdfPrinterDisabled, serializedDefaultDestinationRulesStr, defaultPrinter, pdfPrinterDisabled, isDriveMounted,
userAccounts, syncAvailable) { serializedDefaultDestinationRulesStr, userAccounts, syncAvailable) {
const cloudPrintInterface = CloudPrintInterfaceImpl.getInstance(); const cloudPrintInterface = CloudPrintInterfaceImpl.getInstance();
if (cloudPrintInterface.isConfigured()) { if (cloudPrintInterface.isConfigured()) {
this.cloudPrintDisabled_ = false; this.cloudPrintDisabled_ = false;
...@@ -326,7 +328,7 @@ Polymer({ ...@@ -326,7 +328,7 @@ Polymer({
recentDestinations = recentDestinations.slice( recentDestinations = recentDestinations.slice(
0, this.getRecentDestinationsDisplayCount_(recentDestinations)); 0, this.getRecentDestinationsDisplayCount_(recentDestinations));
this.destinationStore_.init( this.destinationStore_.init(
this.pdfPrinterDisabled_, defaultPrinter, this.pdfPrinterDisabled_, isDriveMounted, defaultPrinter,
serializedDefaultDestinationRulesStr, recentDestinations); serializedDefaultDestinationRulesStr, recentDestinations);
}, },
......
...@@ -148,14 +148,19 @@ Polymer({ ...@@ -148,14 +148,19 @@ Polymer({
* @param {?Array<string>} userAccounts The signed in user accounts. * @param {?Array<string>} userAccounts The signed in user accounts.
* @param {boolean} syncAvailable * @param {boolean} syncAvailable
* @param {boolean} pdfPrinterDisabled Whether the PDF printer is disabled. * @param {boolean} pdfPrinterDisabled Whether the PDF printer is disabled.
* @param {boolean} isDriveMounted Whether Google Drive is mounted. Only used
on Chrome OS.
*/ */
init( init(
appKioskMode, defaultPrinter, serializedDestinationSelectionRulesStr, appKioskMode, defaultPrinter, serializedDestinationSelectionRulesStr,
userAccounts, syncAvailable, pdfPrinterDisabled) { userAccounts, syncAvailable, pdfPrinterDisabled, isDriveMounted) {
this.isInAppKioskMode_ = appKioskMode; this.isInAppKioskMode_ = appKioskMode;
const saveAsPdfDisabled = this.isInAppKioskMode_ || pdfPrinterDisabled; pdfPrinterDisabled = this.isInAppKioskMode_ || pdfPrinterDisabled;
// If PDF printing is disabled, then Save to Drive also needs to be disabled
// on Chrome OS.
isDriveMounted = !pdfPrinterDisabled && isDriveMounted;
this.$.destinationSettings.init( this.$.destinationSettings.init(
defaultPrinter, saveAsPdfDisabled, defaultPrinter, pdfPrinterDisabled, isDriveMounted,
serializedDestinationSelectionRulesStr, userAccounts, syncAvailable); serializedDestinationSelectionRulesStr, userAccounts, syncAvailable);
}, },
......
...@@ -67,6 +67,7 @@ suite(destination_dialog_interactive_test.suiteName, function() { ...@@ -67,6 +67,7 @@ suite(destination_dialog_interactive_test.suiteName, function() {
destinationSettings.cloudPrintInterface = cloudPrintInterface; destinationSettings.cloudPrintInterface = cloudPrintInterface;
destinationSettings.init( destinationSettings.init(
'FooDevice' /* printerName */, false /* pdfPrinterDisabled */, 'FooDevice' /* printerName */, false /* pdfPrinterDisabled */,
true /* isDriveMounted */,
'' /* serializedDefaultDestinationSelectionRulesStr */, '' /* serializedDefaultDestinationSelectionRulesStr */,
[] /* userAccounts */, true /* syncAvailable */); [] /* userAccounts */, true /* syncAvailable */);
return nativeLayer.whenCalled('getPrinterCapabilities').then(() => { return nativeLayer.whenCalled('getPrinterCapabilities').then(() => {
......
...@@ -73,7 +73,8 @@ suite(destination_dialog_test.suiteName, function() { ...@@ -73,7 +73,8 @@ suite(destination_dialog_test.suiteName, function() {
recentDestinations = [makeRecentDestination(destinations[4])]; recentDestinations = [makeRecentDestination(destinations[4])];
nativeLayer.setLocalDestinations(localDestinations); nativeLayer.setLocalDestinations(localDestinations);
destinationStore.init( destinationStore.init(
false /* pdfPrinterDisabled */, 'FooDevice' /* printerName */, false /* pdfPrinterDisabled */, true /* isDriveMounted */,
'FooDevice' /* printerName */,
'' /* serializedDefaultDestinationSelectionRulesStr */, '' /* serializedDefaultDestinationSelectionRulesStr */,
recentDestinations /* recentDestinations */); recentDestinations /* recentDestinations */);
......
...@@ -46,7 +46,8 @@ suite(destination_search_test.suiteName, function() { ...@@ -46,7 +46,8 @@ suite(destination_search_test.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities( nativeLayer.setLocalDestinationCapabilities(
getCddTemplate('FooDevice', 'FooName')); getCddTemplate('FooDevice', 'FooName'));
destinationStore.init( destinationStore.init(
false /* pdfPrinterDisabled */, 'FooDevice' /* printerName */, false /* pdfPrinterDisabled */, false /* isDriveMounted */,
'FooDevice' /* printerName */,
'' /* serializedDefaultDestinationSelectionRulesStr */, '' /* serializedDefaultDestinationSelectionRulesStr */,
[] /* recentDestinations */); [] /* recentDestinations */);
......
...@@ -50,7 +50,8 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -50,7 +50,8 @@ suite(destination_search_test_chromeos.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities( nativeLayer.setLocalDestinationCapabilities(
getCddTemplate('FooDevice', 'FooName')); getCddTemplate('FooDevice', 'FooName'));
destinationStore.init( destinationStore.init(
false /* isInAppKioskMode */, 'FooDevice' /* printerName */, false /* pdfPrinterDisabled */, true /* isDriveMounted */,
'FooDevice' /* printerName */,
'' /* serializedDefaultDestinationSelectionRulesStr */, '' /* serializedDefaultDestinationSelectionRulesStr */,
[] /* recentDestinations */); [] /* recentDestinations */);
......
...@@ -125,6 +125,7 @@ suite(destination_settings_test.suiteName, function() { ...@@ -125,6 +125,7 @@ suite(destination_settings_test.suiteName, function() {
// still not loaded. // still not loaded.
destinationSettings.init( destinationSettings.init(
'FooDevice' /* printerName */, false /* pdfPrinterDisabled */, 'FooDevice' /* printerName */, false /* pdfPrinterDisabled */,
true /* isDriveMounted */,
'' /* serializedDefaultDestinationSelectionRulesStr */, '' /* serializedDefaultDestinationSelectionRulesStr */,
[] /* userAccounts */, true /* syncAvailable */); [] /* userAccounts */, true /* syncAvailable */);
assertFalse(dropdown.loaded); assertFalse(dropdown.loaded);
...@@ -198,7 +199,7 @@ suite(destination_settings_test.suiteName, function() { ...@@ -198,7 +199,7 @@ suite(destination_settings_test.suiteName, function() {
destinationSettings.setSetting('recentDestinations', recentDestinations); destinationSettings.setSetting('recentDestinations', recentDestinations);
destinationSettings.appKioskMode = false; destinationSettings.appKioskMode = false;
destinationSettings.init( destinationSettings.init(
'' /* printerName */, pdfPrinterDisabled, '' /* printerName */, pdfPrinterDisabled, true /* isDriveMounted */,
'' /* serializedDefaultDestinationSelectionRulesStr */, initialAccounts, '' /* serializedDefaultDestinationSelectionRulesStr */, initialAccounts,
true /* syncAvailable */); true /* syncAvailable */);
destinationSettings.state = State.READY; destinationSettings.state = State.READY;
......
...@@ -32,6 +32,7 @@ destination_store_test.TestNames = { ...@@ -32,6 +32,7 @@ destination_store_test.TestNames = {
MultipleRecentDestinationsAccounts: 'multiple recent destinations accounts', MultipleRecentDestinationsAccounts: 'multiple recent destinations accounts',
LoadAndSelectDestination: 'select loaded destination', LoadAndSelectDestination: 'select loaded destination',
LoadSaveToDriveCros: 'load Save to Drive Cros', LoadSaveToDriveCros: 'load Save to Drive Cros',
DriveNotMounted: 'drive not mounted',
}; };
suite(destination_store_test.suiteName, function() { suite(destination_store_test.suiteName, function() {
...@@ -113,7 +114,8 @@ suite(destination_store_test.suiteName, function() { ...@@ -113,7 +114,8 @@ suite(destination_store_test.suiteName, function() {
DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY, DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY,
destinationStore); destinationStore);
destinationStore.init( destinationStore.init(
initialSettings.pdfPrinterDisabled, initialSettings.printerName, initialSettings.pdfPrinterDisabled, !!initialSettings.isDriveMounted,
initialSettings.printerName,
initialSettings.serializedDefaultDestinationSelectionRulesStr, initialSettings.serializedDefaultDestinationSelectionRulesStr,
recentDestinations); recentDestinations);
return opt_expectPrinterFailure ? Promise.resolve() : Promise.race([ return opt_expectPrinterFailure ? Promise.resolve() : Promise.race([
...@@ -523,4 +525,15 @@ suite(destination_store_test.suiteName, function() { ...@@ -523,4 +525,15 @@ suite(destination_store_test.suiteName, function() {
Destination.GooglePromotedId.SAVE_TO_DRIVE_CROS)); Destination.GooglePromotedId.SAVE_TO_DRIVE_CROS));
}); });
}); });
// Tests that the SAVE_TO_DRIVE_CROS destination is not loaded on Chrome OS
// when Google Drive is not mounted.
test(assert(destination_store_test.TestNames.DriveNotMounted), function() {
initialSettings.isDriveMounted = false;
return setInitialSettings(false).then(function(args) {
assertFalse(!!destinationStore.destinations().find(
destination => destination.id ===
Destination.GooglePromotedId.SAVE_TO_DRIVE_CROS));
});
});
}); });
...@@ -31,6 +31,7 @@ export function getDefaultInitialSettings() { ...@@ -31,6 +31,7 @@ export function getDefaultInitialSettings() {
syncAvailable: false, syncAvailable: false,
uiLocale: 'en-us', uiLocale: 'en-us',
unitType: MeasurementSystemUnitType.IMPERIAL, unitType: MeasurementSystemUnitType.IMPERIAL,
isDriveMounted: true,
}; };
} }
......
...@@ -647,6 +647,10 @@ TEST_F( ...@@ -647,6 +647,10 @@ TEST_F(
'PrintPreviewDestinationStoreTestCros', 'LoadSaveToDriveCros', function() { 'PrintPreviewDestinationStoreTestCros', 'LoadSaveToDriveCros', function() {
this.runMochaTest(destination_store_test.TestNames.LoadSaveToDriveCros); this.runMochaTest(destination_store_test.TestNames.LoadSaveToDriveCros);
}); });
TEST_F('PrintPreviewDestinationStoreTestCros', 'DriveNotMounted', function() {
this.runMochaTest(destination_store_test.TestNames.DriveNotMounted);
});
GEN('#endif'); GEN('#endif');
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
......
...@@ -48,7 +48,8 @@ suite('UserManagerTest', function() { ...@@ -48,7 +48,8 @@ suite('UserManagerTest', function() {
const localDestinations = []; const localDestinations = [];
const destinations = getDestinations(localDestinations); const destinations = getDestinations(localDestinations);
destinationStore.init( destinationStore.init(
false /* isInAppKioskMode */, 'FooDevice' /* printerName */, false /* pdfPrinterDisabled */, true /* isDriveMounted */,
'FooDevice' /* printerName */,
'' /* serializedDefaultDestinationSelectionRulesStr */, []); '' /* serializedDefaultDestinationSelectionRulesStr */, []);
nativeLayer.setLocalDestinations(localDestinations); nativeLayer.setLocalDestinations(localDestinations);
......
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