Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash on custom printing margins #22186

Merged
merged 1 commit into from Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1785,18 +1785,21 @@ void WebContents::Print(mate::Arguments* args) {
settings.SetIntKey(printing::kSettingMarginsType, margin_type);

if (margin_type == printing::CUSTOM_MARGINS) {
base::Value custom_margins(base::Value::Type::DICTIONARY);
int top = 0;
margins.Get("top", &top);
settings.SetIntKey(printing::kSettingMarginTop, top);
custom_margins.SetIntKey(printing::kSettingMarginTop, top);
int bottom = 0;
margins.Get("bottom", &bottom);
settings.SetIntKey(printing::kSettingMarginBottom, bottom);
custom_margins.SetIntKey(printing::kSettingMarginBottom, bottom);
int left = 0;
margins.Get("left", &left);
settings.SetIntKey(printing::kSettingMarginLeft, left);
custom_margins.SetIntKey(printing::kSettingMarginLeft, left);
int right = 0;
margins.Get("right", &right);
settings.SetIntKey(printing::kSettingMarginRight, right);
custom_margins.SetIntKey(printing::kSettingMarginRight, right);
settings.SetPath(printing::kSettingMarginsCustom,
std::move(custom_margins));
}
} else {
settings.SetIntKey(printing::kSettingMarginsType,
Expand Down
13 changes: 11 additions & 2 deletions spec-main/api-web-contents-spec.ts
Expand Up @@ -132,9 +132,18 @@ describe('webContents module', () => {
}).to.throw('webContents.print(): Invalid deviceName provided.')
})

it('does not crash', () => {
it('does not crash with custom margins', () => {
expect(() => {
w.webContents.print({ silent: true })
w.webContents.print({
silent: true,
margins: {
marginType: 'custom',
top: 1,
bottom: 1,
left: 1,
right: 1
}
})
}).to.not.throw()
})
})
Expand Down