Closed Bug 1627577 Opened 5 years ago Closed 5 years ago

Enable printing tests (access denied on tmp directory on print reftest on MacOSX)

Categories

(Core :: Printing: Output, defect, P1)

Unspecified
macOS
defect

Tracking

()

RESOLVED FIXED
mozilla78
Tracking Status
firefox78 --- fixed

People

(Reporter: hiro, Assigned: bobowen)

References

(Blocks 1 open bug)

Details

(Whiteboard: [print2020_v78])

Attachments

(4 files, 5 obsolete files)

47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review

When you run ./mach reftest layout/reftests/printing/test-text.html on MacOSX, you will see below error.

1:32.06 GECKO(1705) JavaScript error: resource://reftest/reftest-content.js, line 262: NS_ERROR_FILE_ACCESS_DENIED: Component returned failure code: 0x80520015 (NS_ERROR_FILE_ACCESS_DENIED) [nsIFile.createUnique]

Is this a regression? This kind of writes was restricted ages ago, why is this test not failing on try?

Can we just...not do this from content?

Assignee: nobody → haftandilian
Flags: needinfo?(haftandilian)
Assignee: haftandilian → nobody
Flags: needinfo?(haftandilian)

We're trying to create a file /private/var/folders/<xx>/<...>/T/reftest-print.pdf in the content process which is blocked by process sandboxing. From the error, it's https://searchfox.org/mozilla-central/rev/a707541ff423ade0d81cef6488e6ecfa09273886/layout/tools/reftest/reftest-content.js#262

We shouldn't have to create the file from a content process. During the test, I checked the profile used and print_via_parent=false in the profile prefs. I'm not sure if I'm understanding the tests correctly, but it appears we need to rework the test to use remote printing and do the verification in the parent so that content processes don't need to read/write from the filesystem.

Glad this is being worked on. More test coverage of printing is greatly appreciated.

This is definitely reproducible on my macOS machine. I'm going to mark this as P3, given that we currently don't run these tests.

Priority: -- → P3

(In reply to Haik Aftandilian [:haik] from comment #3)

We shouldn't have to create the file from a content process. During the test, I checked the profile used and print_via_parent=true in the profile prefs. I'm not sure if I'm understanding the tests correctly, but it appears we need to rework the test to use remote printing and do the verification in the parent so that content processes don't need to read/write from the filesystem.

To clarify what I meant by remote printing above, printing on Windows, Mac, and desktop Linux all use print.print_via_parent=true to enable remote printing which was added with bug 1156742 for Windows (which was a large project) and later enabled on Mac and desktop Linux. With remote printing, the print data is sent over IPC and the printing OS API calls are done from the parent process. This is done to allow stronger sandboxing in the content processes.

If we are testing with print_via_parent=false, 1) we will not be exercising large parts of our printing code paths that are used by desktop users 2) printing will not work due to sandboxing and we'll have to make sandboxing changes to allow it. For example, on Mac, content processes don't have access to OS printing services due to process-level sandboxing.

I have some patches that gets printing via the parent with these reftests working.
This along with some other changes to work-around the file system restrictions and other bits and pieces, means the tests work locally for me on Windows and macOS.
(Actually one of the tests failed on macOS, wrong number of pages, but perhaps that is a genuine issue.)

I'll get the patches up next week.
I suspect my fixes are not the best options in some circumstances and they include a patch to PDF.js, which looks like it'll have to be landed in a separate project (unless there is a better option that doesn't require changes).
So, I'll probably just attach the patches to this bug initially for feedback.

Assignee: nobody → bobowencode
Status: NEW → ASSIGNED
Priority: P3 → P1

https://treeherder.mozilla.org/#/jobs?repo=try&revision=6f1b1fc0fcf1735453befc6b1f9001bd7c5a9d72

A few things to sort out, but looks like it could be enabled already on some configurations.

https://treeherder.mozilla.org/#/jobs?repo=try&duplicate_jobs=visible&revision=739519c4fb0965bd7456daffd3fdf38ce168a17d

Lots of crashes on Linux/Android for some reason, so I disabled there:
https://treeherder.mozilla.org/#/jobs?repo=try&duplicate_jobs=visible&revision=c48263899ed1e904a972cefd7b85cce57cbf1e4c

One intermittent reading issue on mac, so we might have to disable there if it turns out to be too bad.

I'm just going to attach the patches to the bug for feedback initially, because if the PDF.js change is really needed then that will have to be landed on its repository I assume.

Comment on attachment 9144283 [details] [diff] [review] Bug 1627577 part 1: Add function to allow window and document to be set in PDF.js module. r=bdahl! The getDocument function uses document to run the worker script and window to get the worker, but they are not set. The global appears to be a Sandbox. There might be a better way of doing this that doesn't require a change to PDF.js bdahl - If this is acceptable I assume I have to land this on PDF.js repository.
Attachment #9144283 - Flags: feedback?(emilio)
Attachment #9144283 - Flags: feedback?(bdahl)
Comment on attachment 9144283 [details] [diff] [review] Bug 1627577 part 1: Add function to allow window and document to be set in PDF.js module. r=bdahl! Review of attachment 9144283 [details] [diff] [review]: ----------------------------------------------------------------- This feels a bit hackish. Does something like this work instead? ``` with ({ window: g.containingWindow, document: g.containingWindow.document }) { // ... } ``` Alternatively... Probably this is an artifact of using the devtools loader to require() pdf.js, but it seems that loading it as a `<script>` element should not have that sandboxing, so maybe either use a script [here](https://searchfox.org/mozilla-central/rev/2bfe3415fb3a2fba9b1c694bc0b376365e086927/layout/tools/reftest/reftest.xhtml#13) or lazily append it if not there when running a print reftest, and wait for its load event before continuing?
Attachment #9144283 - Flags: feedback?(emilio)

FYI, Linux / Android crashes are probably bug 1622075.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #16)

Comment on attachment 9144283 [details] [diff] [review]
Bug 1627577 part 1: Add function to allow window and document to be set in
PDF.js module. r=bdahl!

Review of attachment 9144283 [details] [diff] [review]:

This feels a bit hackish. Does something like this work instead?

I thought that myself. :-)

with ({ window: g.containingWindow, document: g.containingWindow.document })
{
    // ...
}

Alternatively... Probably this is an artifact of using the devtools loader
to require() pdf.js, but it seems that loading it as a <script> element
should not have that sandboxing, so maybe either use a script
[here](https://searchfox.org/mozilla-central/rev/
2bfe3415fb3a2fba9b1c694bc0b376365e086927/layout/tools/reftest/reftest.
xhtml#13) or lazily append it if not there when running a print reftest, and
wait for its load event before continuing?

Thanks I'll give those a go.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #17)

FYI, Linux / Android crashes are probably bug 1622075.

I think that crash is because it is printing in the content process, my changes should fix that as we're printing from the parent like in normal firefox.
One thought I had was whether we run the reftests in parallel on Linux that might be causing issues?

Flags: needinfo?(emilio)
Comment on attachment 9144283 [details] [diff] [review] Bug 1627577 part 1: Add function to allow window and document to be set in PDF.js module. r=bdahl! I think I've got PDF.js loading lazily as a normal script. I'm probably still committing crimes against JavaScript (if there are such things), but I'll get the patches up for review.
Attachment #9144283 - Attachment is obsolete: true
Attachment #9144283 - Flags: feedback?(bdahl)
Attachment #9144287 - Attachment is obsolete: true
Attachment #9144286 - Attachment is obsolete: true
Attachment #9144284 - Attachment is obsolete: true
Attachment #9144285 - Attachment is obsolete: true

(In reply to Bob Owen (:bobowen) from comment #18)

I think that crash is because it is printing in the content process, my changes should fix that as we're printing from the parent like in normal firefox.
One thought I had was whether we run the reftests in parallel on Linux that might be causing issues?

I took a look, and it may be. They're not crashes per se, just timeouts. They all happen after a weird:

JavaScript error: , line 0: uncaught exception: Object

Which unfortunately is probably the worse JS error message ever. It'd be interesting if the new approach of loading the script fixes that or not. Otherwise please file a bug and ni? me, and I'm happy to try reproing here and poking at it with rr.

Thanks again for working on this!

Flags: needinfo?(emilio)
Blocks: 1634335

(In reply to Emilio Cobos Álvarez (:emilio) from comment #25)

(In reply to Bob Owen (:bobowen) from comment #18)

I think that crash is because it is printing in the content process, my changes should fix that as we're printing from the parent like in normal firefox.
One thought I had was whether we run the reftests in parallel on Linux that might be causing issues?

I took a look, and it may be. They're not crashes per se, just timeouts. They all happen after a weird:

JavaScript error: , line 0: uncaught exception: Object

Which unfortunately is probably the worse JS error message ever.

By the way I got a similar error on Windows, which (if IIRC) I tracked down to the file.flush here [1], which seemed an odd thing to do for a read anyway.
So, it could be an issue opening/reading the file.
The tests currently use TmpD (which will be a separately created temporary dir in the content process, where it is called).
I wonder if this is sometimes causing problems, we could pass the filename down from the parent I guess.

[1] https://searchfox.org/mozilla-central/rev/7fd1c1c34923ece7ad8c822bee062dd0491d64dc/layout/tools/reftest/reftest.jsm#1763

Attachment #9144392 - Attachment description: Bug 1627577 part 3: Don't get settings from printer when printing to PDF on macOS. r=jwatt! → Bug 1627577 part 3: Use NSPrintInfo for PrintRange, StartPageRange and EndPageRange in the parent on macOS. r=jwatt!
Pushed by bobowencode@gmail.com: https://hg.mozilla.org/integration/autoland/rev/103b671e8cb0 part 1: Change printing reftests to work with remote printing. r=emilio https://hg.mozilla.org/integration/autoland/rev/763932c16c29 part 2: Fix assertion in nsDeviceContextSpecWin::MakePrintTarget. r=jwatt https://hg.mozilla.org/integration/autoland/rev/d868664d33b0 part 3: Use NSPrintInfo for PrintRange, StartPageRange and EndPageRange in the parent on macOS. r=jwatt https://hg.mozilla.org/integration/autoland/rev/fab960f9cf82 part 4: Enable printing restests on macOS and Windows. r=emilio
Summary: access denied on tmp directory on print reftest on MacOSX → Enable printing tests (access denied on tmp directory on print reftest on MacOSX)
Whiteboard: [print2020_v78]
Regressions: 1643418
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: