mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1809422 - Android Unable to Print/Save PDF r=geckoview-reviewers,calu
The canonical browsing context is not available if the current window/tab is not focused for printing or saving as a PDF. This patch adds a call to `setFocused` before creating a Gecko PDF to ensure the canonical browsing context can be used for generating a PDF to save or print. Differential Revision: https://phabricator.services.mozilla.com/D185311
This commit is contained in:
parent
d649d941ce
commit
c562764160
@ -322,4 +322,25 @@ class PrintDelegateTest : BaseSessionTest() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@NullDelegate(Autofill.Delegate::class)
|
||||
@Test
|
||||
fun availableCanonicalBrowsingContext() {
|
||||
sessionRule.setPrefsUntilTestEnd(mapOf("dom.enable_window_print" to true))
|
||||
activityRule.scenario.onActivity { activity ->
|
||||
// CSS rules render this blue on screen and orange on print
|
||||
mainSession.loadTestPath(ORANGE_PDF_PATH)
|
||||
mainSession.waitForPageStop()
|
||||
// Setting to the default delegate (test rules changed it)
|
||||
mainSession.printDelegate = activity.view.printDelegate
|
||||
mainSession.setFocused(false)
|
||||
mainSession.printPageContent()
|
||||
val centerPixel = printCenterPixelColor()
|
||||
val orange = rgb(255, 113, 57)
|
||||
assertTrue(
|
||||
"Android print opened and rendered.",
|
||||
sessionRule.waitForResult(centerPixel) == orange,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7542,6 +7542,8 @@ public class GeckoSession {
|
||||
final @Nullable Long browsingContextId) {
|
||||
final GeckoResult<InputStream> geckoResult = new GeckoResult<>();
|
||||
if (browsingContextId == null) {
|
||||
// Ensures the canonical browsing context is available
|
||||
setFocused(true);
|
||||
this.mWindow.printToPdf(geckoResult);
|
||||
} else {
|
||||
this.mWindow.printToPdf(geckoResult, browsingContextId);
|
||||
|
Loading…
Reference in New Issue
Block a user