Skip to content

Commit

Permalink
Add PIN code to print ticket.
Browse files Browse the repository at this point in the history
Bug: 848942
Change-Id: Ie5a1060c728f5d1e0dc56603b8950abe3f9e692c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1477234
Commit-Queue: Nikita Podguzov <nikitapodguzov@google.com>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#641904}
  • Loading branch information
Nikita Podguzov authored and Commit Bot committed Mar 19, 2019
1 parent 7a16ff9 commit c1bf3f8
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 25 deletions.
6 changes: 6 additions & 0 deletions chrome/browser/resources/print_preview/new/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@ Polymer({
ticket.OpenPDFInPreview = true;
}

// <if expr="chromeos">
if (this.getSettingValue('pin')) {
ticket.pinValue = this.getSettingValue('pinValue');
}
// </if>

return JSON.stringify(ticket);
},

Expand Down
74 changes: 51 additions & 23 deletions chrome/test/data/webui/print_preview/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ cr.define('model_test', function() {
isColorEnabled: true,
vendorOptions: {},
};
if (cr.isChromeOS) {
stickySettingsDefault.isPinEnabled = false;
stickySettingsDefault.pinValue = '';
}

// Non-default state
const stickySettingsChange = {
Expand All @@ -68,6 +72,10 @@ cr.define('model_test', function() {
printArea: 6,
},
};
if (cr.isChromeOS) {
stickySettingsChange.isPinEnabled = true;
stickySettingsChange.pinValue = '0000';
}

/**
* @param {string} setting The name of the setting to check.
Expand Down Expand Up @@ -101,23 +109,30 @@ cr.define('model_test', function() {
};

model.applyStickySettings();
return testStickySetting('collate', 'isCollateEnabled')
.then(() => testStickySetting('color', 'isColorEnabled'))
.then(
() =>
testStickySetting('cssBackground', 'isCssBackgroundEnabled'))
.then(() => testStickySetting('dpi', 'dpi'))
.then(() => testStickySetting('duplex', 'isDuplexEnabled'))
.then(() => testStickySetting('fitToPage', 'isFitToPageEnabled'))
.then(
() => testStickySetting('headerFooter', 'isHeaderFooterEnabled'))
.then(() => testStickySetting('layout', 'isLandscapeEnabled'))
.then(() => testStickySetting('margins', 'marginsType'))
.then(() => testStickySetting('mediaSize', 'mediaSize'))
.then(() => testStickySetting('customScaling', 'customScaling'))
.then(() => testStickySetting('scaling', 'scaling'))
.then(() => testStickySetting('fitToPage', 'isFitToPageEnabled'))
.then(() => testStickySetting('vendorItems', 'vendorOptions'));
let promise =
testStickySetting('collate', 'isCollateEnabled')
.then(() => testStickySetting('color', 'isColorEnabled'))
.then(
() => testStickySetting(
'cssBackground', 'isCssBackgroundEnabled'))
.then(() => testStickySetting('dpi', 'dpi'))
.then(() => testStickySetting('duplex', 'isDuplexEnabled'))
.then(() => testStickySetting('fitToPage', 'isFitToPageEnabled'))
.then(
() => testStickySetting(
'headerFooter', 'isHeaderFooterEnabled'))
.then(() => testStickySetting('layout', 'isLandscapeEnabled'))
.then(() => testStickySetting('margins', 'marginsType'))
.then(() => testStickySetting('mediaSize', 'mediaSize'))
.then(() => testStickySetting('customScaling', 'customScaling'))
.then(() => testStickySetting('scaling', 'scaling'))
.then(() => testStickySetting('fitToPage', 'isFitToPageEnabled'))
.then(() => testStickySetting('vendorItems', 'vendorOptions'));
if (cr.isChromeOS) {
promise = promise.then(() => testStickySetting('pin', 'isPinEnabled'))
.then(() => testStickySetting('pinValue', 'pinValue'));
}
return promise;
});

/**
Expand Down Expand Up @@ -186,6 +201,10 @@ cr.define('model_test', function() {
},
ranges: [{from: 2, to: 2}],
};
if (cr.isChromeOS) {
settingsChange.pin = true;
settingsChange.pinValue = '0000';
}

// Update settings
Object.keys(settingsChange).forEach(setting => {
Expand Down Expand Up @@ -230,11 +249,16 @@ cr.define('model_test', function() {
print_preview_test_utils.getCddTemplateWithAdvancedSettings(2)
.capabilities;

if (cr.isChromeOS) {
// Make device managed. It's used for testing pin setting behavior.
loadTimeData.overrideValues({isEnterpriseManaged: true});
}
initializeModel();
model.destination = testDestination;
const defaultTicket =
model.createPrintTicket(testDestination, false, false);
const expectedDefaultTicket = JSON.stringify({

const expectedDefaultTicketObject = {
mediaSize: testDestination.capabilities.printer.media_size.option[0],
pageCount: 3,
landscape: false,
Expand Down Expand Up @@ -263,13 +287,13 @@ cr.define('model_test', function() {
pageWidth: 612,
pageHeight: 792,
showSystemDialog: false,
});
expectEquals(expectedDefaultTicket, defaultTicket);
};
expectEquals(JSON.stringify(expectedDefaultTicketObject), defaultTicket);

// Toggle all the values and create a new print ticket.
toggleSettings(testDestination);
const newTicket = model.createPrintTicket(testDestination, false, false);
const expectedNewTicket = JSON.stringify({
const expectedNewTicketObject = {
mediaSize: testDestination.capabilities.printer.media_size.option[1],
pageCount: 1,
landscape: true,
Expand Down Expand Up @@ -304,8 +328,12 @@ cr.define('model_test', function() {
marginBottom: 300,
marginLeft: 400,
},
});
expectEquals(expectedNewTicket, newTicket);
};
if (cr.isChromeOS) {
expectedNewTicketObject.pinValue = '0000';
}

expectEquals(JSON.stringify(expectedNewTicketObject), newTicket);
});

/**
Expand Down
4 changes: 4 additions & 0 deletions printing/backend/cups_ipp_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ extern const char kIppMedia[];
extern const char kIppDuplex[];
extern const char kIppDocumentName[];
extern const char kIppRequestingUserName[];
extern const char kIppPin[];
extern const char kIppPinEncryption[];

extern const char kCollated[];
extern const char kUncollated[];

extern const char kPinEncryptionNone[];

// Smart ptr wrapper for CUPS ipp_t
using ScopedIppPtr = std::unique_ptr<ipp_t, void (*)(ipp_t*)>;

Expand Down
3 changes: 3 additions & 0 deletions printing/print_job_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ const char kSettingPageRangeTo[] = "to";
const char kSettingPageWidth[] = "pageWidth";
const char kSettingPageHeight[] = "pageHeight";

// PIN code entered by the user.
const char kSettingPinValue[] = "pinValue";

// Policies affecting printing destination.
const char kSettingPolicies[] = "policies";

Expand Down
1 change: 1 addition & 0 deletions printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PRINTING_EXPORT extern const char kSettingPageRangeTo[];
PRINTING_EXPORT extern const char kSettingPageWidth[];
PRINTING_EXPORT extern const char kSettingPageHeight[];
PRINTING_EXPORT extern const char kSettingPagesPerSheet[];
PRINTING_EXPORT extern const char kSettingPinValue[];
PRINTING_EXPORT extern const char kSettingPolicies[];
PRINTING_EXPORT extern const char kSettingPreviewModifiable[];
PRINTING_EXPORT extern const char kSettingPrintToGoogleDrive[];
Expand Down
6 changes: 6 additions & 0 deletions printing/print_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class PRINTING_EXPORT PrintSettings {

void set_username(const std::string& username) { username_ = username; }
const std::string& username() const { return username_; }

void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; }
const std::string& pin_value() const { return pin_value_; }
#endif

// Cookie generator. It is used to initialize PrintedDocument with its
Expand Down Expand Up @@ -287,6 +290,9 @@ class PRINTING_EXPORT PrintSettings {

// Username if it's required by the printer.
std::string username_;

// PIN code entered by the user.
std::string pin_value_;
#endif
};

Expand Down
4 changes: 4 additions & 0 deletions printing/print_settings_conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ bool PrintSettingsFromJobSettings(const base::Value& job_settings,
if (username)
settings->set_username(*username);
}

const std::string* pin_value = job_settings.FindStringKey(kSettingPinValue);
if (pin_value)
settings->set_pin_value(*pin_value);
#endif

return true;
Expand Down
6 changes: 4 additions & 2 deletions printing/print_settings_conversion_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ const char kPrinterSettings[] = R"({
"dpiVertical": 300,
"previewModifiable": true,
"sendUserInfo": true,
"username": "username@domain.net"
"username": "username@domain.net",
"pinValue": "0000"
})";

}
} // namespace

TEST(PrintSettingsConversionTest, ConversionTest) {
std::unique_ptr<base::Value> value =
Expand All @@ -57,6 +58,7 @@ TEST(PrintSettingsConversionTest, ConversionTest) {
#if defined(OS_CHROMEOS)
EXPECT_TRUE(settings.send_user_info());
EXPECT_EQ("username@domain.net", settings.username());
EXPECT_EQ("0000", settings.pin_value());
#endif
}

Expand Down
4 changes: 4 additions & 0 deletions printing/printing_context_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ std::vector<ScopedCupsOption> SettingsToCupsOptions(
options.push_back(
ConstructOption(kIppRequestingUserName, settings.username()));
}
if (!settings.pin_value().empty()) {
options.push_back(ConstructOption(kIppPin, settings.pin_value()));
options.push_back(ConstructOption(kIppPinEncryption, kPinEncryptionNone));
}

return options;
}
Expand Down

0 comments on commit c1bf3f8

Please sign in to comment.