Skip to content

Commit

Permalink
fix: crash on custom printing margins (#22164)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 14, 2020
1 parent f0d8729 commit c8b7bd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions shell/browser/api/atom_api_web_contents.cc
Expand Up @@ -1728,18 +1728,20 @@ void WebContents::Print(mate::Arguments* args) {
settings.SetInteger(printing::kSettingMarginsType, margin_type);

if (margin_type == printing::CUSTOM_MARGINS) {
auto custom_margins = std::make_unique<base::DictionaryValue>();
int top = 0;
margins.Get("top", &top);
settings.SetInteger(printing::kSettingMarginTop, top);
custom_margins->SetInteger(printing::kSettingMarginTop, top);
int bottom = 0;
margins.Get("bottom", &bottom);
settings.SetInteger(printing::kSettingMarginBottom, bottom);
custom_margins->SetInteger(printing::kSettingMarginBottom, bottom);
int left = 0;
margins.Get("left", &left);
settings.SetInteger(printing::kSettingMarginLeft, left);
custom_margins->SetInteger(printing::kSettingMarginLeft, left);
int right = 0;
margins.Get("right", &right);
settings.SetInteger(printing::kSettingMarginRight, right);
custom_margins->SetInteger(printing::kSettingMarginRight, right);
settings.SetDictionary(printing::kSettingMarginsCustom, custom_margins);
}
} else {
settings.SetInteger(printing::kSettingMarginsType,
Expand Down
13 changes: 11 additions & 2 deletions spec-main/api-web-contents-spec.ts
Expand Up @@ -130,9 +130,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

0 comments on commit c8b7bd0

Please sign in to comment.