Commit 13c1eb45 authored by Michael Checo's avatar Michael Checo Committed by Commit Bot

Print Jobs: Make history tooltip reflective of policy

Screenshots:

Stored indefinitely: http://shortn/_BuvF4ezVoI
Stored for "x" days: http://shortn/_wfCSX0tOwi
Stored for 1 day: http://shortn/_KVOOqrC97F
Default: http://shortn/_qndr3tYsuf

Bug:1113660
Test: gtest_filter=OSSettingsCupsPrinterLandingPageV3Test.All

Change-Id: Ib254f3e71f9e1b9b28e66d80f4700446413bcbf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2393069Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Commit-Queue: Michael Checo <michaelcheco@google.com>
Cr-Commit-Position: refs/heads/master@{#809974}
parent 547ddc7a
......@@ -44,6 +44,8 @@ PrintingManager::PrintingManager(
delete_print_job_history_allowed_.Init(prefs::kDeletePrintJobHistoryAllowed,
pref_service);
print_job_history_expiration_period_.Init(
prefs::kPrintJobHistoryExpirationPeriod, pref_service);
}
PrintingManager::~PrintingManager() {
......@@ -58,6 +60,11 @@ void PrintingManager::GetPrintJobs(GetPrintJobsCallback callback) {
base::BindOnce(&PrintingManager::OnPrintJobsRetrieved,
base::Unretained(this), std::move(callback)));
}
void PrintingManager::GetPrintJobHistoryExpirationPeriod(
GetPrintJobHistoryExpirationPeriodCallback callback) {
std::move(callback).Run(print_job_history_expiration_period_.GetValue(),
print_job_history_expiration_period_.IsManaged());
}
void PrintingManager::DeleteAllPrintJobs(DeleteAllPrintJobsCallback callback) {
if (!IsHistoryDeletionAllowedByPolicy()) {
......
......@@ -43,6 +43,8 @@ class PrintingManager
// printing_manager::mojom::PrintingMetadataProvider:
void GetPrintJobs(GetPrintJobsCallback callback) override;
void GetPrintJobHistoryExpirationPeriod(
GetPrintJobHistoryExpirationPeriodCallback callback) override;
void DeleteAllPrintJobs(DeleteAllPrintJobsCallback callback) override;
void ObservePrintJobs(
mojo::PendingRemote<printing_manager::mojom::PrintJobsObserver> observer,
......@@ -126,6 +128,8 @@ class PrintingManager
// ongoing print job has been updated.
CupsPrintJobManager* cups_print_job_manager_;
IntegerPrefMember print_job_history_expiration_period_;
base::WeakPtrFactory<PrintingManager> weak_ptr_factory_{this};
};
......
......@@ -208,6 +208,9 @@ class FakePrintingMetadataProvider {
*/
this.printJobsObserverRemote_;
/** @private {number} */
this.expirationPeriod_ = 90;
this.resetForTest();
}
......@@ -225,6 +228,8 @@ class FakePrintingMetadataProvider {
this.resolverMap_.set('cancelPrintJob', new PromiseResolver());
this.resolverMap_.set(
'getDeletePrintJobHistoryAllowedByPolicy', new PromiseResolver());
this.resolverMap_.set(
'getPrintJobHistoryExpirationPeriod', new PromiseResolver());
}
/**
......@@ -273,6 +278,11 @@ class FakePrintingMetadataProvider {
this.printJobs_ = printJobs;
}
/** @param {number} expirationPeriod */
setExpirationPeriod(expirationPeriod) {
this.expirationPeriod_ = expirationPeriod;
}
/**
* @param {boolean} shouldAttemptCancel
*/
......@@ -350,6 +360,17 @@ class FakePrintingMetadataProvider {
});
}
/** @return {!Promise<{expirationPeriod: number}>} */
getPrintJobHistoryExpirationPeriod() {
return new Promise(resolve => {
this.methodCalled('getPrintJobHistoryExpirationPeriod');
resolve({
expirationPeriodInDays: this.expirationPeriod_,
isFromPolicy: true,
});
});
}
/**
* @param {!string} id
* @return {!Promise<{attemptedCancel}>}
......@@ -443,6 +464,111 @@ suite('PrintManagementTest', () => {
return mojoApi.whenCalled('getPrintJobs');
});
}
test('PrintJobHistoryExpirationPeriodOneDay', () => {
const completedInfo = createCompletedPrintJobInfo(CompletionStatus.PRINTED);
const expectedText = 'Print jobs older than 1 day will be removed';
const expectedArr = [
createJobEntry(
'newest', 'titleA',
convertToMojoTime(new Date(Date.UTC(2020, 3, 1, 1, 1, 1))),
PrinterErrorCode.NO_ERROR, completedInfo, /*activeInfo=*/ null),
];
// Print job metadata will be stored for 1 day.
mojoApi_.setExpirationPeriod(1);
return initializePrintManagementApp(expectedArr.slice().reverse())
.then(() => {
return mojoApi_.whenCalled('getPrintJobs');
})
.then(() => {
flush();
return mojoApi_.whenCalled('getPrintJobHistoryExpirationPeriod');
})
.then(() => {
const historyInfoTooltip = page.$$('paper-tooltip');
assertEquals(expectedText, historyInfoTooltip.textContent.trim());
});
});
test('PrintJobHistoryExpirationPeriodDefault', () => {
const completedInfo = createCompletedPrintJobInfo(CompletionStatus.PRINTED);
const expectedText = 'Print jobs older than 90 days will be removed';
const expectedArr = [
createJobEntry(
'newest', 'titleA',
convertToMojoTime(new Date(Date.UTC(2020, 3, 1, 1, 1, 1))),
PrinterErrorCode.NO_ERROR, completedInfo, /*activeInfo=*/ null),
];
// Print job metadata will be stored for 90 days which is the default
// period when the policy is not controlled.
mojoApi_.setExpirationPeriod(90);
return initializePrintManagementApp(expectedArr.slice().reverse())
.then(() => {
return mojoApi_.whenCalled('getPrintJobs');
})
.then(() => {
flush();
return mojoApi_.whenCalled('getPrintJobHistoryExpirationPeriod');
})
.then(() => {
const historyInfoTooltip = page.$$('paper-tooltip');
assertEquals(expectedText, historyInfoTooltip.textContent.trim());
});
});
test('PrintJobHistoryExpirationPeriodIndefinte', () => {
const completedInfo = createCompletedPrintJobInfo(CompletionStatus.PRINTED);
const expectedText = 'Print jobs will appear in history unless they are ' +
'removed manually';
const expectedArr = [
createJobEntry(
'newest', 'titleA',
convertToMojoTime(new Date(Date.UTC(2020, 3, 1, 1, 1, 1))),
PrinterErrorCode.NO_ERROR, completedInfo, /*activeInfo=*/ null),
];
// When this policy is set to a value of -1, the print jobs metadata is
// stored indefinitely.
mojoApi_.setExpirationPeriod(-1);
return initializePrintManagementApp(expectedArr.slice().reverse())
.then(() => {
return mojoApi_.whenCalled('getPrintJobs');
})
.then(() => {
flush();
return mojoApi_.whenCalled('getPrintJobHistoryExpirationPeriod');
})
.then(() => {
const historyInfoTooltip = page.$$('paper-tooltip');
assertEquals(expectedText, historyInfoTooltip.textContent.trim());
});
});
test('PrintJobHistoryExpirationPeriodNDays', () => {
const completedInfo = createCompletedPrintJobInfo(CompletionStatus.PRINTED);
const expectedText = 'Print jobs older than 4 days will be removed';
const expectedArr = [
createJobEntry(
'newest', 'titleA',
convertToMojoTime(new Date(Date.UTC(2020, 3, 1, 1, 1, 1))),
PrinterErrorCode.NO_ERROR, completedInfo, /*activeInfo=*/ null),
];
// Print job metadata will be stored for 4 days.
mojoApi_.setExpirationPeriod(4);
return initializePrintManagementApp(expectedArr.slice().reverse())
.then(() => {
return mojoApi_.whenCalled('getPrintJobs');
})
.then(() => {
flush();
return mojoApi_.whenCalled('getPrintJobHistoryExpirationPeriod');
})
.then(() => {
const historyInfoTooltip = page.$$('paper-tooltip');
assertEquals(expectedText, historyInfoTooltip.textContent.trim());
});
});
test('PrintHistoryListIsSortedReverseChronologically', () => {
const completedInfo = createCompletedPrintJobInfo(CompletionStatus.PRINTED);
......
......@@ -365,8 +365,14 @@ Try tapping the mic to ask me anything.
<message name="IDS_PRINT_MANAGEMENT_HISTORY_HEADER_LABEL" desc="The header label that indicates that print jobs below this header are the user's print history.">
History
</message>
<message name="IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP" desc="The tooltip that states that the user's print jobs are automatically deleted after 90 days.">
Print jobs older than 90 days will be removed
<message name="IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP_INDEFINITE" desc="The tooltip that states that the user's print jobs are stored indefinitely.">
Print jobs will appear in history unless they are removed manually
</message>
<message name="IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP_MULTIPLE_DAYS_EXPIRATION" desc="The tooltip that states that the user's print jobs are automatically deleted after a variable amount of days.">
Print jobs older than <ph name="NUMBER_OF_DAYS">$1<ex>45</ex></ph> days will be removed
</message>
<message name="IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP_SINGLE_DAY_EXPIRATION" desc="The tooltip that states that the user's print jobs are automatically deleted after one day.">
Print jobs older than 1 day will be removed
</message>
<message name="IDS_PRINT_MANAGEMENT_PRINTED_PAGES_ARIA_LABEL" desc="The aria label that describes the current page printed printed versus the total number of pages.">
Printed page <ph name="PRINTED_PAGES">$1<ex>1</ex></ph> out of <ph name="TOTAL_PAGES">$2<ex>2</ex></ph>.
......
7dd93040ef4b848ffb82a5356798ed5b1bfe7b3d
\ No newline at end of file
7c7bd743f86d2c9c7bbea9fd559697342e81a055
\ No newline at end of file
2eb3cd599c1d10b4d72f6d9cd28d01c08caa6f1b
\ No newline at end of file
......@@ -135,4 +135,9 @@ interface PrintingMetadataProvider {
// Returns true if the user is allowed to delete their own print job history
// (default value is true for non-managed users).
GetDeletePrintJobHistoryAllowedByPolicy() => (bool is_allowed_by_policy);
// Returns the database expiration period of the print job metadata in days.
GetPrintJobHistoryExpirationPeriod() => (
int16 expiration_period_in_days,
bool is_from_policy);
};
......@@ -60,7 +60,12 @@ void AddPrintManagementStrings(content::WebUIDataSource* html_source) {
{"cancelButtonLabel", IDS_PRINT_MANAGEMENT_CANCEL_BUTTON_LABEL},
{"clearButtonLabel", IDS_PRINT_MANAGEMENT_CLEAR_BUTTON_LABEL},
{"historyHeader", IDS_PRINT_MANAGEMENT_HISTORY_HEADER_LABEL},
{"historyToolTip", IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP},
{"printJobHistoryExpirationPeriod",
IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP_MULTIPLE_DAYS_EXPIRATION},
{"printJobHistoryIndefinitePeriod",
IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP_INDEFINITE},
{"printJobHistorySingleDay",
IDS_PRINT_MANAGEMENT_HISTORY_TOOL_TIP_SINGLE_DAY_EXPIRATION},
{"printedPageLabel", IDS_PRINT_MANAGEMENT_PRINTED_PAGES_ARIA_LABEL},
{"printedPagesFraction",
IDS_PRINT_MANAGEMENT_PRINTED_PAGES_PROGRESS_FRACTION},
......
......@@ -40,6 +40,9 @@
<g id="delete" width="20" height="20" viewBox="0 0 20 20">
<path d="M13 3V2H7V3H3V5H4V16C4 17.1 4.9 18 6 18H14C15.1 18 16 17.1 16 16V5H17V3H13ZM14 16H6V5H14V16Z"/>
</g>
<g id="enterprise-icon" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 17V3H12V7H18V17H2ZM8 9H10V11H8V9ZM12 11H14V13H12V15H16V9H12V11ZM8 13H10V15H8V13ZM6 13H4V15H6V13ZM6 9H4V11H6V9ZM8 5H10V7H8V5ZM6 5H4V7H6V5Z"/>
</g>
</defs>
</svg>
</iron-iconset-svg>
\ No newline at end of file
......@@ -36,6 +36,14 @@
margin-inline-end: 4px;
}
#enterpriseIcon {
--iron-icon-fill-color: var(--google-grey-refresh-700);
--iron-icon-stroke-color: var(--google-grey-refresh-700);
--iron-icon-height: 13px;
--iron-icon-width: 13px;
margin-inline-start: 8px;
}
#headerContainer {
border-bottom: 1px solid rgba(0,0,0,0.14); /* 14% black */
display: flex;
......@@ -140,13 +148,18 @@
<template is="dom-if" if="[[printJobs_.length]]" restamp>
<div id="historyHeaderContainer" class="column-headers flex-center">
<div aria-label$="[[i18n('historyToolTip')]]">
<div aria-label$="[[printJobHistoryExpirationPeriod_]]">
[[i18n('historyHeader')]]
</div>
<iron-icon id="infoIcon" icon="cr:info-outline" aria-hidden="true">
<iron-icon id="infoIcon" icon="cr:info-outline" aria-hidden="true"
hidden="[[isPolicyControlled_]]">
</iron-icon>
<iron-icon id="enterpriseIcon" icon="print-management:enterprise-icon"
aria-hidden="true" hidden="[[!isPolicyControlled_]]">
</iron-icon>
<paper-tooltip for="infoIcon" fit-to-visible-bounds aria-hidden="true">
[[i18n('historyToolTip')]]
<paper-tooltip for="[[activeHistoryInfoIcon_]]" fit-to-visible-bounds
aria-hidden="true">
[[printJobHistoryExpirationPeriod_]]
</paper-tooltip>
</div>
......
......@@ -24,6 +24,10 @@ import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
const METADATA_STORED_INDEFINITELY = -1;
const METADATA_STORED_FOR_ONE_DAY = 1;
const METADATA_NOT_STORED = 0;
/**
* @typedef {Array<!chromeos.printing.printingManager.mojom.PrintJobInfo>}
*/
......@@ -83,6 +87,24 @@ Polymer({
value: () => [],
},
/** @private */
printJobHistoryExpirationPeriod_: {
type: String,
value: '',
},
/** @private */
activeHistoryInfoIcon_: {
type: String,
value: '',
},
/** @private */
isPolicyControlled_: {
type: Boolean,
value: false,
},
/**
* @type {!PrintJobInfoArr}
* @private
......@@ -150,6 +172,7 @@ Polymer({
/** @override */
attached() {
this.getPrintJobHistoryExpirationPeriod_();
this.startObservingPrintJobs_();
this.fetchDeletePrintJobHistoryPolicy_();
},
......@@ -259,7 +282,51 @@ Polymer({
/** @private */
getPrintJobs_() {
this.mojoInterfaceProvider_.getPrintJobs()
.then(this.onPrintJobsReceived_.bind(this));
.then(this.onPrintJobsReceived_.bind(this));
},
/**
* @param {!{
* expirationPeriodInDays: number,
* isFromPolicy: boolean
* }} printJobPolicyInfo
* @private
*/
onPrintJobHistoryExpirationPeriodReceived_(printJobPolicyInfo) {
const expirationPeriod = printJobPolicyInfo.expirationPeriodInDays;
// If print jobs are not persisted, we can return early since the tooltip
// section won't be shown.
if (expirationPeriod === METADATA_NOT_STORED) {
return;
}
this.isPolicyControlled_ = printJobPolicyInfo.isFromPolicy;
this.activeHistoryInfoIcon_ = this.isPolicyControlled_
? 'enterpriseIcon'
: 'infoIcon';
switch (expirationPeriod) {
case METADATA_STORED_INDEFINITELY:
this.printJobHistoryExpirationPeriod_ =
loadTimeData.getString('printJobHistoryIndefinitePeriod');
break;
case METADATA_STORED_FOR_ONE_DAY:
this.printJobHistoryExpirationPeriod_ =
loadTimeData.getString('printJobHistorySingleDay');
break;
default:
this.printJobHistoryExpirationPeriod_ =
loadTimeData.getStringF(
'printJobHistoryExpirationPeriod',
expirationPeriod
);
}
},
/** @private */
getPrintJobHistoryExpirationPeriod_() {
this.mojoInterfaceProvider_.getPrintJobHistoryExpirationPeriod()
.then(this.onPrintJobHistoryExpirationPeriodReceived_.bind(this));
},
/**
......@@ -283,14 +350,6 @@ Polymer({
this.showClearAllDialog_ = false;
},
/**
* @return {string}
* @private
*/
getHistoryLabel_() {
return loadTimeData.getString('historyToolTip');
},
/**
* @param {string} expectedId
* @return {number}
......
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